Repository navigation
Conversation
christianeu-db
left a comment
There was a problem hiding this comment.
Thanks @vigneshio! The comments on vendor dialects and on the pytest failures should be fixed before merge.
cc @kayemkim if you want to take a look as well
| return errors | ||
|
|
||
|
|
||
| def _sql_ident(part) -> str: |
There was a problem hiding this comment.
A vendor-dialect entry now gets the OSSIE_SQL_2026 quoting rule, so references that are valid in that dialect fail validation (both passed on main):
POSTGRES SUM("amount") -> references undeclared field(s) '"amount"'
BIGQUERY SUM(`amount`) -> references undeclared field(s) '"amount"'
expression_language.md gives the double-quote rule for the Ossie dialect and calls quoted-versus-unquoted comparison DB specific. Could _sql_ident apply only to OSSIE_SQL_2026 entries, as the AGG checks do, and keep the old comparison for other dialects?
There was a problem hiding this comment.
Makes sense, _sql_ident and the declared-name maps now follow the quoting table only for OSSIE_SQL_2026. POSTGRES SUM("amount") and BIGQUERY SUM(`amount`) keep the case-insensitive lookup they had on main.
| continue | ||
| name = member.get("name") | ||
| if isinstance(name, str) and name: | ||
| names.add(declared_name(name)) |
There was a problem hiding this comment.
Two existing tests in validation/tests/ now fail, because declared_name runs during validate_sql and its parse_one is outside _quiet_sqlglot:
FAILED test_another_thread_keeps_its_sqlglot_warnings_while_one_probes
FAILED test_a_validation_that_finishes_does_not_unquiet_one_still_running
CI stops at the duplicate-key tests before it reaches them. Could declared_name get @_quiet_sqlglot(), as expression_is_empty has?
There was a problem hiding this comment.
declared_name now has @_quiet_sqlglot(), same as expression_is_empty. That parse is the first one on the validate_sql path once field names are keyed that way, so the two thread tests were seeing an unquieted parse_one.
| dataset_label = idents[0].name if idents else arg.table | ||
| return ( | ||
| f"AGG({arg.table}.{arg.name}): '{arg.name}' is not a dataset-scoped metric of " | ||
| f"dataset '{arg.table}'" | ||
| f"AGG({written}): '{idents[-1].name if idents else arg.name}' is not a " |
There was a problem hiding this comment.
Not a blocker: these messages drop the quotes from the identifier, so they read as if a declared name, or the source qualifier, were wrong:
AGG(orders."total"): 'total' is not a dataset-scoped metric of dataset 'orders'
'"orders".amount' references unknown dataset 'orders'
uses qualified reference(s) 'source'
Could the metric name and dataset label in agg_argument_problem, the unknown-dataset label in validate_metric_references, and the qualifier in scope_errors print the identifier as written, as the mapping check does ('"orders"')? The two new AGG tests that assert the unquoted text would change with it.
There was a problem hiding this comment.
Labels in agg_argument_problem, the unknown-dataset message in validate_metric_references, and the qualifier in scope_errors now print the identifier as written, quotes included. The two AGG tests assert '"total"' and '"order_revenue"'.
There was a problem hiding this comment.
The messages now print identifiers as written, but _ident_written and _column_written render them in sqlglot's default dialect, so a BIGQUERY reference shows double quotes where the model has backticks:
SUM(`orders`.nope) -> '"orders".nope' is not a declared field of dataset '"orders"'
Could both render in the expression's dialect through SQLGLOT_DIALECTS, as _expression_with_first_token_quoted does with .sql(dialect=dialect)? Fine as a follow-up if you'd prefer.
There was a problem hiding this comment.
Left the dialect of the labels for a follow-up. _ident_written still uses part.sql() in the default dialect, so a BIGQUERY backtick still prints as double quotes.
3bcdd10 to
5db6937
Compare
christianeu-db
left a comment
There was a problem hiding this comment.
@vigneshio can you take a look at the failing CI when you have the chance?
|
@vigneshio the two failing tests aren't from your change. sqlglot 30.34.0 came out shortly before this run started, and main fails on the same two with it. Merged onto main your branch passes on 30.33.0. #810 fixes them, and I left a note there on its new quoted-name test, which asserts |
kayemkim
left a comment
There was a problem hiding this comment.
names_cache in _expressions_in() lives for one field or metric, so _expression_field_names() runs again for every member of a dataset, and every name in it goes through declared_name(), which parses with sqlglot. The time grows with the square of the field count. A dataset of 400 fields written with sql validates in 0.3 s on main and in about 8.5 s on this branch, and one of 1,600 fields takes over two minutes. The examples in the repository stop at 21 fields, so nothing there shows it. With functools.lru_cache on declared_name() the 400-field document is back at 0.4 s and the suite passes.
The comparison itself matches the table in expression_language.md for the declared names and reference forms I tried under sql and OSSIE_SQL_2026: regular and mixed-case names, names that need quotes, and the source qualifier. Other dialects resolve as on main.
Metric references, dataset-scoped scoping, AGG, and field shadowing
compared SQL names with casefold, so SUM("Amount") matched field amount
and AGG(orders."total") matched metric total. The mapping checker
already follows expression_language.md: a regular identifier upper-cases,
a quoted one matches as written.
Reuse normalized_identifier and declared_name for those SQL lookups.
YAML keys and relationship lists stay on dataset_field_names (casefold).
The source qualifier is the regular identifier SOURCE; quoted "source"
is not.
Quoted versus unquoted identifier matching is DB specific
(expression_language.md). Vendor dialects keep the case-insensitive
lookup they had; POSTGRES SUM("amount") and BIGQUERY SUM(`amount`)
against field amount stay valid.
Quiet declared_name the same way as other probes, so it is not the
first unquieted parse on the validate_sql path. Print identifiers as
written in AGG and scope labels.
names_cache in _expressions_in is per member, so every YAML name was parsed once per field. Cache the parse. Vendor dialects still casefold without it. Quoted "amount" stays an ANSI pass-through, as on main.
5db6937 to
5150a67
Compare
|
Rebased onto main so this picks up #818. The GET / PGDATE_PART failures were sqlglot 30.34.0 on main, same as you mentioned. The quoted-name clash with #810 went away when #818 replaced it. |
christianeu-db
left a comment
There was a problem hiding this comment.
Thanks @vigneshio, this looks good to me now. Pre-commit fails on the ruff hooks that #818 added: make pre-commit fixes the formatting, and D401/D205 on the new docstrings and B023 on by_name need small edits by hand. Happy to approve once it's green.
MrBlack1995
left a comment
There was a problem hiding this comment.
Converters are the main writers of quoted identifiers, so I ran this branch (5150a67) and main (59080f6) over real documents and compared the diagnostics:
- the latest Interop matrix run on ossie-converters main: every input and every document a converter returned in the 272 portability cases, 514 documents;
- the 17 fixtures under
compliance/portabilityand the 11 documents underexamples.
Both validators report the same on every one of them, so nothing the converters return today starts to fail or to warn.
One case that may surprise an author, and that I did not find a test for: a field declared with a mixed-case name that needs no quotes, name: Amount, is the regular identifier AMOUNT, so SUM(orders."Amount") now gets 'orders."Amount"' is not a declared field of dataset 'orders'. name: Order Amount with SUM(orders."Order Amount") passes, because that name can only be written quoted. Both follow from the comparison table in expression_language.md. A test with a mixed-case declared name would pin the first case down, and the message could say that the declared name is read as a regular identifier. Fine as a follow-up.
I did not run the test suite or pre-commit on this head.
jbonofre
left a comment
There was a problem hiding this comment.
LGTM. Thanks @vigneshio!
I pushed a small commit to address the pre-commit Ruff lint and formatting checks.
Metric references, dataset-scoped scoping, AGG, and field shadowing compared SQL names with
casefold, soSUM("Amount")matched fieldamountandAGG(orders."total")matched metrictotal. The mapping checker already followsexpression_language.md: a regular identifier upper-cases, a quoted one matches as written.This reuses
normalized_identifieranddeclared_namefor those SQL lookups. YAML keys and relationship lists stay ondataset_field_names(casefold). Thesourcequalifier is the regular identifierSOURCE; quoted"source"is not