Skip to content

fix(sql): support quoted column names in ALTER COLUMN#6842

Merged
bluestreak01 merged 8 commits intomasterfrom
nw_quotes
Mar 6, 2026
Merged

fix(sql): support quoted column names in ALTER COLUMN#6842
bluestreak01 merged 8 commits intomasterfrom
nw_quotes

Conversation

@nwoolmer
Copy link
Copy Markdown
Contributor

@nwoolmer nwoolmer commented Mar 3, 2026

Fixes #6838

Summary

ALTER TABLE ... ALTER COLUMN and ALTER MATERIALIZED VIEW ... ALTER COLUMN failed 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 of MY_COL, resulting in a "column does not exist" error.

Changes

  • Wrap tok with unquote() before the column name lookup in both compileAlterTable and compileAlterMatView
  • Add test for quoted column names with ALTER TABLE and ALTER MATERIALIZED VIEW

nwoolmer added 2 commits March 3, 2026 14:01
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.
@nwoolmer nwoolmer added Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution labels Mar 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 3, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5bb6338c-ca85-43c3-bc67-66ae29e68447

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Unquoted 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

Cohort / File(s) Summary
Core compiler change
core/src/main/java/io/questdb/griffin/SqlCompilerImpl.java
Normalize identifiers by calling unquote(tok) before creating/resolving column identifiers and before error messages in ALTER TABLE and ALTER MATERIALIZED VIEW code paths.
Alter table — alter column tests
core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java
Added tests exercising ALTER COLUMN operations with quoted names: add/drop index, alter type, cache/nocache, and special-character/mixed-case quoted identifiers.
Materialized view tests
core/src/test/java/io/questdb/test/cairo/mv/MatViewTest.java
Added test(s) validating ALTER MATERIALIZED VIEW ... ALTER COLUMN with quoted column names (add/drop index) and subsequent verification of index state.
Alter table — add column tests
core/src/test/java/io/questdb/test/griffin/AlterTableAddColumnTest.java
Added tests for adding duplicate columns when the column name is quoted, including IF NOT EXISTS variant and associated error message checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • bluestreak01
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for quoted column names in ALTER COLUMN operations, which aligns with the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the issue with quoted column names in ALTER TABLE/ALTER MATERIALIZED VIEW and detailing the fix applied.
Linked Issues check ✅ Passed The pull request addresses issue #6838 by implementing unquote() in compileAlterTable and compileAlterMatView, and adds comprehensive tests for quoted column names in various ALTER COLUMN scenarios.
Out of Scope Changes check ✅ Passed All changes are focused on fixing quoted column name handling in ALTER COLUMN operations and adding related tests; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch nw_quotes

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nwoolmer
Copy link
Copy Markdown
Contributor Author

nwoolmer commented Mar 3, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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 testQuotedColumnName to 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 COLUMN case, 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

📥 Commits

Reviewing files that changed from the base of the PR and between ea4ef52 and 4fe91b6.

📒 Files selected for processing (2)
  • core/src/main/java/io/questdb/griffin/SqlCompilerImpl.java
  • core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java

nwoolmer and others added 4 commits March 5, 2026 11:30
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]>
@nwoolmer nwoolmer requested a review from glasstiger March 5, 2026 13:49
@glasstiger
Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BY strings 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4fe91b6 and 87eb1fa.

📒 Files selected for processing (4)
  • core/src/main/java/io/questdb/griffin/SqlCompilerImpl.java
  • core/src/test/java/io/questdb/test/cairo/mv/MatViewTest.java
  • core/src/test/java/io/questdb/test/griffin/AlterTableAddColumnTest.java
  • core/src/test/java/io/questdb/test/griffin/AlterTableAlterColumnTest.java

glasstiger
glasstiger previously approved these changes Mar 5, 2026
@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 6 / 6 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/SqlCompilerImpl.java 6 6 100.00%

@bluestreak01 bluestreak01 merged commit e1bc6a8 into master Mar 6, 2026
50 checks passed
@bluestreak01 bluestreak01 deleted the nw_quotes branch March 6, 2026 20:34
maciulis pushed a commit to maciulis/questdb that referenced this pull request Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ALTER COLUMN doesn't support quotes

3 participants