fix(sql): support quoted column names in ALTER COLUMN#6842
fix(sql): support quoted column names in ALTER COLUMN#6842bluestreak01 merged 8 commits intomasterfrom
ALTER COLUMN#6842Conversation
ALTER TABLE/MATERIALIZED VIEW ... ALTER COLUMN now supports quoted column names, matching the behavior of CREATE TABLE. This fixes issue #6838 where attempting to alter a column with quotes (e.g., ALTER TABLE t ALTER COLUMN "MY_COL" TYPE FLOAT) would fail with a 'column does not exist' error because the quotes were not stripped from the column name before looking it up in the table metadata.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughUnquoted identifiers are now used when resolving and reporting column names in ALTER TABLE and ALTER MATERIALIZED VIEW flows; tests were added to cover quoted column behavior across add/drop index, type changes, cache/nocache, duplicate-add checks, and materialized view alterations. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java (2)
170-171: Place the new test method in sorted order with peer methods.Move
testQuotedColumnNameto the correct alphabetical position among instance test methods.As per coding guidelines: "Java class members are grouped by kind (static vs. instance) and visibility, and sorted alphabetically. When adding new methods or fields, insert them in the correct alphabetical position among existing members of the same kind."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java` around lines 170 - 171, The new instance test method testQuotedColumnName in class AlterTableAlterColumnTest must be relocated so instance test methods remain alphabetically ordered; move the entire testQuotedColumnName method block to the alphabetical position among other instance `@Test` methods in AlterTableAlterColumnTest (compare method name strings) so it fits the existing sorting convention for instance members.
170-181: Broaden coverage to all affected quoted-identifier paths.Please add assertions for at least one single-quoted column token and one
ALTER MATERIALIZED VIEW ... ALTER COLUMNcase, since the parser change affects both paths.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java` around lines 170 - 181, Extend testQuotedColumnName (or add a new test) to cover the remaining quoted-identifier parsing paths: add at least one assertion that uses a single-quoted column token (e.g., execute("ALTER TABLE test_quoted ALTER COLUMN 'MY_COL' ADD INDEX"/similar) to exercise the single-quote token branch) and add a case that runs ALTER MATERIALIZED VIEW ... ALTER COLUMN (e.g., create a materialized view and call execute("ALTER MATERIALIZED VIEW mv_name ALTER COLUMN \"MY_COL\" ADD INDEX" and a corresponding DROP/ CACHE/NOCACHE) to exercise the materialized view code path), ensuring the same operations as in testQuotedColumnName (ADD INDEX, DROP INDEX, CACHE, NOCACHE) are asserted; update test method names or add a new test method accordingly so both parser branches are covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java`:
- Around line 170-171: The new instance test method testQuotedColumnName in
class AlterTableAlterColumnTest must be relocated so instance test methods
remain alphabetically ordered; move the entire testQuotedColumnName method block
to the alphabetical position among other instance `@Test` methods in
AlterTableAlterColumnTest (compare method name strings) so it fits the existing
sorting convention for instance members.
- Around line 170-181: Extend testQuotedColumnName (or add a new test) to cover
the remaining quoted-identifier parsing paths: add at least one assertion that
uses a single-quoted column token (e.g., execute("ALTER TABLE test_quoted ALTER
COLUMN 'MY_COL' ADD INDEX"/similar) to exercise the single-quote token branch)
and add a case that runs ALTER MATERIALIZED VIEW ... ALTER COLUMN (e.g., create
a materialized view and call execute("ALTER MATERIALIZED VIEW mv_name ALTER
COLUMN \"MY_COL\" ADD INDEX" and a corresponding DROP/ CACHE/NOCACHE) to
exercise the materialized view code path), ensuring the same operations as in
testQuotedColumnName (ADD INDEX, DROP INDEX, CACHE, NOCACHE) are asserted;
update test method names or add a new test method accordingly so both parser
branches are covered.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
core/src/main/java/io/questdb/griffin/SqlCompilerImpl.javacore/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java
core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java
Outdated
Show resolved
Hide resolved
The ADD COLUMN code path uses the raw (potentially quoted) token for duplicate column detection via getColumnIndexQuiet(), but the actual column creation correctly calls unquote(tok). This means quoted column names like "existing_col" bypass duplicate detection. Apply unquote() to both the IF NOT EXISTS path (line 943) and the regular ADD COLUMN path (line 980), and also unquote the column name in the error message on line 982 for consistency. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace the weak execute-only testQuotedColumnName with four focused tests that verify state via isColumnIndexed() and assertQueryNoLeakCheck(). Cover ADD/DROP INDEX, ALTER TYPE, CACHE/NOCACHE, single-quoted column names, spaces, SQL keywords, and mixed case. Add mat view test for quoted column names in ALTER MATERIALIZED VIEW ... ALTER COLUMN. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Cover the two ADD COLUMN paths fixed in 4aa1796: the plain duplicate check and the IF NOT EXISTS path, both with quoted column names. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
core/src/test/java/io/questdb/test/cairo/mv/MatViewTest.java (1)
309-314: Normalize SQL keyword casing in new test SQL strings.The new
CREATE TABLE/SELECT ... SAMPLE BYstrings use lowercase keywords; please align with test SQL casing conventions.Suggested diff
- executeWithRewriteTimestamp( - "create table base_price (" + - " \"MY_SYM\" symbol, price double, ts `#TIMESTAMP`" + - ") timestamp(ts) partition by DAY WAL" - ); - createMatView("select \"MY_SYM\", last(price) as price, ts from base_price sample by 1h"); + executeWithRewriteTimestamp( + "CREATE TABLE base_price (" + + " \"MY_SYM\" SYMBOL, price DOUBLE, ts `#TIMESTAMP`" + + ") TIMESTAMP(ts) PARTITION BY DAY WAL" + ); + createMatView("SELECT \"MY_SYM\", last(price) AS price, ts FROM base_price SAMPLE BY 1h");As per coding guidelines: In SQL statements within test code, use UPPERCASE for SQL keywords (CREATE TABLE, INSERT, SELECT ... AS ... FROM, etc.).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@core/src/test/java/io/questdb/test/cairo/mv/MatViewTest.java` around lines 309 - 314, The SQL strings in MatViewTest (around the create table for base_price and the createMatView call) use lowercase SQL keywords; update the literals so SQL keywords are UPPERCASE (e.g., "CREATE TABLE", "TIMESTAMP", "PARTITION BY DAY WAL", "SELECT", "AS", "FROM", "SAMPLE BY") while keeping identifiers like "MY_SYM", column names, and the function call createMatView(...) unchanged; ensure both the CREATE TABLE string and the SELECT ... SAMPLE BY string follow the test code's uppercase SQL keyword convention.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@core/src/test/java/io/questdb/test/griffin/AlterTableAddColumnTest.java`:
- Around line 647-660: The test method testAddDuplicateColumnQuotedIfNotExists
uses lowercase SQL strings; update the SQL literals passed to execute(...) and
assertExceptionNoLeakCheck(...) to use UPPERCASE SQL keywords (e.g., ALTER
TABLE, ADD COLUMN, IF NOT EXISTS) while keeping table/column quoting unchanged
so the assertions still reference the same statements in the test.
In `@core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java`:
- Line 212: Update the large numeric literal in the test's SQL string to use
underscore separators for readability and consistency: change the value in the
execute(...) call that inserts into test_quoted (in AlterTableAlterColumnTest)
from 123456789 to 123_456_789 so the SQL literal follows the repository rule for
numbers with 5+ digits.
---
Nitpick comments:
In `@core/src/test/java/io/questdb/test/cairo/mv/MatViewTest.java`:
- Around line 309-314: The SQL strings in MatViewTest (around the create table
for base_price and the createMatView call) use lowercase SQL keywords; update
the literals so SQL keywords are UPPERCASE (e.g., "CREATE TABLE", "TIMESTAMP",
"PARTITION BY DAY WAL", "SELECT", "AS", "FROM", "SAMPLE BY") while keeping
identifiers like "MY_SYM", column names, and the function call
createMatView(...) unchanged; ensure both the CREATE TABLE string and the SELECT
... SAMPLE BY string follow the test code's uppercase SQL keyword convention.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d896c417-6da1-4e26-ade0-939283e3f034
📒 Files selected for processing (4)
core/src/main/java/io/questdb/griffin/SqlCompilerImpl.javacore/src/test/java/io/questdb/test/cairo/mv/MatViewTest.javacore/src/test/java/io/questdb/test/griffin/AlterTableAddColumnTest.javacore/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java
core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java
Show resolved
Hide resolved
[PR Coverage check]😍 pass : 6 / 6 (100.00%) file detail
|
Fixes #6838
Summary
ALTER TABLE ... ALTER COLUMNandALTER MATERIALIZED VIEW ... ALTER COLUMNfailed when the column name was quoted (e.g."MY_COL"). The token from the lexer was used as-is for the metadata lookup, so"MY_COL"(with quotes) was looked up instead ofMY_COL, resulting in a "column does not exist" error.Changes
tokwithunquote()before the column name lookup in bothcompileAlterTableandcompileAlterMatViewALTER TABLEandALTER MATERIALIZED VIEW