Skip to content

fix(validation): pass the validator tests on sqlglot 30.34.0 - #810

Closed
403pagelabs wants to merge 1 commit into
apache:mainfrom
403pagelabs:validation-sqlglot-30-34
Closed

403pagelabs wants to merge 1 commit into
apache:mainfrom
403pagelabs:validation-sqlglot-30-34

Conversation

@403pagelabs

Copy link
Copy Markdown
Contributor

Summary

The validation job installs the latest sqlglot. Since sqlglot 30.34.0 two tests in validation/tests/ fail on main:

  • test_metric_check_reads_the_redshift_pgdate_part_unit_as_a_unit expects 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 statement and 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_PART as an expression. The redshift reader gained a parser for PGDATE_PART that does the same. A unit written as a bare name is now a column in the this of an Extract.

python -c "import sqlglot; print(repr(sqlglot.parse_one('PGDATE_PART(day, orders.ordered)', dialect='redshift')))"
  • 30.33.0: Anonymous(this=PGDATE_PART, expressions=[Column(day), Column(orders.ordered)])
  • 30.34.0: Extract(this=Column(day), expression=Column(orders.ordered), date_part=True)

is_date_part handled the anonymous form through DATE_PART_FUNCTIONS and had no case for a column in the unit position of an Extract, so day was checked as a field reference. Postgres DATE_PART(day, orders.ordered) changed in the same way, from Extract(this=Var(DAY)) to Extract(this=Column(day)), with no test on it.

The change: an unquoted date part name in the this of an Extract is a unit. A quoted name there is an identifier and is still read as a column, which keeps the result for snowflake DATE_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 a STAGE_PATH token and the reader raises because the Get has no this:

  • 30.33.0: Get(this=Parameter(this=Var(this=stage)), target=Var(this=file://x))
  • 30.34.0: 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 a Get on 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 + (1 for 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_PART into a Var and drops the quotes, so the validator cannot tell "day" from day. From 30.34.0 the quoted name arrives as a quoted column. A metric that writes DATE_PART("day", orders.ordered) under POSTGRES or PGDATE_PART("day", orders.ordered) under REDSHIFT gets the 'day' is not qualified warning 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 snowflake DATE_PART("day", x) on every version.

Tests

New: test_metric_check_reads_the_postgres_date_part_unit_as_a_unit (fails on main with 30.34.0) and test_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/ -q

sqlglot main this branch
30.29.0 1103 passed, 1 skipped 1105 passed, 1 skipped
30.33.0 1103 passed, 1 skipped 1105 passed, 1 skipped
30.34.0 2 failed, 1101 passed, 1 skipped 1105 passed, 1 skipped

These 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.py reports OK on all three. On this branch with the latest sqlglot: python/tests/ 295 passed, scripts/tests/ 15 passed, scripts/generate-spec-types.py --check exits 0.

Related Issues

None filed. Validation CI on main has failed on these two tests since sqlglot 30.34.0 was released.

Checklist

Tests

  • All existing tests pass (pytest / CI green)

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 kayemkim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged with #784 this test fails on 30.29.0 and 30.34.0. #784 prints an identifier as written, so the finding reads '"day"' is not qualified. assert "is not qualified" in findings[0] passes with #784 and without it.

@403pagelabs

403pagelabs commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing this in favour of #818, which merged this morning and fixes the same two tests: is_date_part reads the unit of the Extract that PGDATE_PART now parses to and the GET case writes the stage first. main is green without this branch.

Thanks for the review. On the POSTGRES point I ran the same expressions on main after #818:

POSTGRES expression sqlglot 30.33.0 sqlglot 30.34.0
MAX(DATE_PART(day, orders.ordered)) no finding 'day' is not qualified
MAX(DATE_PART(isodow, orders.ordered)) no finding 'isodow' is not qualified
MAX(DATE_PART('day', orders.ordered)) no finding no finding
MAX(EXTRACT(isodow FROM orders.ordered)) no finding no finding

isoyear, julian and timezone behave like isodow. I think 30.34.0 has it right. PostgreSQL takes the unit of date_part as a string, so select date_part(day, now()) fails with column "day" does not exist (checked on PostgreSQL 18) and the warning says what the database says. This branch read DATE_PART(day, x) as a unit under POSTGRES, which was the wrong half of the fix. #818 leaves it alone.

The assertion you flagged against #784 goes away with the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants