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
6 changes: 6 additions & 0 deletions examples/malloy_demo/malloy_output/thelook.malloy
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# desc: Product catalog
source: products is duckdb.table('data/products.parquet') extend {

except: name, category, subcategory, price

dimension:
name is name
category is category
Expand All @@ -17,6 +19,8 @@ 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
Expand All @@ -31,6 +35,8 @@ 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
Expand Down
22 changes: 18 additions & 4 deletions sidemantic/adapters/malloy.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,29 @@ 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)
dims_to_export = [dim for dim in model.dimensions if dim.name != model.primary_key]
# 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()
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("")
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
Expand Down