Repository navigation
fix: support partitioned_by = <expr> in model definitions - #6294
andretorresdg wants to merge 1 commit into
Conversation
Consume the optional '=' before parsing the partitioned_by value. ClickHouse's _parse_partitioned_by does not accept it, so the model failed to load. Dialects that do accept it could keep it in the SQL stored in state (e.g. BigQuery with a function expression), which then failed to deserialize with "Failed to parse '(= ...)' into PartitionedByProperty". Signed-off-by: Andre Devay <andretorresdg@alumni.usp.br>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Description
Fixes #5234
partitioned_by = <expr>(with=) in aMODELblock is not handled consistently:_parse_partitioned_bydoesn't skip the=, so on currentmain(sqlglot 30.8) the model fails to load withRequired keyword: 'this' missing for EQ._parse_partitioned_byconsumes the=, but the start token formeta["sql"]is recorded before it, so the SQL kept for state can include it. For example, with BigQuerypartitioned_by = DATE_TRUNC(ds, MONTH)is stored as"= DATE_TRUNC(ds, MONTH)", and loading it back fails withFailed to parse '(= DATE_TRUNC(ds, MONTH))' into PartitionedByProperty. This is the error from the issue.The fix consumes the optional
=in SQLMesh's model parser before recording the start token and calling_parse_partitioned_by.partitioned_by = xnow gives the same result aspartitioned_by xin every dialect.Test Plan
Added
test_partitioned_by_with_equals_signintests/core/test_model.py, parametrized over ClickHouse (single expression and tuple) and BigQuery. It loads the model, checkspartitioned_by, then round-trips it throughSqlModel.parse_raw(model.json()). All 3 cases fail without the change and pass with it.tests/core/test_model.pyandtests/core/test_dialect.pygive the same results as onmainapart from the 3 new cases.ruff check,ruff format --checkandmypypass on the changed files.Checklist
make styleand fixed any issues (ran ruff and mypy on the changed files)make fast-test) (rantests/core/test_model.pyandtests/core/test_dialect.pyonly)git commit -s) per the DCO