Skip to content

Commit 4c50da3

Browse files
committed
Add old format tables schema
1 parent 8b90307 commit 4c50da3

File tree

2 files changed

+231
-0
lines changed

2 files changed

+231
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
CREATE TABLE IF NOT EXISTS inserts_null_table
2+
(
3+
chain_id UInt256,
4+
block Tuple(
5+
block_number UInt256,
6+
block_timestamp DateTime,
7+
hash FixedString(66),
8+
parent_hash FixedString(66),
9+
sha3_uncles FixedString(66),
10+
nonce FixedString(18),
11+
mix_hash FixedString(66),
12+
miner FixedString(42),
13+
state_root FixedString(66),
14+
transactions_root FixedString(66),
15+
receipts_root FixedString(66),
16+
logs_bloom String,
17+
size UInt64,
18+
extra_data String,
19+
difficulty UInt256,
20+
total_difficulty UInt256,
21+
transaction_count UInt64,
22+
gas_limit UInt256,
23+
gas_used UInt256,
24+
withdrawals_root FixedString(66),
25+
base_fee_per_gas Nullable(UInt64)),
26+
transactions Array(Tuple(
27+
hash FixedString(66),
28+
nonce UInt64,
29+
block_hash FixedString(66),
30+
block_number UInt256,
31+
block_timestamp DateTime,
32+
transaction_index UInt64,
33+
from_address FixedString(42),
34+
to_address FixedString(42),
35+
value UInt256,
36+
gas UInt64,
37+
gas_price UInt256,
38+
data String,
39+
function_selector FixedString(10),
40+
max_fee_per_gas UInt128,
41+
max_priority_fee_per_gas UInt128,
42+
max_fee_per_blob_gas UInt256,
43+
blob_versioned_hashes Array(String),
44+
transaction_type UInt8,
45+
r UInt256,
46+
s UInt256,
47+
v UInt256,
48+
access_list Nullable(String),
49+
authorization_list Nullable(String),
50+
contract_address Nullable(FixedString(42)),
51+
gas_used Nullable(UInt64),
52+
cumulative_gas_used Nullable(UInt64),
53+
effective_gas_price Nullable(UInt256),
54+
blob_gas_used Nullable(UInt64),
55+
blob_gas_price Nullable(UInt256),
56+
logs_bloom Nullable(String),
57+
status Nullable(UInt64))),
58+
logs Array(Tuple(
59+
block_number UInt256,
60+
block_hash FixedString(66),
61+
block_timestamp DateTime,
62+
transaction_hash FixedString(66),
63+
transaction_index UInt64,
64+
log_index UInt64,
65+
address FixedString(42),
66+
data String,
67+
topic_0 String,
68+
topic_1 String,
69+
topic_2 String,
70+
topic_3 String)),
71+
traces Array(Tuple(
72+
block_number UInt256,
73+
block_hash FixedString(66),
74+
block_timestamp DateTime,
75+
transaction_hash FixedString(66),
76+
transaction_index UInt64,
77+
subtraces Int64,
78+
trace_address Array(Int64),
79+
type LowCardinality(String),
80+
call_type LowCardinality(String),
81+
error Nullable(String),
82+
from_address FixedString(42),
83+
to_address FixedString(42),
84+
gas UInt64,
85+
gas_used UInt64,
86+
input String,
87+
output Nullable(String),
88+
value UInt256,
89+
author Nullable(FixedString(42)),
90+
reward_type LowCardinality(Nullable(String)),
91+
refund_address Nullable(FixedString(42)))),
92+
token_transfers Array(Tuple(
93+
token_type LowCardinality(String),
94+
token_address FixedString(42),
95+
token_id UInt256,
96+
from_address FixedString(42),
97+
to_address FixedString(42),
98+
block_number UInt256,
99+
block_timestamp DateTime,
100+
transaction_hash FixedString(66),
101+
transaction_index UInt64,
102+
amount UInt256,
103+
log_index UInt64,
104+
batch_index Nullable(UInt16))),
105+
insert_timestamp DateTime DEFAULT now(),
106+
is_deleted UInt8 DEFAULT 0,
107+
sign Int8 DEFAULT 1
108+
)
109+
ENGINE = Null
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
CREATE MATERIALIZED VIEW IF NOT EXISTS insert_blocks_mv
2+
TO blocks
3+
AS
4+
SELECT
5+
chain_id,
6+
block.1 AS block_number,
7+
block.2 AS block_timestamp,
8+
block.3 AS hash,
9+
block.4 AS parent_hash,
10+
block.5 AS sha3_uncles,
11+
block.6 AS nonce,
12+
block.7 AS mix_hash,
13+
block.8 AS miner,
14+
block.9 AS state_root,
15+
block.10 AS transactions_root,
16+
block.11 AS receipts_root,
17+
block.12 AS logs_bloom,
18+
block.13 AS size,
19+
block.14 AS extra_data,
20+
block.15 AS difficulty,
21+
block.16 AS total_difficulty,
22+
block.17 AS transaction_count,
23+
block.18 AS gas_limit,
24+
block.19 AS gas_used,
25+
block.20 AS withdrawals_root,
26+
block.21 AS base_fee_per_gas,
27+
insert_timestamp,
28+
is_deleted
29+
FROM inserts_null_table;
30+
31+
CREATE MATERIALIZED VIEW IF NOT EXISTS insert_transactions_mv
32+
TO transactions
33+
AS
34+
SELECT
35+
chain_id,
36+
t.1 AS hash,
37+
t.2 AS nonce,
38+
t.3 AS block_hash,
39+
t.4 AS block_number,
40+
t.5 AS block_timestamp,
41+
t.6 AS transaction_index,
42+
t.7 AS from_address,
43+
t.8 AS to_address,
44+
t.9 AS value,
45+
t.10 AS gas,
46+
t.11 AS gas_price,
47+
t.12 AS data,
48+
t.13 AS function_selector,
49+
t.14 AS max_fee_per_gas,
50+
t.15 AS max_priority_fee_per_gas,
51+
t.16 AS max_fee_per_blob_gas,
52+
t.17 AS blob_versioned_hashes,
53+
t.18 AS transaction_type,
54+
t.19 AS r,
55+
t.20 AS s,
56+
t.21 AS v,
57+
t.22 AS access_list,
58+
t.23 AS authorization_list,
59+
t.24 AS contract_address,
60+
t.25 AS gas_used,
61+
t.26 AS cumulative_gas_used,
62+
t.27 AS effective_gas_price,
63+
t.28 AS blob_gas_used,
64+
t.29 AS blob_gas_price,
65+
t.30 AS logs_bloom,
66+
t.31 AS status,
67+
insert_timestamp,
68+
is_deleted
69+
FROM inserts_null_table
70+
ARRAY JOIN transactions AS t;
71+
72+
CREATE MATERIALIZED VIEW IF NOT EXISTS insert_logs_mv
73+
TO logs
74+
AS
75+
SELECT
76+
chain_id,
77+
l.1 AS block_number,
78+
l.2 AS block_hash,
79+
l.3 AS block_timestamp,
80+
l.4 AS transaction_hash,
81+
l.5 AS transaction_index,
82+
l.6 AS log_index,
83+
l.7 AS address,
84+
l.8 AS data,
85+
l.9 AS topic_0,
86+
l.10 AS topic_1,
87+
l.11 AS topic_2,
88+
l.12 AS topic_3,
89+
insert_timestamp,
90+
is_deleted
91+
FROM inserts_null_table
92+
ARRAY JOIN logs AS l;
93+
94+
CREATE MATERIALIZED VIEW IF NOT EXISTS insert_traces_mv
95+
TO traces
96+
AS
97+
SELECT
98+
chain_id,
99+
tr.1 AS block_number,
100+
tr.2 AS block_hash,
101+
tr.3 AS block_timestamp,
102+
tr.4 AS transaction_hash,
103+
tr.5 AS transaction_index,
104+
tr.6 AS subtraces,
105+
tr.7 AS trace_address,
106+
tr.8 AS type,
107+
tr.9 AS call_type,
108+
tr.10 AS error,
109+
tr.11 AS from_address,
110+
tr.12 AS to_address,
111+
tr.13 AS gas,
112+
tr.14 AS gas_used,
113+
tr.15 AS input,
114+
tr.16 AS output,
115+
tr.17 AS value,
116+
tr.18 AS author,
117+
tr.19 AS reward_type,
118+
tr.20 AS refund_address,
119+
insert_timestamp,
120+
is_deleted
121+
FROM inserts_null_table
122+
ARRAY JOIN traces AS tr;

0 commit comments

Comments
 (0)