Skip to content

Commit d323414

Browse files
use denormalized columns throughout bigqueries (#1155)
Signed-off-by: Stephen Compall <stephen.compall@digitalasset.com>
1 parent ec95f03 commit d323414

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

apps/app/src/test/resources/total-supply-bigquery.sql

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,26 @@ SET
3434
SELECT
3535
COALESCE(SUM(PARSE_BIGNUMERIC(JSON_VALUE(c.create_arguments, path))), 0)
3636
FROM
37-
experiment_dataset.creates c,
38-
experiment_dataset.transactions t
37+
experiment_dataset.creates c
3938
WHERE
4039
NOT EXISTS (
4140
SELECT
4241
TRUE
4342
FROM
44-
experiment_dataset.exercises e,
45-
experiment_dataset.transactions t2
43+
experiment_dataset.exercises e
4644
WHERE
47-
e.update_row_id = t2.row_id
48-
AND (t2.migration_id < migration_id
49-
OR (t2.migration_id = migration_id
50-
AND t2.record_time <= rt_micros))
45+
(e.migration_id < migration_id
46+
OR (e.migration_id = migration_id
47+
AND e.record_time <= rt_micros))
5148
AND e.consuming
5249
AND e.template_id_module_name = module_name
5350
AND e.template_id_entity_name = entity_name
5451
AND e.contract_id = c.contract_id)
5552
AND c.template_id_module_name = module_name
5653
AND c.template_id_entity_name = entity_name
57-
AND c.update_row_id = t.row_id -- we don't assume that t.row_id increases with record time
58-
AND (t.migration_id < migration_id
59-
OR (t.migration_id = migration_id
60-
AND t.record_time <= rt_micros)));
54+
AND (c.migration_id < migration_id
55+
OR (c.migration_id = migration_id
56+
AND c.record_time <= rt_micros)));
6157
END
6258
;
6359

@@ -146,16 +142,14 @@ SET
146142
+ PARSE_BIGNUMERIC(JSON_VALUE(e.result, inputValidatorRewardAmount))
147143
+ PARSE_BIGNUMERIC(JSON_VALUE(e.result, inputSvRewardAmount)))
148144
FROM
149-
experiment_dataset.exercises e,
150-
experiment_dataset.transactions t
145+
experiment_dataset.exercises e
151146
WHERE
152147
e.choice = 'AmuletRules_Transfer'
153148
AND e.template_id_module_name = 'Splice.AmuletRules'
154149
AND e.template_id_entity_name = 'AmuletRules'
155-
AND e.update_row_id = t.row_id -- we don't assume that t.row_id increases with record time
156-
AND (t.migration_id < migration_id
157-
OR (t.migration_id = migration_id
158-
AND t.record_time <= UNIX_MICROS(as_of_record_time))));
150+
AND (e.migration_id < migration_id
151+
OR (e.migration_id = migration_id
152+
AND e.record_time <= UNIX_MICROS(as_of_record_time))));
159153
END
160154
;
161155

@@ -218,8 +212,7 @@ SET result = (
218212
SUM(result_burn(e.choice,
219213
e.result)) fees
220214
FROM
221-
experiment_dataset.exercises e,
222-
experiment_dataset.transactions t
215+
experiment_dataset.exercises e
223216
WHERE
224217
((e.choice IN ('AmuletRules_BuyMemberTraffic',
225218
'AmuletRules_Transfer',
@@ -229,17 +222,15 @@ SET result = (
229222
OR (e.choice = 'TransferPreapproval_Renew'
230223
AND e.template_id_entity_name = 'TransferPreapproval'))
231224
AND e.template_id_module_name = 'Splice.AmuletRules'
232-
AND e.update_row_id = t.row_id -- we don't assume that t.row_id increases with record time
233-
AND (t.migration_id < migration_id
234-
OR (t.migration_id = migration_id
235-
AND t.record_time <= UNIX_MICROS(as_of_record_time))))
225+
AND (e.migration_id < migration_id
226+
OR (e.migration_id = migration_id
227+
AND e.record_time <= UNIX_MICROS(as_of_record_time))))
236228
UNION ALL (-- Purchasing ANS Entries
237229
SELECT
238230
SUM(PARSE_BIGNUMERIC(JSON_VALUE(c.create_arguments, '$.record.fields[2].value.record.fields[0].value.numeric'))) fees -- .amount.initialAmount
239231
FROM
240232
experiment_dataset.exercises e,
241-
experiment_dataset.creates c,
242-
experiment_dataset.transactions t
233+
experiment_dataset.creates c
243234
WHERE
244235
((e.choice = 'SubscriptionInitialPayment_Collect'
245236
AND e.template_id_entity_name = 'SubscriptionInitialPayment'
@@ -250,10 +241,9 @@ SET result = (
250241
AND e.template_id_module_name = 'Splice.Wallet.Subscriptions'
251242
AND c.template_id_module_name = 'Splice.Amulet'
252243
AND c.template_id_entity_name = 'Amulet'
253-
AND e.update_row_id = t.row_id -- we don't assume that t.row_id increases with record time
254-
AND (t.migration_id < migration_id
255-
OR (t.migration_id = migration_id
256-
AND t.record_time <= UNIX_MICROS(as_of_record_time))))));
244+
AND (e.migration_id < migration_id
245+
OR (e.migration_id = migration_id
246+
AND e.record_time <= UNIX_MICROS(as_of_record_time))))));
257247
END;
258248

259249
-- using the functions

0 commit comments

Comments
 (0)