Repository navigation
fix(validation): pass the validator tests on sqlglot 30.34.0 - #810
403pagelabs wants to merge 1 commit into
Conversation
Two tests in validation/tests fail on sqlglot 30.34.0, which the
validation job installs, and pass on 30.29.0 to 30.33.0.
The postgres and redshift readers now parse the unit of DATE_PART and
PGDATE_PART as an expression. Up to 30.33.0 `PGDATE_PART(day, x)` was an
anonymous function, which DATE_PART_FUNCTIONS covers, and postgres
`DATE_PART(day, x)` was an Extract whose unit was a Var. From 30.34.0
both are an Extract whose unit is the column `day`, so the metric check
warned that 'day' is not qualified. is_date_part now reads an unquoted
date part name in the unit position of an Extract as a unit. A quoted
name there is an identifier and is still read as a column, as it is for
snowflake `DATE_PART("day", x)`.
The snowflake-get case wrote `GET file://x @stage`, the file before the
stage, which is PUT's order. The snowflake reader took it as a Get up to
30.33.0 and raises on it from 30.34.0, so the validator reports a parse
error where the test expects "found a GET statement". The case now
writes the stage first, `GET @stage 'file:///tmp/x'`, which is a Get on
every supported version. The text is rejected either way.
Tests added for the postgres DATE_PART unit and for a quoted name in the
unit position. validation/tests gives 1105 passed and 1 skipped on
sqlglot 30.29.0, 30.33.0 and 30.34.0.
kayemkim
left a comment
There was a problem hiding this comment.
Under POSTGRES the new branch reads some unit names as units and reports others. On 30.34.0 with this branch:
MAX(DATE_PART(day, orders.ordered)) no finding
MAX(DATE_PART(isodow, orders.ordered)) Warning: 'isodow' is not qualified
isoyear, julian and timezone get the warning as well. is_date_part_name() goes by sqlglot's alias table, and those four Postgres field names aren't in it. All of them pass on 30.33.0, so this is a second result that differs by version, next to the quoted name under "Not changed". Fine as a follow-up if you'd rather get CI green first.
| findings = _VALIDATE.validate_metric_references(document) | ||
|
|
||
| assert len(findings) == 1 | ||
| assert "'day' is not qualified" in findings[0] |
|
Closing this in favour of #818, which merged this morning and fixes the same two tests: Thanks for the review. On the POSTGRES point I ran the same expressions on
The assertion you flagged against #784 goes away with the branch. |
Summary
The validation job installs the latest sqlglot. Since sqlglot 30.34.0 two tests in
validation/tests/fail onmain:test_metric_check_reads_the_redshift_pgdate_part_unit_as_a_unitexpects no findings and gets a warning that'day' is not qualified.test_rejects_a_dialect_sql_statement_used_as_an_expression[snowflake-get]expects[SQL] ctx: expected an expression, found a GET statementand gets[SQL] ctx: Invalid expression / Unexpected token. Line 1, Col: 19.Both pass on 30.33.0 and on the declared minimum, 30.29.0. Neither failure comes from a change in this repository.
Postgres DATE_PART and Redshift PGDATE_PART
From 30.34.0 the postgres reader parses the first argument of
DATE_PARTas an expression. The redshift reader gained a parser forPGDATE_PARTthat does the same. A unit written as a bare name is now a column in thethisof anExtract.Anonymous(this=PGDATE_PART, expressions=[Column(day), Column(orders.ordered)])Extract(this=Column(day), expression=Column(orders.ordered), date_part=True)is_date_parthandled the anonymous form throughDATE_PART_FUNCTIONSand had no case for a column in the unit position of anExtract, sodaywas checked as a field reference. PostgresDATE_PART(day, orders.ordered)changed in the same way, fromExtract(this=Var(DAY))toExtract(this=Column(day)), with no test on it.The change: an unquoted date part name in the
thisof anExtractis a unit. A quoted name there is an identifier and is still read as a column, which keeps the result for snowflakeDATE_PART("day", x)on every version. It reads the parsed structure and checks no sqlglot version.Snowflake GET
The case wrote
GET file://x @stage, the file before the stage. That is PUT's order; GET takes the stage first. Up to 30.33.0 the snowflake reader accepted it. From 30.34.0@is aSTAGE_PATHtoken and the reader raises because theGethas nothis:Get(this=Parameter(this=Var(this=stage)), target=Var(this=file://x))ParseError: Required keyword: 'this' missing for <class 'sqlglot.expressions.query.Get'>. Line 1, Col: 19.The validator rejects the text on both versions. On 30.34.0 it reports the parse error, since no parse exists to name a statement from. The case now writes
GET @stage 'file:///tmp/x', which is aGeton 30.29.0, 30.33.0 and 30.34.0, so the test checks what its name says: a GET statement used as an expression is named as one.I also have a version that keeps the old input passing by naming the kind of a statement the parser starts and cannot finish (a second parse with
ErrorLevel.IGNORE). It changes the message for every malformed statement on every version and mislabels some broken expressions,update + (1for one, so I left it out. I can open it separately if you want that behaviour.Not changed
One result still differs by sqlglot version. Up to 30.33.0 the postgres reader turns any first argument of
DATE_PARTinto aVarand drops the quotes, so the validator cannot tell"day"fromday. From 30.34.0 the quoted name arrives as a quoted column. A metric that writesDATE_PART("day", orders.ordered)under POSTGRES orPGDATE_PART("day", orders.ordered)under REDSHIFT gets the'day' is not qualifiedwarning on 30.34.0 and no finding on earlier versions. This branch reads a quoted name in the unit position as a column, which matches what the validator already reports for snowflakeDATE_PART("day", x)on every version.Tests
New:
test_metric_check_reads_the_postgres_date_part_unit_as_a_unit(fails onmainwith 30.34.0) andtest_metric_check_reads_a_quoted_name_in_the_unit_position_of_extract_as_a_column(a guard, passes before and after).uv run --with pytest --with pyyaml --with jsonschema --with "sqlglot==X" -m pytest validation/tests/ -qmainThese counts are from macOS. The skipped test needs a file name that is not valid UTF-8, which the local file system refuses.
uv run --with "sqlglot==X" validation/test_validate.pyreports OK on all three. On this branch with the latest sqlglot:python/tests/295 passed,scripts/tests/15 passed,scripts/generate-spec-types.py --checkexits 0.Related Issues
None filed. Validation CI on
mainhas failed on these two tests since sqlglot 30.34.0 was released.Checklist
Tests
pytest/ CI green)