Commit dde1c51
Fix BSL adapter: compound expressions, joins, filters, time dims (#113)
* Fix BSL adapter: compound expressions, with: joins, filters, time dimensions
Extend the BSL expression parser to handle compound arithmetic
(_.a - _.b).sum() and boolean comparison (_.col == "val").sum()
expressions that previously fell through to the fallback.
Add support for BSL YAML features that were silently ignored:
- with: join syntax (shorthand for left_on/right_on)
- Model-level primary_key, time_dimension, smallest_time_grain
- Model-level filter expressions (parsed via AST, stored as Segment)
- calculated_measures section
Store original BSL expressions in metadata for lossless roundtrip
instead of fragile regex reconstruction. Add bsl_filter_to_sql with
proper AST-based conversion. Add second/minute to Model.default_grain
for consistency with Dimension.granularity.
* Auto-update JSON schema
* Fix filter precedence and COUNT(*) export regression
Wrap filter operands in parens when translating & / | to AND / OR
so mixed-precedence filters preserve grouping.
Handle COUNT(*) metrics (agg="count", sql=None) in cross-format
export path to emit _.count() instead of _.name.count().
* Fix nested arithmetic grouping and composite FK export
Wrap nested BinOp children in parens in _binop_to_sql so
(_.a - (_.b + _.c)).sum() produces "a - (b + c)" not "a - b + c".
Only emit with: join shorthand for single-string foreign keys,
fall back to left_on/right_on for list-typed composite keys.
* Bake model-level filters into model.sql, handle ~ (NOT) in filters
Instead of creating a Segment that callers must explicitly apply,
bake BSL filter: expressions into model.sql as a filtered subquery
(SELECT * FROM table WHERE filter). This matches BSL semantics
where model filters always apply to all queries.
Add ~ (ast.Invert) handling in _filter_node_to_sql so negated
filter expressions like ~(_.origin == 'LAX') produce NOT (origin = 'LAX')
instead of falling through to the regex fallback.
* Preserve filters in cross-format export, handle isin/notin/between
Clear model.table when filter is baked into model.sql so exporters
(Cube, MetricFlow) that prefer table over sql don't silently drop
the filter. Store original table name in metadata for BSL roundtrip.
Add isin/notin/between/isnull/notnull method call handling to
_filter_node_to_sql so _.col.isin(['a','b']) produces
col IN ('a', 'b') instead of falling through to regex fallback.
* Fix operator detection, SQL-to-BSL = -> ==, raise on bad filters
Add >= to _sql_to_bsl_expr operator detection so expressions like
a >= 5 are recognized as compound and wrapped correctly.
Convert SQL = to Python == and <> to != in _sql_to_bsl_expr output
so emitted BSL expressions are valid Python syntax.
Replace silent regex fallback in bsl_filter_to_sql with ValueError
so untranslatable filter expressions fail at parse time instead of
producing invalid SQL at query time.
* Keep model.table for migrator, prefer model.sql in exporters
Restore model.table on filtered BSL models so migrator's
table_to_model index stays intact. Swap export priority in Cube,
MetricFlow, and LookML adapters to check model.sql before
model.table, ensuring filtered subqueries are preserved in
cross-format conversion.
* Support signed numeric literals in BSL filter translation
Python parses -5 as ast.UnaryOp(USub, Constant(5)), not as a negative
Constant. _expr_to_sql only handled Constant, so filters like
_.delta > -5 produced None on the RHS and failed at parse time.
Handle UnaryOp with USub to emit the negated value.
* Format cli.py
* Fix review feedback: align granularity validation, prefer sql in all exporters
* Fix MetricFlow roundtrip: parse sql field so filtered models survive re-import
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>1 parent db1fc81 commit dde1c51
14 files changed
Lines changed: 913 additions & 131 deletions
File tree
- sidemantic
- adapters
- core
- tests/adapters/bsl
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2937 | 2937 | | |
2938 | 2938 | | |
2939 | 2939 | | |
| 2940 | + | |
| 2941 | + | |
2940 | 2942 | | |
2941 | 2943 | | |
2942 | 2944 | | |
| |||
0 commit comments