From 69612b2bcf4f79ed342a5b683e84c06dc22b9ff2 Mon Sep 17 00:00:00 2001 From: Nico Ritschel Date: Sun, 4 Jan 2026 20:39:30 -0800 Subject: [PATCH 1/2] Skip passthrough dims in Malloy export --- .../malloy_demo/malloy_output/thelook.malloy | 17 ----------------- sidemantic/adapters/malloy.py | 14 +++++++++++--- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/examples/malloy_demo/malloy_output/thelook.malloy b/examples/malloy_demo/malloy_output/thelook.malloy index 9c2e0f6e..6f57abfe 100644 --- a/examples/malloy_demo/malloy_output/thelook.malloy +++ b/examples/malloy_demo/malloy_output/thelook.malloy @@ -1,12 +1,6 @@ # desc: Product catalog source: products is duckdb.table('data/products.parquet') extend { - dimension: - name is name - category is category - subcategory is subcategory - price is price - measure: # desc: Number of products product_count is count() @@ -17,12 +11,6 @@ source: products is duckdb.table('data/products.parquet') extend { # desc: Customer master data source: customers is duckdb.table('data/customers.parquet') extend { - dimension: - name is name - email is email - region is region - tier is tier - measure: # desc: Total number of customers customer_count is count() @@ -32,11 +20,6 @@ source: customers is duckdb.table('data/customers.parquet') extend { source: orders is duckdb.table('data/orders.parquet') extend { dimension: - customer_id is customer_id - product_id is product_id - quantity is quantity - amount is amount - status is status created_time is created_at created_date is created_at created_week is created_at diff --git a/sidemantic/adapters/malloy.py b/sidemantic/adapters/malloy.py index 89ac5093..df635ea5 100644 --- a/sidemantic/adapters/malloy.py +++ b/sidemantic/adapters/malloy.py @@ -852,14 +852,22 @@ def _export_source(self, model: Model) -> list[str]: # Dimensions # Skip dimensions that match the primary key (Malloy auto-exposes the PK column) - dims_to_export = [dim for dim in model.dimensions if dim.name != model.primary_key] + # and passthrough dimensions that just re-declare an existing column. + dims_to_export: list[tuple[Dimension, str]] = [] + for dim in model.dimensions: + if dim.name == model.primary_key: + continue + sql = self._strip_model_prefix(dim.sql or dim.name).strip() + if sql == dim.name: + continue + dims_to_export.append((dim, sql)) + if dims_to_export: lines.append("") lines.append(" dimension:") - for dim in dims_to_export: + for dim, sql in dims_to_export: if dim.description: lines.append(f" # desc: {dim.description}") - sql = self._strip_model_prefix(dim.sql or dim.name) lines.append(f" {dim.name} is {sql}") # Measures From 82e13fadec9d92e166e2738340ea6ee6b8276b34 Mon Sep 17 00:00:00 2001 From: Nico Ritschel Date: Sun, 4 Jan 2026 20:45:03 -0800 Subject: [PATCH 2/2] Emit except list for passthrough Malloy dims --- .../malloy_demo/malloy_output/thelook.malloy | 23 +++++++++++++++++++ sidemantic/adapters/malloy.py | 14 +++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/examples/malloy_demo/malloy_output/thelook.malloy b/examples/malloy_demo/malloy_output/thelook.malloy index 6f57abfe..5f1ae2bd 100644 --- a/examples/malloy_demo/malloy_output/thelook.malloy +++ b/examples/malloy_demo/malloy_output/thelook.malloy @@ -1,6 +1,14 @@ # desc: Product catalog source: products is duckdb.table('data/products.parquet') extend { + except: name, category, subcategory, price + + dimension: + name is name + category is category + subcategory is subcategory + price is price + measure: # desc: Number of products product_count is count() @@ -11,6 +19,14 @@ source: products is duckdb.table('data/products.parquet') extend { # desc: Customer master data source: customers is duckdb.table('data/customers.parquet') extend { + except: name, email, region, tier + + dimension: + name is name + email is email + region is region + tier is tier + measure: # desc: Total number of customers customer_count is count() @@ -19,7 +35,14 @@ source: customers is duckdb.table('data/customers.parquet') extend { # desc: Customer orders with status and revenue tracking (LookML format) source: orders is duckdb.table('data/orders.parquet') extend { + except: customer_id, product_id, quantity, amount, status + dimension: + customer_id is customer_id + product_id is product_id + quantity is quantity + amount is amount + status is status created_time is created_at created_date is created_at created_week is created_at diff --git a/sidemantic/adapters/malloy.py b/sidemantic/adapters/malloy.py index df635ea5..d872f992 100644 --- a/sidemantic/adapters/malloy.py +++ b/sidemantic/adapters/malloy.py @@ -851,16 +851,22 @@ def _export_source(self, model: Model) -> list[str]: lines.append(f" primary_key: {model.primary_key}") # Dimensions - # Skip dimensions that match the primary key (Malloy auto-exposes the PK column) - # and passthrough dimensions that just re-declare an existing column. + # Skip dimensions that match the primary key (Malloy auto-exposes the PK column). + # For passthrough dimensions (sql == name), Malloy requires excluding the base + # field before redefining, so we emit an `except:` list. dims_to_export: list[tuple[Dimension, str]] = [] + passthrough_dims: list[str] = [] for dim in model.dimensions: if dim.name == model.primary_key: continue sql = self._strip_model_prefix(dim.sql or dim.name).strip() - if sql == dim.name: - continue dims_to_export.append((dim, sql)) + if sql == dim.name: + passthrough_dims.append(dim.name) + + if passthrough_dims: + lines.append("") + lines.append(f" except: {', '.join(passthrough_dims)}") if dims_to_export: lines.append("")