Repository navigation
Conversation
… functions Follow-up to apache#792. The field aggregate check named a call after sqlglot's class, not the function the expression writes, so VAR_POP(x) was reported as VARIANCE_POP, VAR_SAMP(x) as VARIANCE and APPROX_COUNT_DISTINCT(x) as APPROX_DISTINCT. The name is now read from the expression text at the call's token position. _parse_sql_expression may parse the text as written, as SELECT {text}, or with its first token quoted, so each of those offsets is tried, and a slice is used only when it is a name sqlglot reads as the call's class; otherwise the class's name is kept. Ranking and offset functions were handled by the same check because sqlglot classes most of them as aggregates: RANK() in a field was reported as an aggregation, and ROW_NUMBER(), which is not an AggFunc in sqlglot, was not reported at all. expression_language.md defines each of them only with an OVER clause, in fields and metrics alike, so the OSSIE_SQL_2026 construct check now rejects ROW_NUMBER, RANK, DENSE_RANK, NTILE, PERCENT_RANK, CUME_DIST, LAG, LEAD, FIRST_VALUE, LAST_VALUE and NTH_VALUE without one, and the field aggregate check leaves them to it. The grammar reads them as ordinary function calls, so compliance/expressions is unchanged. The window detection moves to a shared _is_windowed helper, and the bare projection test runs once for each expression instead of once for each call.
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.
Summary
Follow-up to #792, covering two points from its review.
Functions are named as written. The field aggregate check named a call after sqlglot's class, so the error could name a function that is not in the expression:
VAR_POP(x)calls VARIANCE_POPcalls VAR_POPVAR_SAMP(x)calls VARIANCEcalls VAR_SAMPAPPROX_COUNT_DISTINCT(x)calls APPROX_DISTINCTcalls APPROX_COUNT_DISTINCTVAR_SAMP(x) + VARIANCE(x)calls VARIANCEcalls VAR_SAMP, VARIANCEVAR_SAMPandVARIANCEparse to the same sqlglot class, so the name is read from the expression text at the call's token position (call.meta)._parse_sql_expressionmay parse the text as written, asSELECT {text}, or with its first token quoted, so each offset is tried. A slice is used only when it is a name sqlglot reads as that class; otherwise the class's name is kept, as before.Window functions need an OVER clause. sqlglot classes most ranking and offset functions as aggregates, so in a field
RANK()was reported as an aggregation, whileROW_NUMBER()(not anAggFuncin sqlglot) was not reported at all.expression_language.md(Window Functions) definesROW_NUMBER,RANK,DENSE_RANK,NTILE,PERCENT_RANK,CUME_DIST,LAG,LEAD,FIRST_VALUE,LAST_VALUEandNTH_VALUEonly with an OVER clause, in fields and metrics alike. So the OSSIE_SQL_2026 construct check (_portable_sql_construct_error) now rejects them without one, and the field aggregate check leaves them to it:A call in a window's PARTITION BY or ORDER BY, or in the argument of the windowed call, is not windowed, so
RANK() OVER (ORDER BY LAG(x))reportsLAG. Other dialects are left alone. The grammar reads these as ordinary function calls, socompliance/expressions/is unchanged.Smaller changes: the window detection moves to a shared
_is_windowedhelper, and_is_bare_projection(tree)runs once for each expression instead of once for each call.Not in this PR
x + (SELECT SUM(x)), is left to feat(validation): reject queries in portable expressions and parse query sources #698, which rejects queries in portable expressions.LISTAGG,BIT_AND,EVERY, ...) still passes in OSSIE_SQL_2026. Rejecting a function the language does not define is a separate check, since vendor functions belong in a dialect entry.Impact on existing documents
validate_documentover the YAML model and mapping documents in apache/ossie atd4dca4eand apache/ossie-converters at62a61ba(103 documents, 705 fields) gives the same findings as onmain. The windowedLAG(SUM(...), 1) OVER (...)metric inexamples/tpcds_semantic_model.yamlstays valid.Testing
pytest validation/tests/goes from 1026 to 1060 passed (1 skipped) on sqlglot 30.33.0. On 30.19.0 the only failures are the two from validation: two tests fail on sqlglot 30.19.0, the declared minimum #767, the same as onmain.make checkpasses.Related Issues
Follow-up to #792 (fixes #785).
Checklist
Specification
core-spec/and follow the existing structure[DISCUSS]thread ondev@with a stated end date, and reach lazy consensus (or pass a[VOTE]) before mergedocs/spec_changes.mdrecords rationale, compatibility and migration impact, or the PR explains why no entry is needed (no spec change: the validator now enforces whatexpression_language.mdalready says)Ontology
ontology/are consistent with spec changesConverters
Validation
validation/are updated if the spec changedDocumentation
docs/is updated to reflect any user-facing changesCONTRIBUTING.mdis updated if the contribution process changedExamples
examples/are added or updated for any new spec constructsTests
pytest/ CI green)Compliance
NOTICEand/orLICENSEhave been updated per ASF policy