Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/duckshop-10k/checksum.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
generator 1 files 10874 sha256 4d276ad2428841efa2a1b851c83863bea70505d9e085a71390401399b5667667
generator 2 files 10874 sha256 7dd651a573bce90f9816889cdeece75b9f837137813a033125daafa28b7b70eb
2 changes: 1 addition & 1 deletion benchmarks/duckshop-10k/duckshop10k/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
regenerate checksum.txt, whenever a change alters any generated file.
"""

GENERATOR_VERSION = "1"
GENERATOR_VERSION = "2"
SEED = 20261024
PROJECT_NAME = "duckshop_10k"
14 changes: 4 additions & 10 deletions benchmarks/duckshop-10k/duckshop10k/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
SQL_MACROS: dict[str, str] = {
"cdc_latest": """MACRO (
description "Latest surviving version of each key in an append-only change log",
arguments (
src RELATION (_op VARCHAR, _seq NUMBER(38, 0), _loaded_at TIMESTAMP_NTZ),
key COLUMN OF src,
),
arguments (src RELATION (_op VARCHAR, _seq NUMBER(38, 0), _loaded_at TIMESTAMP_NTZ, key COLUMNS)),
);

WITH cdc_versions AS (
SELECT *
FROM @src
QUALIFY ROW_NUMBER() OVER (PARTITION BY @key ORDER BY _seq DESC) = 1
QUALIFY ROW_NUMBER() OVER (PARTITION BY @src.key ORDER BY _seq DESC) = 1
),

