You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- connect the sink to the _final_validator_dashboard_roi_hourly table
19
+
CREATE MATERIALIZED VIEW IF NOT EXISTS _mv_backfill_final_validator_dashboard_roi_hourly_electra_fork TO _final_validator_dashboard_roi_hourly
20
+
(
21
+
`validator_index` UInt64,
22
+
`t` DateTime,
23
+
`roi_dividend` Int128,
24
+
`roi_divisor` Int128
25
+
)
26
+
ASSELECT
27
+
validator_index AS validator_index,
28
+
toStartOfHour(foo.epoch_timestamp) AS t,
29
+
SUM(CAST(foo.withdrawals_amount, 'Int128')) AS roi_dividend, -- i.e, we add the withdrawal amount to the roi_dividend
30
+
0AS roi_divisor -- i.e, we dont modify the divisor
31
+
FROM _insert_sink_backfill_electra_fork_epoch_events AS foo
32
+
GROUP BY
33
+
t,
34
+
validator_index
35
+
-- once it is in the hourly, it will be automatically propagated to the daily, weekly and monthly tables by the existing materialized views
36
+
-- +goose StatementEnd
37
+
-- +goose StatementBegin
38
+
-- connect the sink to the _final_validator_dashboard_data_hourly table
39
+
CREATE MATERIALIZED VIEW IF NOT EXISTS _mv_backfill_final_validator_dashboard_data_hourly_electra_fork TO _final_validator_dashboard_data_hourly
40
+
(
41
+
`validator_index` UInt64,
42
+
`t` DateTime,
43
+
`withdrawals_amount` Int64,
44
+
`withdrawals_count` Int64
45
+
)
46
+
ASSELECT
47
+
validator_index AS validator_index,
48
+
toStartOfHour(foo.epoch_timestamp) AS t,
49
+
SUM(foo.withdrawals_amount) AS withdrawals_amount, -- i.e we add the withdrawal amount to the withdrawal amount
50
+
SUM(foo.withdrawals_count) AS withdrawals_count -- i.e we add the withdrawal count to the withdrawal count
51
+
FROM _insert_sink_backfill_electra_fork_epoch_events AS foo
52
+
GROUP BY
53
+
t,
54
+
validator_index
55
+
-- +goose StatementEnd
56
+
-- +goose StatementBegin
57
+
SELECT'the migration will now attempt to create a dictionary. this will only work if the migration is run as the default (root) user.';
58
+
-- +goose StatementEnd
59
+
-- +goose StatementBegin
60
+
CREATE DICTIONARY IF NOT EXISTS _dict_backfill_electra_fork_epoch_events (validator_index Int64, epoch_timestamp DateTime, withdrawals_amount Int64, withdrawals_count Int64)
61
+
PRIMARY KEY epoch_timestamp, validator_index SOURCE(CLICKHOUSE(TABLE _insert_sink_backfill_electra_fork_epoch_events DB currentDatabase()))
62
+
LAYOUT(complex_key_direct()); -- we dont use complex_key_cache here because that would require us to make sure that the cache is up to date when we trigger the mutation. it should only be at most 200k keys anyways
63
+
-- +goose StatementEnd
64
+
-- +goose StatementBegin
65
+
-- kickstart the backfill with the latest exported epoch
66
+
INSERT INTO _exporter_backfill_metadata
67
+
SELECT
68
+
epoch,
69
+
'electra_fork_epoch_events'as backfill_name,
70
+
transfer_batch_id as backfill_batch_id,
71
+
NULLAS successful_backfill
72
+
FROM
73
+
(
74
+
SELECT*
75
+
FROM _exporter_metadata
76
+
WHERE successful_transfer IS NOT NULL
77
+
ORDER BY epoch DESC
78
+
LIMIT1
79
+
)
80
+
-- +goose StatementEnd
81
+
-- +goose StatementBegin
82
+
SELECT'successfully created the dictionary. now start the dashboard exporter again. once the backfill is done (i.e it shows up as 0 epochs left in the grafana dashboard), run the next migration version to update the epoch table.';
83
+
-- +goose StatementEnd
84
+
85
+
-- +goose Down
86
+
-- +goose StatementBegin
87
+
DROPVIEW IF EXISTS _mv_backfill_final_validator_dashboard_roi_hourly_electra_fork;
88
+
-- +goose StatementEnd
89
+
-- +goose StatementBegin
90
+
DROPVIEW IF EXISTS _mv_backfill_final_validator_dashboard_data_hourly_electra_fork;
0 commit comments