Repository navigation
fix(data-diff): quote BigQuery/Spark/Databricks/Hive identifiers with backticks #1873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,14 +44,19 @@ function quoteIdentForDialect(identifier: string, dialect: string): string { | |
| case "mysql": | ||
| case "mariadb": | ||
| case "clickhouse": | ||
| // A double-quoted token is a string literal in these engines, not a name. | ||
| case "bigquery": | ||
| case "spark": | ||
| case "databricks": | ||
|
Comment on lines
+48
to
+50
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Uncapped warehouse queries per partition For categorical diffs on BigQuery and default Databricks, Learn moreThe data diff tool lets an agent choose categorical partitioning, and its read permission prompt does not describe the job count or cost. Before this change, the double-quoted categorical column on BigQuery and default Databricks selected one constant from each nonempty table. Correct identifier quoting now makes partition discovery retrieve every distinct value across both tables. The partition loop starts a new engine session for every value. The step limit resets in each session, so it does not limit the total work. Example: Comparing two large BigQuery event tables by a string-valued customer ID with 10,000 distinct customers starts 10,000 separate diffs. The initial approval to read both tables does not disclose that query fan-out. Recommended fix: Bound discovery and the overall job budget rather than only the steps per partition. Before running above that budget, show a warehouse cost estimate and require explicit confirmation, as required by the cost review rule. Was this helpful? React with 👍 or 👎 to provide feedback.
Comment on lines
+48
to
+50
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Apostrophes break categorical partition comparisons
Learn morePartition discovery reads distinct category values from the warehouse once the column is quoted correctly. The partition loop builds a separate filter from each returned value. Both filters use buildPartitionWhereClause, which always doubles apostrophes. The dialect-aware batch SQL tests record that BigQuery requires a backslash escape and Databricks interprets doubled apostrophes as string concatenation. The diff therefore does not check the discovered rows in either warehouse for these values. Example: A partition value of Recommended fix: Bind partition values as parameters where the execution path supports them. Otherwise use a dialect-aware value encoder that preserves apostrophes and backslashes, and add coverage that checks what each warehouse reads rather than only comparing generated SQL strings. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| case "hive": | ||
| return `\`${identifier.replace(/`/g, "``")}\`` | ||
| case "tsql": | ||
| case "fabric": | ||
| case "sqlserver": | ||
| case "mssql": | ||
| return `[${identifier.replace(/\]/g, "]]")}]` | ||
| default: | ||
| // ANSI SQL: Postgres, Snowflake, BigQuery, DuckDB, Oracle, Redshift, etc. | ||
| // ANSI SQL: Postgres, Snowflake, DuckDB, Oracle, Redshift, etc. | ||
| return `"${identifier.replace(/"/g, '""')}"` | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 BigQuery boolean partitions fail comparison
quoteIdentForDialectnow lets discovery read a BigQuery boolean partition column. buildPartitionWhereClause compares it with a string literal, which BigQuery rejects.Learn more
The data diff tool advertises boolean columns for categorical partitioning. The BigQuery driver returns row values as supplied by the client, but executeQuery converts them to strings. buildPartitionWhereClause then wraps each value in single quotes. GoogleSQL does not coerce STRING literals to BOOL for equality comparisons.
Example: Partitioning two BigQuery tables by their
is_activeboolean column discoverstrueandfalse, then generates predicates such asis_active = 'true'. BigQuery rejects the predicate instead of comparing active rows.Recommended fix: Retain the discovered value type for predicate construction, or bind a typed parameter. Emit
TRUEandFALSEfor boolean columns while preserving'true'and'false'for string columns.Was this helpful? React with 👍 or 👎 to provide feedback.