Repository navigation
fix(data-diff): quote BigQuery/Spark/Databricks/Hive identifiers with backticks - #1873
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
… backticks Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
👋 This PR was automatically closed by our quality checks. Common reasons:
If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you. |
There was a problem hiding this comment.
Devin Review found 3 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| case "bigquery": | ||
| case "spark": | ||
| case "databricks": |
There was a problem hiding this comment.
🔴 Uncapped warehouse queries per partition
For categorical diffs on BigQuery and default Databricks, quoteIdentForDialect lets discovery return one partition per distinct value. runPartitionedDiff starts a separate warehouse diff for every value without a cap or cost confirmation.
Learn more
The 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.
| case "bigquery": | ||
| case "spark": | ||
| case "databricks": |
There was a problem hiding this comment.
🟡 Apostrophes break categorical partition comparisons
quoteIdentForDialect now lets discovery return actual category values, including names with apostrophes. buildPartitionWhereClause doubles the apostrophe, which BigQuery rejects and Databricks drops. The partition either fails or compares the wrong rows.
Learn more
Partition 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 O'Brien produces 'O''Brien'. BigQuery rejects the adjacent literals; Databricks reads them as OBrien and can report an empty, identical partition even if the O'Brien rows differ.
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 "mariadb": | ||
| case "clickhouse": | ||
| // A double-quoted token is a string literal in these engines, not a name. | ||
| case "bigquery": |
There was a problem hiding this comment.
🟡 BigQuery boolean partitions fail comparison
quoteIdentForDialect now 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_active boolean column discovers true and false, then generates predicates such as is_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 TRUE and FALSE for boolean columns while preserving 'true' and 'false' for string columns.
Was this helpful? React with 👍 or 👎 to provide feedback.
Issue for this PR
Closes #1820
Type of change
What does this PR do?
quoteIdentForDialectinpackages/opencode/src/altimate/native/connections/data-diff.tssent BigQuery, Spark, Databricks and Hive to the ANSI branch, so identifiers came out double-quoted. In those engines "name" is a string literal, so a partitioned diff's WHERE "status" = 'open' compared two constants and a CTE-wrapped table became SELECT * FROM "proj"."ds"."t".Those four dialects now take the backtick branch (with backtick doubling), the same as MySQL/MariaDB/ClickHouse. The ANSI-branch comment no longer lists BigQuery.
Not done here: the issue also suggests sharing one helper with
quoteNameinsql-classify.ts. That helper only exists in open PR #1812, so merging the two tables is left until #1812 lands. The dialect list here matches the one quoteName uses.How did you verify your code works?
bun test test/altimate/data-diffpasses (57 tests), and so do data-diff-safety, release-v0.12.9-adversarial and tool-cli/runner (211 tests).tsgo --noEmitin packages/opencode is clean, and the pre-push hook (bun typecheckand the tracker-leak scan) passed.Cost side effects
None. Only the quoting of identifiers in SQL that data_diff already generates changes. It adds no queries, model calls or resources.
Screenshots / recordings
Not a UI change.
Checklist