Repository navigation
Conversation
… a column
sqlglot's default parser does not know the spec's part-first DATEDIFF(part,
start, end) and DATEADD(part, amount, date). It reads the part as a column and,
for DATEDIFF, the end date as the unit. Two converters' real M6 returns were
graded wrong in opposite directions:
- dbt returns AVG(DATEDIFF(DAY, order_date, ship_date)), which is the same
expression, but it was graded "review: normalized trees differ".
- cube exports DATEDIFF({CUBE}.day, ...), which reads a day column the table
does not have. It came back as DATEDIFF(sales.day, ...) and was graded
cosmetic, because the qualifier of a name no dataset declares is dropped.
The grader now reads a bare first argument as the part before resolving
qualifiers. A qualified first argument stays a column and needs review.
…e and bare-form rule The manifest header still said rungs M0-M3 and gave the validation baseline from before M4-M6. The README still said the bare form was pending apache#486 and apache#343, which apache#631 resolved by carrying it as a dataset-scoped metric.
MrBlack1995
approved these changes
Nov 19, 2026
MrBlack1995
left a comment
Contributor
There was a problem hiding this comment.
Thanks for taking this one, it is the M6 gap I asked about on #631. Reading the bare first argument as the part before resolving qualifiers is the right place for it, and the dbt and cube returns make good tests.
What I checked here:
- The 54 grader tests pass on the branch.
- Since #756 and #757 landed, this conflicts with main in
grade.pyandtest_grade.py. I resolved it locally by keeping main's version and calling_read_date_parts(tree)right aftersqlglot.parse_one(text, read=reader)incanonical: all 61 tests pass (main's plus yours), so the part reading works under both NULL-ordering readers from #756. - A few cases beyond the tests, on that merged version:
'day'vsdayandDayvsDAYare cosmetic; a different part, orDATEADD(day, 7, ...)vsDATEADD(day, 8, ...), needs review; an end date that is an expression (CURRENT_DATE,ship_date + 1) still compares; a qualified first argument (sales.day) stays a column and needs review.
One note for the ladder, not for this PR: the grader can now tell that dbt's DATEDIFF(DAY, ...) is the same text as the authored one, but not that the same text can return different numbers on different engines for month and year. That is the open question in #743, where djwaldo's probe now points to boundary counting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #631, addressing the non-blocking review comments.
Changes
The grader reads the part of
DATEDIFFandDATEADDas a part. sqlglot's default parser does not know the spec's part-firstDATEDIFF(part, start, end)andDATEADD(part, amount, date). It reads the part as a column and, forDATEDIFF, the end date as the unit. Two converters' real M6 returns were graded wrong, in opposite directions:AVG(DATEDIFF(DAY, order_date, ship_date)), which is the same expression, but it was gradedreview: normalized trees differ.DATEDIFF({CUBE}.day, {CUBE}.order_date, {CUBE}.ship_date), which reads adaycolumn the table doesn't have. It comes back asDATEDIFF(sales.day, ...)and was graded cosmetic, because the grader drops the qualifier of a name no dataset declares.The grader now reads a bare first argument (or a string literal) as the part before resolving qualifiers. A qualified first argument stays a column and needs review.
validate.pyworks around the same parser behavior initer_columns. The grader keeps its own copy because it imports nothing from the repository, and apache/ossie-converters loads it by path.Tests built from dbt's and cube's real M6 returns. Two more cover a different part or swapped dates (both need review), and
DATEADDin a field expression, where a part read as a column would resolve to the field's own dataset.Docs:
manifest.yamlheader now says rungs M0-M6 and gives a validation baseline on current main.Testing
PYTHONPATH=. pytest test_grade.py: 54 tests pass with sqlglot 30.33.0, and with 30.31.0, the version the converters grade with. Without the fix, 3 of the 4 new tests fail. The fourth (a different part, swapped dates) checks that the change does not make a real difference look cosmetic.reviewto cosmetic, and cube from cosmetic toreview.validate.pypasses all 13 fixtures with no warnings on main (6160adf), with sqlglot 30.33.0.Related Issues
Refs apache/ossie-converters#24.