Skip to content

feat(sql): allow plural 'partitions' keyword in ALTER TABLE CONVERT#6733

Open
gggeon96 wants to merge 9 commits intoquestdb:masterfrom
gggeon96:feature/allow-plural-partitions-in-convert
Open

feat(sql): allow plural 'partitions' keyword in ALTER TABLE CONVERT#6733
gggeon96 wants to merge 9 commits intoquestdb:masterfrom
gggeon96:feature/allow-plural-partitions-in-convert

Conversation

@gggeon96
Copy link
Copy Markdown

@gggeon96 gggeon96 commented Feb 1, 2026

Summary

Allow both PARTITION and PARTITIONS keywords in the ALTER TABLE ... CONVERT PARTITION TO PARQUET/NATIVE syntax.

Why

Currently only the singular form PARTITION is accepted, but users naturally expect PARTITIONS (plural) to work as well, especially when converting multiple partitions. This improves SQL grammar consistency and user experience.

Changes

  • SqlCompilerImpl.java: Accept both isPartitionKeyword() and isPartitionsKeyword() in the CONVERT clause
  • AlterTableConvertPartitionTest.java: Added testConvertAllPartitionsPlural to verify the fix

Test

  • Added unit test that uses plural PARTITIONS keyword
  • Existing tests still pass (singular form unchanged)

Fixes #6494

Allow both 'partition' and 'partitions' keywords in the
ALTER TABLE ... CONVERT PARTITION TO PARQUET/NATIVE syntax
for better SQL grammer consistency.

Fixes questdb#6494
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 1, 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: 95fe0f3f-7e81-4fd5-9101-62d8e3fd754f

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

…nExpected

Update test to expect 'partition' or 'partitions' in error message
to match the updated parser behavior from issue questdb#6494.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the SQL grammar for ALTER TABLE ... CONVERT ... to accept both PARTITION and PARTITIONS, improving usability and consistency with user expectations (Fixes #6494).

Changes:

  • Updated SqlCompilerImpl to treat PARTITION and PARTITIONS equivalently in ALTER TABLE ... CONVERT ....
  • Updated a compiler error-message assertion to match the new accepted keywords.
  • Added a unit test covering the plural PARTITIONS keyword for convert-to-parquet.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
core/src/main/java/io/questdb/griffin/SqlCompilerImpl.java Extends ALTER TABLE ... CONVERT parsing to accept PARTITIONS in addition to PARTITION.
core/src/test/java/io/questdb/test/griffin/engine/SqlCompilerImplTest.java Updates expected syntax error message to include both keyword forms.
core/src/test/java/io/questdb/test/griffin/AlterTableConvertPartitionTest.java Adds coverage to ensure CONVERT PARTITIONS works for the WHERE form.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

gggeon96 and others added 3 commits February 3, 2026 19:37
Allow both 'partition' and 'partitions' keywords in the
ALTER TABLE ... CONVERT PARTITION TO PARQUET/NATIVE syntax
for better SQL grammer consistency.

Fixes questdb#6494
…nExpected

Update test to expect 'partition' or 'partitions' in error message
to match the updated parser behavior from issue questdb#6494.
@gggeon96 gggeon96 force-pushed the feature/allow-plural-partitions-in-convert branch from 21716ec to a66c8c5 Compare February 3, 2026 10:37
@bluestreak01
Copy link
Copy Markdown
Member

@CodeRabbit pls critically review this change and also see if claims are valid (including issue PR claims to have fixed)

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 4, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@bluestreak01, I'll conduct a thorough critical review of this PR and verify the claims. Let me gather the necessary information first.


🏁 Script executed:

#!/bin/bash

# Get the PR diff to see the actual changes
gh pr view 6733 --json files,additions,deletions,changedFiles,body,number,title | jq '.'

# Get the issue `#6494` details to verify the claim
gh issue view 6494 --json number,title,body,labels,state | jq '.'

# Get the actual diff
gh pr diff 6733

Length of output: 7999


🏁 Script executed:

#!/bin/bash

# Verify isPartitionsKeyword() method exists
echo "=== Checking if isPartitionsKeyword() method exists ==="
rg -n "isPartitionsKeyword" --type=java -C 3

# Check for other keyword checking methods to understand the pattern
echo -e "\n=== Pattern of keyword checking methods ==="
rg -n "boolean isPartition.*Keyword" --type=java -A 2

# Look for other ALTER TABLE CONVERT test scenarios
echo -e "\n=== Other ALTER TABLE CONVERT test methods ==="
rg -n "testConvert" core/src/test/java/io/questdb/test/griffin/AlterTableConvertPartitionTest.java

