Sync portfolio laboratory source
This commit is contained in:
commit
24ddb06c6e
12 changed files with 246 additions and 0 deletions
29
sql/02-vault.sql
Normal file
29
sql/02-vault.sql
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
-- Хабы сохраняют бизнес-ключ и стабильный SHA-256. Связи ссылаются на хабы.
|
||||
CREATE TABLE IF NOT EXISTS iceberg.tpch_vault.hub_customer AS
|
||||
SELECT to_hex(sha256(to_utf8(cast(custkey AS varchar)))) AS customer_hk,
|
||||
custkey, current_timestamp(3) AS loaded_at, 'tpch.tiny' AS record_source
|
||||
FROM iceberg.tpch_raw.customer;
|
||||
CREATE TABLE IF NOT EXISTS iceberg.tpch_vault.hub_order AS
|
||||
SELECT to_hex(sha256(to_utf8(cast(orderkey AS varchar)))) AS order_hk,
|
||||
orderkey, current_timestamp(3) AS loaded_at, 'tpch.tiny' AS record_source
|
||||
FROM iceberg.tpch_raw.orders;
|
||||
CREATE TABLE IF NOT EXISTS iceberg.tpch_vault.hub_part AS
|
||||
SELECT to_hex(sha256(to_utf8(cast(partkey AS varchar)))) AS part_hk,
|
||||
partkey, current_timestamp(3) AS loaded_at, 'tpch.tiny' AS record_source
|
||||
FROM iceberg.tpch_raw.part;
|
||||
CREATE TABLE IF NOT EXISTS iceberg.tpch_vault.hub_supplier AS
|
||||
SELECT to_hex(sha256(to_utf8(cast(suppkey AS varchar)))) AS supplier_hk,
|
||||
suppkey, current_timestamp(3) AS loaded_at, 'tpch.tiny' AS record_source
|
||||
FROM iceberg.tpch_raw.supplier;
|
||||
CREATE TABLE IF NOT EXISTS iceberg.tpch_vault.link_order_customer AS
|
||||
SELECT o.order_hk, c.customer_hk, o.loaded_at, o.record_source
|
||||
FROM iceberg.tpch_raw.orders r
|
||||
JOIN iceberg.tpch_vault.hub_order o ON o.orderkey = r.orderkey
|
||||
JOIN iceberg.tpch_vault.hub_customer c ON c.custkey = r.custkey;
|
||||
CREATE TABLE IF NOT EXISTS iceberg.tpch_vault.link_line AS
|
||||
SELECT to_hex(sha256(to_utf8(format('%d|%d', l.orderkey, l.linenumber)))) AS line_hk,
|
||||
o.order_hk, p.part_hk, s.supplier_hk, l.linenumber, o.loaded_at, o.record_source
|
||||
FROM iceberg.tpch_raw.lineitem l
|
||||
JOIN iceberg.tpch_vault.hub_order o ON o.orderkey = l.orderkey
|
||||
JOIN iceberg.tpch_vault.hub_part p ON p.partkey = l.partkey
|
||||
JOIN iceberg.tpch_vault.hub_supplier s ON s.suppkey = l.suppkey;
|
||||
Loading…
Add table
Add a link
Reference in a new issue