cdc_latest AS (
Expand All @@ -28,16 +25,13 @@
""",
"cdc_history": """MACRO (
description "Every version of each key in a change log, keeping the last one of each load",
arguments (
src RELATION (_op VARCHAR, _seq NUMBER(38, 0), _loaded_at TIMESTAMP_NTZ),
key COLUMN OF src,
),
arguments (src RELATION (_op VARCHAR, _seq NUMBER(38, 0), _loaded_at TIMESTAMP_NTZ, key COLUMNS)),
);

WITH cdc_history AS (
SELECT *
FROM @src
QUALIFY ROW_NUMBER() OVER (PARTITION BY @key, _loaded_at ORDER BY _seq DESC) = 1
QUALIFY ROW_NUMBER() OVER (PARTITION BY @src.key, _loaded_at ORDER BY _seq DESC) = 1
)
""",
"load_metadata": """MACRO (
Expand Down
7 changes: 4 additions & 3 deletions benchmarks/duckshop-10k/duckshop10k/rules_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def _is_change_log(ctx: RuleContext, source: str) -> bool:
code="XSQBRDUCK001",
message="Staging models over a change-log source must deduplicate it with a change-log macro",
remediation=(
"Read the source in an import CTE and follow it with @sql.cdc_latest(<cte>, <key>), or "
"@sql.cdc_history(<cte>, <key>) for a model that keeps every version, so deletes and "
"superseded versions are handled the same way everywhere."
"Read the source in an import CTE and follow it with "
"@sql.cdc_latest(<cte>, src.key := (<key>)), or "
"@sql.cdc_history(<cte>, src.key := (<key>)) for a model that keeps every version, so "
"deletes and superseded versions are handled the same way everywhere."
),
)
def staging_uses_change_log_macro(*, model: Model, ctx: RuleContext) -> list[Finding]:
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/duckshop-10k/duckshop10k/staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def base_model(project: Project, instance: Instance, archetype: Archetype, folde
)
relation = "deduplicated"
else:
ctes.append(f"@sql.cdc_latest(src, {key})")
ctes.append(f"@sql.cdc_latest(src, src.key := ({key}))")
relation = "cdc_latest"
items: list[str] = []
columns: list[Column] = []
Expand Down Expand Up @@ -480,7 +480,7 @@ def history_model(project: Project, instance: Instance, archetype: Archetype, fo
)
ctes = [
import_cte("src", f'__source("{source}")'),
f"@sql.cdc_history(src, {key_physical})",
f"@sql.cdc_history(src, src.key := ({key_physical}))",
cte("versions", f"SELECT\n{select_list(versions)}\nFROM cdc_history AS s"),
cte("final", f"SELECT\n{select_list(items)}\nFROM versions AS h"),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
MACRO (
description "Latest surviving version of each key in an append-only change log",
arguments (
src RELATION (_op VARCHAR, _seq NUMBER(38, 0), _loaded_at TIMESTAMP_NTZ),
key COLUMN OF src,
),
arguments (src RELATION (_op VARCHAR, _seq NUMBER(38, 0), _loaded_at TIMESTAMP_NTZ, key COLUMNS)),
);

WITH cdc_versions AS (
SELECT *
FROM @src
QUALIFY ROW_NUMBER() OVER (PARTITION BY @key ORDER BY _seq DESC) = 1
QUALIFY ROW_NUMBER() OVER (PARTITION BY @src.key ORDER BY _seq DESC) = 1
),

cdc_latest AS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ WITH src AS (
FROM __source("catalogue__brands")
),

@sql.cdc_latest(src, brand_code)
@sql.cdc_latest(src, src.key := (brand_code))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WITH src AS (
FROM __source("catalogue__bundle_components")
),

@sql.cdc_latest(src, component_id)
@sql.cdc_latest(src, src.key := (component_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WITH src AS (
FROM __source("catalogue__bundles")
),

@sql.cdc_latest(src, bundle_sku)
@sql.cdc_latest(src, src.key := (bundle_sku))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("catalogue__categories")
),

@sql.cdc_latest(src, category_id)
@sql.cdc_latest(src, src.key := (category_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("catalogue__price_lists")
),

@sql.cdc_latest(src, price_list_id)
@sql.cdc_latest(src, src.key := (price_list_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("catalogue__product_media")
),

@sql.cdc_latest(src, media_id)
@sql.cdc_latest(src, src.key := (media_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("catalogue__product_variants")
),

@sql.cdc_latest(src, sku)
@sql.cdc_latest(src, src.key := (sku))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WITH src AS (
FROM __source("catalogue__products")
),

@sql.cdc_latest(src, product_id)
@sql.cdc_latest(src, src.key := (product_id))

paths AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("catalogue__supplier_costs")
),

@sql.cdc_latest(src, cost_id)
@sql.cdc_latest(src, src.key := (cost_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WITH src AS (
FROM __source("catalogue__suppliers")
),

@sql.cdc_latest(src, supplier_code)
@sql.cdc_latest(src, src.key := (supplier_code))

contacts AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WITH src AS (
FROM __source("finance__chargebacks")
),

@sql.cdc_latest(src, chargeback_id)
@sql.cdc_latest(src, src.key := (chargeback_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("finance__invoices")
),

@sql.cdc_latest(src, invoice_id)
@sql.cdc_latest(src, src.key := (invoice_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("finance__ledger_entries")
),

@sql.cdc_latest(src, entry_id)
@sql.cdc_latest(src, src.key := (entry_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WITH src AS (
FROM __source("finance__payouts")
),

@sql.cdc_latest(src, payout_id)
@sql.cdc_latest(src, src.key := (payout_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WITH src AS (
FROM __source("finance__tax_rates")
),

@sql.cdc_latest(src, tax_rate_id)
@sql.cdc_latest(src, src.key := (tax_rate_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("fulfilment__carrier_rate_cards")
),

@sql.cdc_latest(src, rate_card_id)
@sql.cdc_latest(src, src.key := (rate_card_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("fulfilment__delivery_exceptions")
),

@sql.cdc_latest(src, exception_id)
@sql.cdc_latest(src, src.key := (exception_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("fulfilment__delivery_slots")
),

@sql.cdc_latest(src, slot_id)
@sql.cdc_latest(src, src.key := (slot_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("fulfilment__pick_tasks")
),

@sql.cdc_latest(src, task_id)
@sql.cdc_latest(src, src.key := (task_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ WITH src AS (
FROM __source("fulfilment__return_inspections")
),

@sql.cdc_latest(src, inspection_id)
@sql.cdc_latest(src, src.key := (inspection_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("fulfilment__returns")
),

@sql.cdc_latest(src, return_id)
@sql.cdc_latest(src, src.key := (return_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WITH src AS (
FROM __source("fulfilment__shipment_packages")
),

@sql.cdc_latest(src, package_id)
@sql.cdc_latest(src, src.key := (package_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("fulfilment__shipments")
),

@sql.cdc_latest(src, shipment_id)
@sql.cdc_latest(src, src.key := (shipment_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("growth__affiliate_conversions")
),

@sql.cdc_latest(src, conversion_id)
@sql.cdc_latest(src, src.key := (conversion_id))

clicks AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WITH src AS (
FROM __source("growth__campaign_spend")
),

@sql.cdc_latest(src, spend_id)
@sql.cdc_latest(src, src.key := (spend_id))

metrics AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WITH src AS (
FROM __source("growth__campaigns")
),

@sql.cdc_latest(src, campaign_id)
@sql.cdc_latest(src, src.key := (campaign_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("growth__influencer_posts")
),

@sql.cdc_latest(src, post_id)
@sql.cdc_latest(src, src.key := (post_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("growth__newsletter_subscriptions")
),

@sql.cdc_latest(src, list_subscription_id)
@sql.cdc_latest(src, src.key := (list_subscription_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WITH src AS (
FROM __source("growth__referral_invites")
),

@sql.cdc_latest(src, invite_id)
@sql.cdc_latest(src, src.key := (invite_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ WITH src AS (
FROM __source("growth__survey_responses")
),

@sql.cdc_latest(src, response_id)
@sql.cdc_latest(src, src.key := (response_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("inventory__bin_locations")
),

@sql.cdc_latest(src, bin_id)
@sql.cdc_latest(src, src.key := (bin_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH src AS (
FROM __source("inventory__po_receipts")
),

@sql.cdc_latest(src, receipt_id)
@sql.cdc_latest(src, src.key := (receipt_id))

final AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH src AS (
FROM __source("inventory__purchase_orders")
),

@sql.cdc_latest(src, po_id)
@sql.cdc_latest(src, src.key := (po_id))

final AS (
SELECT
Expand Down
Loading
Loading