# Check for other usages of PARTITION keyword in ALTER TABLE context
echo -e "\n=== Other PARTITION keyword usages in ALTER TABLE ==="
rg -n "isPartitionKeyword" core/src/main/java/io/questdb/griffin/SqlCompilerImpl.java -C 5

# Check if there are LIST or specific partition convert scenarios
echo -e "\n=== Looking for CONVERT PARTITION LIST syntax ==="
rg -n "convert.*partition.*list" --type=java -i -C 2

Length of output: 23798


@bluestreak01, I've completed the critical review. The claims are valid (issue #6494 exists and matches), but I have significant concerns about this implementation:

❌ Critical Issues

1. Grammar Inconsistency Across ALTER TABLE Operations

The implementation creates an arbitrary inconsistency:

// CONVERT - now accepts BOTH (after this PR)
if (!isPartitionKeyword(tok) && !isPartitionsKeyword(tok))

// ATTACH - accepts ONLY singular (line 2124-2130)
if (isPartitionKeyword(tok))

// DETACH - accepts ONLY singular (line 2132-2138) 
if (isPartitionKeyword(tok))

// DROP - accepts ONLY singular (line 2110)
else if (isPartitionKeyword(tok))

// SQUASH - accepts ONLY plural (line 2313)
if (isPartitionsKeyword(tok))

Why does CONVERT get special treatment? Other operations consistently enforce singular/plural. What's the design principle here?

2. Inadequate Test Coverage

The new test only covers the WHERE clause:

"alter table " + tableName + " convert " + partitionKeyword + " to parquet where timestamp > 0"

But completely ignores the LIST syntax, which is heavily used:

  • Line 115: convert partition to parquet list '2024-06'
  • Line 119: convert partition to parquet list '1970-01'
  • Line 138: convert partition to parquet list '2024-06-10', '2024-06-11'

Where are the tests for:

ALTER TABLE x CONVERT PARTITIONS TO PARQUET LIST '2024-06-10'
ALTER TABLE x CONVERT PARTITIONS TO NATIVE LIST '2024-06-10', '2024-06-11'

3. Semantic Ambiguity

Now this is valid:

-- Plural form for single partition - semantically wrong?
ALTER TABLE x CONVERT PARTITIONS TO PARQUET LIST '2024-06-10'

Should plural really work when converting a single partition? Other DBs (PostgreSQL, MySQL) are strict about this for good reason - it guides users toward correct SQL.

4. Missing Design Rationale

The issue shows: convert partitions to parquet where timestamp < '2025-11-28'

This converts multiple partitions, so plural makes semantic sense. But:

  • Why allow plural for LIST '2024-06-10' (single partition)?
  • Why not make ATTACH/DETACH/DROP consistent too?
  • What about SQUASH, which only accepts plural?

🤔 Questions for the Author

  1. Why not align ALL partition operations to accept both forms if this is about UX?
  2. Or conversely, why not enforce semantic correctness (singular for one, plural for many)?
  3. Was there consideration for parser ambiguity or future grammar conflicts?
  4. Should the error message guide users on when to use which form?

✅ What's Correct

  • Issue #6494 exists and is accurately described
  • isPartitionsKeyword() method exists
  • Basic implementation works
  • Error message updated

📋 Recommendations

  1. Add comprehensive tests for LIST syntax with plural keyword
  2. Document the design decision - why CONVERT is special
  3. Consider grammar-wide consistency - either make all operations flexible or enforce semantics
  4. Add grammar documentation noting both forms are accepted

This feels like a quick fix without considering the broader grammar design. The friction is real, but the solution creates technical debt.


🧠 Learnings used
Learnt from: jerrinot
Repo: questdb/questdb PR: 0
File: :0-0
Timestamp: 2026-02-04T11:18:36.475Z
Learning: For PRs by jerrinot, always use a thorough and critical review mode: question design decisions, challenge assumptions, scrutinize implementations for edge cases and potential issues, and avoid superficial validation. They prefer hard-core reviews that push back on the code.

…om:gggeon96/questdb into feature/allow-plural-partitions-in-convert
@gggeon96
Copy link
Copy Markdown
Author

gggeon96 commented Feb 5, 2026

Thanks for the review.

Regarding the scope:

Regarding test coverage:

  • I'll add tests for List syntax:
    • CONVERT PARTITIONS TO PARQUET LIST '...'
    • CONVERT PARTITIONS TO NATIVE LIST '...', '...'

I'll push the additional tests shortly. Thanks!

gggeon96 and others added 3 commits February 5, 2026 11:07
- Remove duplicate testConvertAllPartitionsPlural method
- Add assertConvertListPartitionsWithKeyword helper method
- Refactor testConvertListPartitions to use helper
- Add testConvertListPartitionsPlural for LIST syntax coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CONVERT PARTITION should accept plural PARTITIONS as well

5 participants