Write Primitives merge_scd_type2_basic
Write Primitives benchmark · all Write Primitives queries
Representative SQL
Rendered for DataFusion with default parameters.
UPDATE scd2_ops_dim_customer SET is_current = FALSE, valid_to = ( SELECT MIN(s.effective_ts) FROM scd2_ops_stage_customer AS s WHERE s.c_custkey = scd2_ops_dim_customer.c_custkey AND s.change_type = 'changed')WHERE scd2_ops_dim_customer.is_current = TRUE AND EXISTS( SELECT 1 FROM scd2_ops_stage_customer AS s WHERE s.c_custkey = scd2_ops_dim_customer.c_custkey AND s.change_type = 'changed' AND s.row_hash <> scd2_ops_dim_customer.row_hash );INSERT INTO scd2_ops_dim_customerSELECT ( SELECT MAX(sk) FROM scd2_ops_dim_customer ) + ROW_NUMBER() OVER (ORDER BY s.c_custkey), s.c_custkey, s.c_name, s.c_address, s.c_acctbal, s.c_mktsegment, s.row_hash, TRUE, s.effective_ts, CAST('9999-12-31' AS DATE)FROM scd2_ops_stage_customer AS sWHERE ( s.change_type = 'new' OR ( s.change_type = 'changed' AND EXISTS( SELECT 1 FROM scd2_ops_dim_customer AS d WHERE d.c_custkey = s.c_custkey AND d.is_current = FALSE AND d.valid_to = s.effective_ts ) ) ) AND NOT EXISTS( SELECT 1 FROM scd2_ops_dim_customer AS d2 WHERE d2.c_custkey = s.c_custkey AND d2.is_current = TRUE )Representative DataFrame
No DataFrame implementation is registered for this query.
Get the exact query for your run
The blocks above are representative. To get the precise statement a specific platform runs at a specific scale, substitute your own values:
from benchbox import WritePrimitives
bench = WritePrimitives(scale_factor=0.01) # your scale factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['merge_scd_type2_basic'])Source
Query text: benchbox/core/write_primitives/operations.py