Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

Implements the IN PARTITION clause for ALTER TABLE ... UPDATE statements per ClickHouse SQL reference.

Changes

Parser

  • Modified parseUpdateAssignment() to use parseSubExpr(pos, precedenceIn) instead of parseExpr(pos), preventing the expression parser from consuming the IN keyword as part of a binary operation
  • Extended parseAlterTableUpdate() to parse optional IN PARTITION clause before WHERE clause (not after)

AST

  • Added InPartition *PartitionClause field to AlterTableUpdate struct
  • Updated String() method to output IN PARTITION before WHERE clause
  • Updated Accept() and Walk() methods to handle the new field

Tests

  • Added test cases covering simple partitions, PARTITION ID syntax, and multiple column assignments

Syntax

ALTER TABLE test.users 
UPDATE status = 'active' 
IN PARTITION '2024-01'
WHERE id > 100;

Note: The IN PARTITION clause appears between assignments and WHERE, not after WHERE.

The implementation preserves backward compatibility—standard expressions in assignments and WHERE clauses continue to work correctly.

Known Limitation

The ID keyword in PARTITION ID syntax is not preserved in formatted output (e.g., IN PARTITION ID '202401' formats as IN PARTITION '202401'). This is consistent with existing behavior in other ALTER commands due to PartitionClause.String() implementation.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add support of IN PARTITION expression for ALTER TABLE ... UPDATE</issue_title>
<issue_description>For the detailed syntax, please refer to: https://clickhouse.com/docs/sql-reference/statements/alter/update</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: git-hulk <4987594+git-hulk@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for IN PARTITION expression in ALTER TABLE UPDATE Add IN PARTITION clause support for ALTER TABLE UPDATE Oct 27, 2025
Copilot AI requested a review from git-hulk October 27, 2025 02:55
Copilot finished work on behalf of git-hulk October 27, 2025 02:55
@git-hulk
Copy link
Member

@copilot The correct syntax is follwoing:

ALTER TABLE [db.]table [ON CLUSTER cluster] UPDATE column1 = expr1 [, ...] [IN PARTITION partition_id] WHERE filter_expr

IN PARTITION should be parsed before WHERE keyword. Also, you need to search the codebase to see if we have parsed IN PARTITION before. If yes, reuse the parse function if possible.

@coveralls
Copy link

coveralls commented Oct 27, 2025

Pull Request Test Coverage Report for Build 18828241324

Details

  • 23 of 31 (74.19%) changed or added relevant lines in 4 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.05%) to 50.281%

Changes Missing Coverage Covered Lines Changed/Added Lines %
parser/parser_alter.go 12 14 85.71%
parser/walk.go 2 4 50.0%
parser/ast.go 4 8 50.0%
Files with Coverage Reduction New Missed Lines %
parser/ast.go 1 39.89%
Totals Coverage Status
Change from base Build 18827715548: 0.05%
Covered Lines: 7521
Relevant Lines: 14958

💛 - Coveralls

Co-authored-by: git-hulk <4987594+git-hulk@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot The correct syntax is follwoing:

...

Fixed in commit 3ce2d80. The IN PARTITION clause is now parsed before the WHERE keyword as specified in the ClickHouse documentation.

The implementation:

  • Moved IN PARTITION parsing to occur after assignments but before WHERE
  • Used parseSubExpr(pos, precedenceIn) in parseUpdateAssignment to prevent the expression parser from consuming the IN keyword
  • Updated the String() method to output the correct syntax order
  • Reused existing tryParsePartitionClause function as suggested

All tests are passing with the corrected syntax:

ALTER TABLE table UPDATE column = value [IN PARTITION partition_id] WHERE condition

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • clickhouse.com
    • Triggering command: curl -s REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of git-hulk October 27, 2025 03:22
@git-hulk git-hulk closed this Oct 27, 2025
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.

Add support of IN PARTITION expression for ALTER TABLE ... UPDATE

3 participants