Repository navigation
feat(warehouse): add shared SQL identifier and string literal quoting helpers - #7406
Merged
Merged
Conversation
… helpers Add dialect-specific helpers in warehouse/utils so every warehouse integration quotes identifiers and string literals the same way instead of duplicating the escaping rules: - identifiers: double quote (Postgres, Redshift, Snowflake), bracket (MSSQL, Azure Synapse), backtick (Databricks) and backslash-escaped backtick (BigQuery) - qualified identifiers, identifier lists and comma separated column lists - string literals: doubled quote (MSSQL, Azure Synapse), backslash aware with a doubled quote (Redshift, Snowflake) and Spark SQL style (Databricks) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> 🔒 Scanned for secrets using gitleaks 8.29.1
achettyiitr
force-pushed
the
feature/int-6791-warehouse-identifier-utils
branch
from
September 18, 2026 04:18
dbeb885 to
2f0a845
Compare
This was referenced Sep 18, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7406 +/- ##
==========================================
+ Coverage 84.38% 84.41% +0.02%
==========================================
Files 620 621 +1
Lines 62640 62660 +20
==========================================
+ Hits 52861 52894 +33
+ Misses 9776 9763 -13
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
saikumarrs
approved these changes
Sep 18, 2026
achettyiitr
added a commit
that referenced
this pull request
Sep 24, 2026
…ence check (#7405) # Description Stacked on #7406, which adds the shared helpers; this PR targets that branch and will retarget to `master` once it merges. Most Postgres identifiers in generated DDL and load SQL are already quoted with `DoubleQuoteIdentifier`. Two gaps remained: 1. `schemaExists` interpolated the namespace into a `'…'` string literal: ```sql SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = '<namespace>'); ``` This PR passes the namespace as a bind parameter (`$1`) instead, so a namespace containing `'` can no longer break out of the literal. 2. `insertIntoLoadTable` built the column list with `warehouseutils.DoubleQuoteAndJoinByComma`, which uses Go's `%q`. Go escapes a double quote as `\"`, which Postgres does not honour inside a quoted identifier, so a column name containing `"` could break out. Each column is now quoted with `DoubleQuoteIdentifier` (follow-up raised on #7127). ## Tests - Integration test `TestIntegration` → `Load Table` → "prevents SQL injection via malicious identifiers" (replaces "quotes identifiers in create table" and the sqlmock-based create-table quoting test): creates a namespace containing `'` and `"` breakout payloads and runs `CreateSchema` twice (the second call must find the existing schema, which fails if the namespace is interpolated into a string literal), then creates a table and columns whose names contain `"` breakout payloads (plus a trailing-backslash column) alongside a control table. It then verifies the control table survives, `AddColumns` works on the malicious table, the names round-trip verbatim through `FetchSchema`, and `DropTable` drops only the targeted table. ## Linear Ticket Resolves INT-6791 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used.
achettyiitr
added a commit
that referenced
this pull request
Sep 24, 2026
# Description Stacked on #7406, which adds the shared helpers; this PR targets that branch and will retarget to `master` once it merges. MSSQL SQL statements were built by interpolating schema, table, staging-table and column names directly into the query, either unquoted or wrapped in `"…"` / Go's `%q`. None of these escape SQL Server delimiters, so a name containing `]`, `"` or `'` could break out of the identifier or literal. This PR routes all generated SQL through the shared quoting helpers added in #7406 (`warehouse/utils/identifier.go`): - `BracketQuoteIdentifier` / `BracketQuoteQualifiedIdentifier` / `BracketQuoteAndJoinByComma` / `QuoteCommaSeparatedIdentifiers` — bracket quoting (`[name]`), escaping `]` as `]]`. - `SQLStringLiteral` / `UnicodeStringLiteral` — `'…'` / `N'…'` literals, escaping `'` as `''`. - `UnicodeStringLiteral(BracketQuoteQualifiedIdentifier(...))` — an `N'[schema].[table]'` literal for `OBJECT_ID(...)`. Covered statements: - `CreateSchema`: the `sys.schemas` lookup uses a Unicode literal, and the dynamic `EXEC('CREATE SCHEMA …')` escapes the bracket-quoted name inside the string. - `CreateTable` / `AddColumns`: the `IF NOT EXISTS` / `OBJECT_ID(...)` guard now uses **the same quoted name** as the `CREATE TABLE` / `ALTER TABLE` it protects, so names that need quoting are still detected as existing. - `DropTable` (which now also logs the executed statement instead of the unformatted template), `DeleteBy`, staging-table creation, `CopyIn` target, dedup `DELETE` / `INSERT … ROW_NUMBER()` (including composite discards partition keys split into individually quoted columns), `loadUserTables`, dangling staging-table cleanup and `TestLoadTable`. ## Tests - Integration test `TestIntegration` → `Load Table` → "prevents SQL injection via malicious identifiers": creates a namespace, table and columns whose names contain `]` and `'` breakout payloads (plus a trailing-backslash column), alongside a control table, then verifies the control table survives, the names round-trip verbatim through `FetchSchema`, and `DropTable` drops only the targeted table. Re-running `CreateTable` / `AddColumns` must be a no-op, which proves the `OBJECT_ID` guards resolve the quoted name against a real server. It also creates a dangling staging table whose name contains `]`, `'` and a SQL payload, runs `Cleanup`, and verifies against `information_schema` that the table was dropped. - `mssql_quoting_test.go`: column-list quoting neutralizes identifier breakout payloads. ## Linear Ticket Resolves INT-6791 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used. --------- Co-authored-by: tech-infra-rudderstack <[email protected]> Co-authored-by: Akash Chetty <[email protected]>
achettyiitr
added a commit
that referenced
this pull request
Sep 24, 2026
# Description Stacked on #7406, which adds the shared helpers; this PR targets that branch and will retarget to `master` once it merges. Azure Synapse SQL statements were built by interpolating schema, table, staging-table and column names directly into the query, either unquoted or wrapped in `"…"` / Go's `%q`. None of these escape SQL Server delimiters, so a name containing `]`, `"` or `'` could break out of the identifier or literal. This PR routes all generated SQL through the shared quoting helpers added in #7406 (`warehouse/utils/identifier.go`): - `BracketQuoteIdentifier` / `BracketQuoteQualifiedIdentifier` / `BracketQuoteAndJoinByComma` / `QuoteCommaSeparatedIdentifiers` — bracket quoting (`[name]`), escaping `]` as `]]`. - `SQLStringLiteral` / `UnicodeStringLiteral` — `'…'` / `N'…'` literals, escaping `'` as `''`. - `UnicodeStringLiteral(BracketQuoteQualifiedIdentifier(...))` — an `N'[schema].[table]'` literal for `OBJECT_ID(...)`. Covered statements: - `CreateSchema`: the `sys.schemas` lookup uses a Unicode literal, and the dynamic `EXEC('CREATE SCHEMA …')` escapes the bracket-quoted name inside the string. - `CreateTable` / `AddColumns` / `dropStagingTable`: the `IF [NOT] EXISTS` / `OBJECT_ID(...)` guards now use **the same quoted name** as the `CREATE TABLE`, `ALTER TABLE` or `DROP TABLE` they protect, so names that need quoting are detected correctly. Otherwise creates can fail on existing tables and staging tables can be left behind. - `DropTable` (which now also logs the executed statement instead of the unformatted template), staging-table creation, `CopyIn` target, dedup `DELETE` / `INSERT … ROW_NUMBER()` (including composite discards partition keys split into individually quoted columns), `loadUserTables`, dangling staging-table cleanup and `TestLoadTable`. `DeleteBy` remains not implemented for Azure Synapse. ## Tests - `DeleteBy` still returns the not-implemented error. - Integration test `TestIntegration` → `Load Table` → "prevents SQL injection via malicious identifiers": creates a namespace, table and columns whose names contain `]` and `'` breakout payloads (plus a trailing-backslash column), alongside a control table, then verifies the control table survives, the names round-trip verbatim through `FetchSchema`, and `DropTable` drops only the targeted table. Re-running `CreateTable` / `AddColumns` must be a no-op, which proves the `OBJECT_ID` guards resolve the quoted name against a real server. It also creates a dangling staging table whose name contains `]`, `'` and a SQL payload, runs `Cleanup`, and verifies against `information_schema` that the table was dropped. - `azure_synapse_injection_test.go`: column-list quoting neutralizes identifier breakout payloads. ## Linear Ticket Resolves INT-6791 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used. --------- Co-authored-by: tech-infra-rudderstack <[email protected]> Co-authored-by: Akash Chetty <[email protected]>
achettyiitr
added a commit
that referenced
this pull request
Sep 24, 2026
# Description Stacked on #7406, which adds the shared helpers; this PR targets that branch and will retarget to `master` once it merges. Snowflake SQL statements interpolated schema, table and column names with Go's `%q` or raw `"…"`, and embedded values in `'…'` literals without escaping. `%q` produces Go string escaping, not SQL escaping, and Snowflake also interprets backslash escape sequences inside string constants. This PR routes all generated SQL through the shared quoting helpers added in #7406 (`warehouse/utils/identifier.go`): - `DoubleQuoteIdentifier` / `DoubleQuoteQualifiedIdentifier` / `DoubleQuoteAndJoinByComma` / `QuoteCommaSeparatedIdentifiers` — double-quote identifiers, escaping `"` as `""`. - `SQLStringLiteralBackslash` — `'…'` literals escaping **both** `\` (as `\\`) and `'` (as `''`). Changes: - `schemaIdentifier`, `CreateTable` / `AddColumns` (standard and Iceberg table managers), `DropTable`, `IsEmpty`, `DownloadIdentityRules`. - `tableExists`, `columnExists` and `schemaExists` now use bind parameters instead of interpolated literals. - `DeleteBy`: table and column identifiers are quoted. Column names go through `ToProviderCase`, so they resolve to the uppercase columns Snowflake stores (the previous unquoted names were implicitly uppercased). - Load path: staging table creation, `COPY INTO` targets, column lists and load-location literals, `MERGE` join keys / update set / insert columns, duplicate sampling and `LoadUserTables`. - `partitionKeyMap` now holds raw column names, and they are quoted when used, so composite discards keys become individually quoted columns. - Identity tables: `LoadIdentityMergeRulesTable` / `LoadIdentityMappingsTable` targets and load locations. - Iceberg tables: `EXTERNAL_VOLUME` and `BASE_LOCATION` are escaped string literals. The base location value itself is unchanged, so new tables keep the existing storage path layout. - `SHOW GRANTS TO USER` and `TestLoadTable` use the new quoting. - The configurable merge window column (`Warehouse.snowflake.mergeWindow.<destinationID>.column`) is converted to provider case before quoting, so a lowercase configuration value keeps matching the stored uppercase column, as it did when it was unquoted. - `STORAGE_INTEGRATION` is intentionally left unquoted (configuration value, not event data); quoting it would make it case-sensitive for existing configurations. A code comment documents this. ## Tests - `table_manager_test.go`: Iceberg `EXTERNAL_VOLUME` / `BASE_LOCATION` literal escaping. - The existing merge window integration test now configures the merge window column in lowercase. - Integration test `TestIntegration` → `Load Table` → "prevents SQL injection via malicious identifiers": creates a table and columns whose names contain `"` breakout payloads, alongside a control table, then verifies the control table survives, the names round-trip verbatim through `FetchSchema`, and `DropTable` drops only the targeted table. - `snowflake_quoting_internal_test.go`: column-list quoting neutralizes identifier breakout payloads. ## Linear Ticket Resolves INT-6791 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used. --------- Co-authored-by: tech-infra-rudderstack <[email protected]> Co-authored-by: Akash Chetty <[email protected]>
achettyiitr
added a commit
that referenced
this pull request
Sep 24, 2026
# Description Stacked on #7406, which adds the shared helpers; this PR targets that branch and will retarget to `master` once it merges. BigQuery DDL (`CreateTable`, `AddColumns`, `DropTable`) goes through the typed Go client API, where names are struct fields rather than SQL. The remaining raw-SQL paths interpolated dataset, table and column names without escaping: the dedup view, `DeleteBy`, the users merge, `FetchSchema`, dangling staging-table cleanup and identity-rule downloads. This PR routes those paths through the shared quoting helpers added in #7406 (`warehouse/utils/identifier.go`): - `BigQueryQuoteIdentifier` wraps names in backticks. GoogleSQL quoted identifiers use the same escape sequences as string literals, so **both `\` and `` ` `` are escaped with a backslash**; escaping only the backtick would still allow a name ending in `\` to break out. - `BigQueryQuoteTablePath` quotes a `project.dataset.table` path as a single backtick-quoted identifier. - `QuoteCommaSeparatedIdentifiers` splits composite partition keys into individually quoted columns. Changes: - Dedup view (`createTableView` / `deduplicationQuery`): view name, source table path, partition columns, `ORDER BY loaded_at` and the partition filter column are quoted. - `LoadUserTables`: the merge SQL is extracted into `usersMergeQuery`, with every column, `id`, `received_at` and the staging table quoted. Columns are emitted in sorted order so the query is deterministic. - `DeleteBy` and `DownloadIdentityRules`: table paths are quoted. `DownloadIdentityRules` also fixes a stray `"` in the select list used for tables that have `user_id` but no `anonymous_id` (`null as anonymous_id", user_id`), which produced invalid SQL. - `FetchSchema` and `dropDanglingStagingTables`: the dataset qualifier is quoted (`` `dataset`.INFORMATION_SCHEMA.TABLES ``), and the `table_schema` / `LIKE` filters are passed as **query parameters** instead of string literals. ## Tests - `deduplicationQuery` output for a dataset and table containing backticks. - Exact-SQL assertion for `usersMergeQuery` with column names containing backticks, backslashes and SQL fragments. - `bigquery_quoting_internal_test.go`: a table name with a backtick breakout payload stays inside the backtick-quoted table path, both in the deduplication view and in `BigQueryQuoteTablePath`. - Integration test `TestIntegration` → "prevents SQL injection via malicious identifiers": BigQuery rejects backticks, backslashes, `"`, `;` and parentheses in names at the API level, so the test uses names BigQuery accepts but that are only valid SQL when correctly quoted (spaces, dashes, and flexible column name characters such as `'`, `=`, `#` and `|`). It creates a control table and a table with such names, then verifies the deduplication view is created, `DeleteBy` runs, the names round-trip verbatim through `FetchSchema` (`INFORMATION_SCHEMA` with query parameters), and `DropTable` drops only the targeted table. ## Linear Ticket Resolves INT-6791 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used. --------- Co-authored-by: tech-infra-rudderstack <[email protected]> Co-authored-by: Akash Chetty <[email protected]>
achettyiitr
added a commit
that referenced
this pull request
Sep 24, 2026
# Description Stacked on #7406, which adds the shared helpers; this PR targets that branch and will retarget to `master` once it merges. Delta Lake (Databricks) SQL statements interpolated schema, table and column names completely unquoted, and embedded the namespace, table-listing pattern, external location and load folders in `'…'` literals without escaping. This PR routes all generated SQL through the shared quoting helpers added in #7406 (`warehouse/utils/identifier.go`): - `BacktickQuoteIdentifier` / `BacktickQuoteQualifiedIdentifier` / `BacktickQuoteAndJoinByComma` — backtick-quoted identifiers, escaping an embedded backtick by doubling it. - `SparkSQLStringLiteral` — Spark SQL treats `\` as an escape character inside string literals and does **not** treat `''` as an escaped quote, so both `\` and `'` are escaped with a backslash. Changes: - Schema and table management: `fetchTables` (`SHOW TABLES … LIKE`), `schemaExists` (`SHOW SCHEMAS LIKE`), `createSchema`, `CreateTable` (columns, generated `event_date` column, `PARTITIONED BY`, `LOCATION`), `AddColumns`, `dropTable`, `fetchTableAttributes`. - Load path: `COPY INTO` staging targets and load-folder literals, column lists / casts, dedup `INSERT` and `MERGE` statements (join keys, update set, insert columns, partition keys). - `LoadUserTables`: `FIRST_VALUE` projections and staging/users tables. - `TestLoadTable`: target table, columns and load folder. Databricks identifiers are case-insensitive, so quoting existing names does not change which objects are resolved. ## Tests - Integration test `TestIntegration` → `Load Table` → "prevents SQL injection via malicious identifiers": creates a table and columns whose names contain backticks (Databricks rejects most other special characters regardless of quoting), then verifies the control table survives, the names round-trip verbatim through `FetchSchema`, and `DropTable` drops only the targeted table. - `deltalake_quoting_internal_test.go`: column-list quoting neutralizes identifier breakout payloads. ## Linear Ticket Resolves INT-6791 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used. --------- Co-authored-by: tech-infra-rudderstack <[email protected]> Co-authored-by: Akash Chetty <[email protected]>
achettyiitr
added a commit
that referenced
this pull request
Sep 24, 2026
# Description Stacked on #7406, which adds the shared helpers; this PR targets that branch and will retarget to `master` once it merges. Redshift SQL statements were built with Go's `%q` or raw `"…"` interpolation of schema, table, staging-table and column names. `%q` produces Go string escaping (`\"`), not SQL escaping, so a name containing `"` was not safely quoted. This PR routes all generated SQL through the shared quoting helpers added in #7406 (`warehouse/utils/identifier.go`): `DoubleQuoteIdentifier`, `DoubleQuoteQualifiedIdentifier`, `DoubleQuoteAndJoinByComma` and `QuoteCommaSeparatedIdentifiers`, and routes all generated SQL through them: - `CreateTable` (columns and `SORTKEY`), `DropTable`, `AddColumns`, `createSchema` - `DeleteBy`, staging-table creation and cleanup (including dangling staging tables) - `COPY` targets and column lists, dedup `DELETE … USING` and `INSERT … row_number()` (composite discards partition keys are split into individually quoted columns) - `loadUserTables` (`FIRST_VALUE` projections, union/staging tables, merge delete/insert) - `AlterColumn` (add/update/rename/drop column statements) and `TestLoadTable` `schemaExists` now passes the namespace as a bind parameter instead of interpolating it. The S3 source location in the `COPY` statements (load files and `TestLoadTable`) is emitted through `SQLStringLiteralBackslash`, which escapes both `'` and `\` because Redshift interprets backslash escape sequences inside string literals. Redshift folds quoted identifiers to lowercase by default, so quoting existing names does not change which objects are resolved. ## Tests - Integration test `TestIntegration` → `Load Table` → "prevents SQL injection via malicious identifiers": creates a namespace, table and columns whose names contain `"` breakout payloads, alongside a control table, then verifies the control table survives, the names round-trip verbatim through `FetchSchema`, and `DropTable` drops only the targeted table. - `redshift_injection_test.go` (DDL-drop and `COPY … TO PROGRAM` payloads): column-list quoting neutralizes identifier breakout payloads. ## Linear Ticket Resolves INT-6791 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used. --------- Co-authored-by: tech-infra-rudderstack <[email protected]> Co-authored-by: Akash Chetty <[email protected]>
This was referenced Sep 28, 2026
Merged
itsmihir
pushed a commit
that referenced
this pull request
Sep 28, 2026
🤖 I have created a release *beep* *boop* --- ## [1.89.0-rc.1](v1.88.0...v1.89.0-rc.1) (2026-09-28) ### Features * **warehouse:** add shared SQL identifier and string literal quoting helpers ([#7406](#7406)) ([814f6db](814f6db)) ### Bug Fixes * **warehouse:** quote azure synapse identifiers ([#7363](#7363)) ([d399fd1](d399fd1)) * **warehouse:** quote bigquery identifiers ([#7366](#7366)) ([89de526](89de526)) * **warehouse:** quote clickhouse identifiers ([#7420](#7420)) ([490c097](490c097)) * **warehouse:** quote deltalake identifiers ([#7368](#7368)) ([08f2f1e](08f2f1e)) * **warehouse:** quote mssql identifiers ([#7364](#7364)) ([695b881](695b881)) * **warehouse:** quote postgres load column list and bind schema existence check ([#7405](#7405)) ([2ff81c1](2ff81c1)) * **warehouse:** quote redshift identifiers ([#7365](#7365)) ([a3e2a3c](a3e2a3c)) * **warehouse:** quote snowflake identifiers ([#7367](#7367)) ([53d4891](53d4891)) ### Miscellaneous * sync release v1.88.0 to main branch ([#7415](#7415)) ([130bdd3](130bdd3)) * **warehouse:** drop the per dialect identifier quoting wrappers ([#7421](#7421)) ([ec0cf52](ec0cf52)) * **warehouse:** drop the v2 suffix now v1 is gone ([#7418](#7418)) ([b759c33](b759c33)) * **warehouse:** move back to upstream clickhouse-go ([#7419](#7419)) ([1a7e776](1a7e776)) * **warehouse:** remove the ClickHouse v1 driver ([#7417](#7417)) ([bd14179](bd14179)) * **warehouse:** replace dead clickhouse blockSize with commitEvery ([#7427](#7427)) ([0806478](0806478)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir
pushed a commit
that referenced
this pull request
Sep 29, 2026
🤖 I have created a release *beep* *boop* --- ## [1.89.0](v1.88.0...v1.89.0) (2026-09-28) ### Features * **warehouse:** add shared SQL identifier and string literal quoting helpers ([#7406](#7406)) ([814f6db](814f6db)) ### Bug Fixes * **warehouse:** quote azure synapse identifiers ([#7363](#7363)) ([d399fd1](d399fd1)) * **warehouse:** quote bigquery identifiers ([#7366](#7366)) ([89de526](89de526)) * **warehouse:** quote clickhouse identifiers ([#7420](#7420)) ([490c097](490c097)) * **warehouse:** quote deltalake identifiers ([#7368](#7368)) ([08f2f1e](08f2f1e)) * **warehouse:** quote mssql identifiers ([#7364](#7364)) ([695b881](695b881)) * **warehouse:** quote postgres load column list and bind schema existence check ([#7405](#7405)) ([2ff81c1](2ff81c1)) * **warehouse:** quote redshift identifiers ([#7365](#7365)) ([a3e2a3c](a3e2a3c)) * **warehouse:** quote snowflake identifiers ([#7367](#7367)) ([53d4891](53d4891)) ### Miscellaneous * sync release v1.88.0 to main branch ([#7415](#7415)) ([130bdd3](130bdd3)) * **warehouse:** drop the per dialect identifier quoting wrappers ([#7421](#7421)) ([ec0cf52](ec0cf52)) * **warehouse:** drop the v2 suffix now v1 is gone ([#7418](#7418)) ([b759c33](b759c33)) * **warehouse:** move back to upstream clickhouse-go ([#7419](#7419)) ([1a7e776](1a7e776)) * **warehouse:** remove the ClickHouse v1 driver ([#7417](#7417)) ([bd14179](bd14179)) * **warehouse:** replace dead clickhouse blockSize with commitEvery ([#7427](#7427)) ([0806478](0806478)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
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.
Description
The warehouse integrations each build SQL from schema, table and column names that originate from event payloads. Quoting those names correctly is dialect specific, and the rules were about to be duplicated in every integration package.
This PR adds them once in
warehouse/utils/identifier.go:Identifiers
DoubleQuoteIdentifier"doubledBracketQuoteIdentifier]doubledBacktickQuoteIdentifier`doubledBigQueryQuoteIdentifier`and\backslash escapedQuoteQualifiedIdentifier,JoinQuotedIdentifiersandQuoteCommaSeparatedIdentifierstake the dialect's quoting function, so composite partition keys and column lists are quoted per column.BigQueryQuoteTablePathquotes a dottedproject.dataset.tablepath as a single identifier.String literals
SQLStringLiteral/UnicodeStringLiteral'doubled,N'…'variantSQLStringLiteralBackslash\escaped,'doubledSparkSQLStringLiteral\escaped,'escaped as\'Redshift, Snowflake, BigQuery and Databricks all interpret backslash escape sequences inside string literals, so doubling the quote alone can be defeated by a value containing
\'.This PR only adds the helpers. The integration PRs stacked on it switch their SQL over:
Tests
identifier_test.go: per dialect identifier escaping (including breakout payloads and a trailing backslash), qualified identifiers, identifier lists, comma separated column lists, and the three string literal forms. Each escaper is also run over a value containing every delimiter and escape character (",`,],',\) to assert it escapes only its own.Linear Ticket
Resolves INT-6791
Security