Repository navigation
PHOENIX-8092 String literals in generated SQL do not escape backslashes - #2724
Merged
Merged
Conversation
CREATE INDEX with a WHERE clause makes a probe UPSERT statement. For a VARCHAR or CHAR ARRAY column, the probe value is a random sample character. When the sample is a backslash, the literal is ARRAY['\']. The SQL lexer reads \' as an escaped quote, so the literal does not close, and the statement fails with ERROR 602. The root cause is general. StringUtil.escapeStringConstant doubles single quotes but not backslashes. The lexer reads a backslash as the start of an escape sequence. Thus generated SQL text does not always parse back to the same value. This affects view statements, index WHERE clauses, column defaults and other generated text. The change: - escapeStringConstant doubles each backslash and each single quote. The parser reads the quoted result back as the original string. - MetaDataClient no longer escapes backslashes in functional index expressions a second time. For string literals, the stored expression text does not change. Backslashes in quoted identifiers are no longer doubled; the old doubling made such expressions unresolvable. - PostIndexDDLCompiler uses the stored functional index expression as it is. Before, it escaped backslashes again, so an index build by this path computed a different value than index maintenance. - SchemaUtil.normalizeLiteral returns the parsed value of a string literal. SHOW TABLES/SCHEMAS LIKE patterns and GRANT/REVOKE names thus get the value that the statement gives. A statement can give any value, including one with doubled quotes, with escaped characters. - SHOW TABLES and SHOW SCHEMAS escape the pattern in their SQL text. - The CREATE INDEX probe uses a fixed element for VARCHAR and CHAR arrays, so the probe row is deterministic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
A regression test is needed to verify consistent escaping when backfilling and maintaining a global functional index with a backslash-containing expression on a transactional table.
1 open issue
What changed in this PR
Fixes PHOENIX-8092 by preserving backslashes in generated Phoenix SQL, preventing intermittent index-creation failures.
Changes:
- Escape backslashes and quotes consistently, without double-escaping functional index expressions.
- Preserve parsed literal values and escape SHOW patterns.
- Make character-array probes deterministic and add serialization regression tests.
| File | Description |
|---|---|
| phoenix-core/src/test/java/org/apache/phoenix/util/StringUtilTest.java | Tests string-literal round trips. |
| phoenix-core/src/test/java/org/apache/phoenix/schema/SchemaUtilTest.java | Tests parsed literal normalization. |
| phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java | Tests SHOW statement round trips. |
| phoenix-core-client/src/main/java/org/apache/phoenix/util/StringUtil.java | Escapes backslashes and quotes. |
| phoenix-core-client/src/main/java/org/apache/phoenix/util/SchemaUtil.java | Returns parsed string values. |
| phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java | Removes duplicate expression escaping. |
| phoenix-core-client/src/main/java/org/apache/phoenix/parse/ShowTablesStatement.java | Escapes table patterns. |
| phoenix-core-client/src/main/java/org/apache/phoenix/parse/ShowSchemasStatement.java | Escapes schema patterns. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/PostIndexDDLCompiler.java | Uses stored expressions without re-escaping. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/CreateIndexCompiler.java | Uses deterministic character-array probes. |
Review effort: Balanced
A transactional table builds a new global index through its own compiler, while later writes go through index maintenance. A new test commits rows, creates a functional index whose expression holds a backslash string literal, and then writes more rows. It checks that the rows from the index build and from index maintenance get the same index values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Precommit note: the failures in this run are not related to this change. Each one is a known problem on master.
(Claude Code) |
asf-gitbox-commits
pushed a commit
that referenced
this pull request
Dec 5, 2026
…es (#2724) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Andrew Purtell <apurtell@salesforce.com>
asf-gitbox-commits
pushed a commit
that referenced
this pull request
Dec 5, 2026
…es (#2724) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Andrew Purtell <apurtell@salesforce.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.

CREATE INDEX ... WHEREfails at random with ERROR 602 when the table has a character array column. The probe upsert uses a random sample element. When that element is a backslash, the lexer reads the closing quote as escaped, so the literal does not close.The root cause is general. The string constant escape doubles quotes but not backslashes, so generated SQL text does not always parse back to the same value. The escape now doubles both. Functional index expressions get one escape, not two, so index builds match index maintenance. String literal normalization returns the parsed value. SHOW TABLES and SHOW SCHEMAS escape their patterns. The probe uses a fixed element. Users now see doubled backslashes in the string form of character arrays, in EXPLAIN text and in new column defaults.
🤖 Generated with Claude Code