trino-iceberg-minio-notes/sql/07-quality.sql

25 lines
1.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Все выражения fail прерывают выполнение после расчёта контрольной метрики.
SELECT IF(count(*) = 15000 AND count(DISTINCT orderkey) = 15000, 'orders OK', fail('TPC-H orders mismatch'))
FROM iceberg.tpch_raw.orders;
SELECT IF(count(*) = 60175, 'lineitem OK', fail('TPC-H lineitem mismatch')) FROM iceberg.tpch_raw.lineitem;
SELECT IF(count(*) = 0, 'foreign key OK', fail('Orphan order customer'))
FROM iceberg.tpch_raw.orders o LEFT JOIN iceberg.tpch_raw.customer c ON o.custkey = c.custkey
WHERE c.custkey IS NULL;
SELECT IF(sum(orders) = 15000, 'sales OK', fail('Sales view discrepancy')) FROM iceberg.tpch_bi.sales;
SELECT IF(sum(lines) = 60175, 'supply OK', fail('Supply view discrepancy')) FROM iceberg.tpch_bi.supply;
SELECT IF(count(*) = 15002
AND count(DISTINCT ROW(order_hk, batch_id)) = 15002,
'event identity OK', fail('Missing or duplicate order revisions'))
FROM iceberg.tpch_vault.sat_order;
SELECT IF(count(*) = 2 AND count(DISTINCT hashdiff) = 1,
'reversion OK', fail('The baseline or reversion is missing'))
FROM iceberg.tpch_vault.sat_order
WHERE batch_id IN (0, 2)
AND order_hk = (
SELECT order_hk FROM iceberg.tpch_vault.hub_order ORDER BY orderkey LIMIT 1
);
SELECT IF(count(*) = 1, 'correction OK', fail('The correction has no distinct state'))
FROM iceberg.tpch_vault.sat_order AS correction
JOIN iceberg.tpch_vault.sat_order AS baseline
ON correction.order_hk = baseline.order_hk AND baseline.batch_id = 0
WHERE correction.batch_id = 1 AND correction.hashdiff <> baseline.hashdiff;