Skip to content

[#10381][#10378] fix(clickhouse-catalog): Fix ClickHouse alter-table bugs#10383

Merged
yuqi1129 merged 20 commits intoapache:mainfrom
yuqi1129:fix-10381-10378-clickhouse-alter-it
Mar 20, 2026
Merged

[#10381][#10378] fix(clickhouse-catalog): Fix ClickHouse alter-table bugs#10383
yuqi1129 merged 20 commits intoapache:mainfrom
yuqi1129:fix-10381-10378-clickhouse-alter-it

Conversation

@yuqi1129
Copy link
Copy Markdown
Contributor

@yuqi1129 yuqi1129 commented Mar 11, 2026

What changes were proposed in this pull request?

Add comprehensive integration coverage for ClickHouse alter-table behavior in:

  • CatalogClickHouseIT
  • CatalogClickHouseClusterIT

The new tests exercise ClickHouseTableOperations#generateAlterTableSql branches in real ClickHouse environments, including:

  • supported alter branches: add/update type/update default/update comment/update position/update nullability/delete index/delete column
  • edge/no-op branches: delete missing column/index with ifExists=true
  • unsupported branches: set/remove property, update auto increment, nested column add

Tests also verify resulting table metadata (column type/comment/nullability/index removal) after alter operations.

Why are the changes needed?

To prevent regressions in ClickHouse ALTER TABLE SQL generation and close branch-level test gaps for issues discussed in #10381 and #10378.

Fixed: #10381
Fixed: #10372
Fixed: #10396
Fixed: #10405

Does this PR introduce any user-facing change?

N/A

Closes #10381
Closes #10378

…0381)

Add integration tests in CatalogClickHouseIT and CatalogClickHouseClusterIT to cover generateAlterTableSql branches, including supported alter operations and unsupported/edge branches for property, index, and column changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 11, 2026 12:52
Copy link
Copy Markdown
Contributor

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

Adds additional ClickHouse JDBC integration tests to exercise more ALTER TABLE branches (including index deletion, missing column/index handling, and unsupported change types) in both single-node and cluster ClickHouse environments, helping prevent regressions discussed in #10381 and #10378.

Changes:

  • Add a new single-node integration test covering alter-table edge/unsupported branches and index deletion.
  • Add a new cluster integration test covering alter-table branches including add column, position/type/comment/default/nullability updates, and index deletion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
catalogs-contrib/catalog-jdbc-clickhouse/src/test/java/org/apache/gravitino/catalog/clickhouse/integration/test/CatalogClickHouseIT.java Adds a new integration test to cover additional alter-table branches (incl. missing column/index behavior and unsupported operations).
catalogs-contrib/catalog-jdbc-clickhouse/src/test/java/org/apache/gravitino/catalog/clickhouse/integration/test/CatalogClickHouseClusterIT.java Adds a new cluster integration test to exercise alter-table branches on clustered ClickHouse tables.

yuqi1129 and others added 2 commits March 11, 2026 21:04
Add integration cases for unsupported addIndex branch, both updateColumnAutoIncrement(true/false) unsupported branches, and multi-index drop validation for minmax and bloom filter indexes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Implement AddIndex handling in ClickHouseTableOperations#generateAlterTableSql for DATA_SKIPPING_MINMAX and DATA_SKIPPING_BLOOM_FILTER, with validation for duplicate/invalid index definitions and explicit unsupported behavior for PRIMARY_KEY alter-add. Update unit and integration tests to validate real behavior for add/drop index and autoIncrement branches.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yuqi1129
Copy link
Copy Markdown
Contributor Author

Verified against real ClickHouse integration tests: ADD INDEX and DROP INDEX for data skipping indexes are supported and now implemented in generateAlterTableSql for DATA_SKIPPING_MINMAX and DATA_SKIPPING_BLOOM_FILTER. ADD INDEX PRIMARY_KEY via ALTER is not supported and stays explicit unsupported behavior. updateColumnAutoIncrement true/false is unsupported in tested ClickHouse 24.8 and tests now assert this behavior. Also updated unit and integration coverage to match runtime behavior.

@yuqi1129 yuqi1129 changed the title [Improvement] Add ClickHouse alter-table integration branch coverage [#10381][#10378] fix(clickhouse-catalog): Fix ClickHouse alter-table bugs Mar 11, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 11, 2026

Code Coverage Report

Overall Project 64.94% -0.03% 🟢
Files changed 62.88% 🟢

Module Coverage
aliyun 1.73% 🔴
api 47.14% 🟢
authorization-common 85.96% 🟢
aws 1.1% 🔴
azure 2.6% 🔴
catalog-common 10.0% 🔴
catalog-fileset 80.02% 🟢
catalog-hive 80.98% 🟢
catalog-jdbc-clickhouse 79.06% -1.4% 🟢
catalog-jdbc-common 42.89% -10.37% 🟢
catalog-jdbc-doris 80.28% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.23% 🟢
catalog-jdbc-oceanbase 78.38% 🟢
catalog-jdbc-postgresql 82.05% 🟢
catalog-jdbc-starrocks 78.27% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 45.07% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 87.15% 🟢
catalog-lakehouse-paimon 77.71% 🟢
catalog-model 77.72% 🟢
cli 44.51% 🟢
client-java 77.83% 🟢
common 49.42% 🟢
core 81.31% 🟢
filesystem-hadoop3 76.97% 🟢
flink 38.86% 🔴
flink-runtime 0.0% 🔴
gcp 14.2% 🔴
hadoop-common 10.39% 🔴
hive-metastore-common 45.82% 🟢
iceberg-common 50.21% 🟢
iceberg-rest-server 66.24% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 23.78% 🔴
lance-rest-server 57.84% 🟢
lineage 53.02% 🟢
optimizer 82.95% 🟢
optimizer-api 21.95% 🔴
server 85.6% 🟢
server-common 69.72% 🟢
spark 32.79% 🔴
spark-common 39.09% 🔴
trino-connector 31.62% 🔴
Files
Module File Coverage
catalog-jdbc-clickhouse ClickHouseClusterUtils.java 100.0% 🟢
ClickHouseTableOperations.java 82.16% 🟢
ClickHouseDatabaseOperations.java 51.43% 🔴
catalog-jdbc-common JdbcCatalogOperations.java 9.05% 🔴

yuqi1129 and others added 3 commits March 12, 2026 15:23
Add explicit assertions for column ordering after updateColumnPosition and for col_1 default value after updateColumnDefaultValue in CatalogClickHouseClusterIT.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Validate create-table columns in ClickHouse and fail fast when any column is marked autoIncrement. Add unit and integration tests to lock behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Handle multiline ORDER BY/PARTITION BY clauses when parsing SHOW CREATE TABLE, so loadTable keeps sort orders configured at create time. Add unit parsing test and cluster integration assertions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yuqi1129 yuqi1129 self-assigned this Mar 12, 2026
@yuqi1129 yuqi1129 requested a review from diqiu50 March 12, 2026 09:26
@jerryshao jerryshao added the branch-1.2 Automatically cherry-pick commit to branch-1.2 label Mar 12, 2026
Comment thread docs/jdbc-clickhouse-catalog.md Outdated
@yuqi1129 yuqi1129 requested review from Copilot and diqiu50 March 16, 2026 07:45
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.


You can also share your feedback on Copilot code review. Take the survey.

Comment thread docs/jdbc-clickhouse-catalog.md Outdated
Comment thread docs/jdbc-clickhouse-catalog.md
@yuqi1129
Copy link
Copy Markdown
Contributor Author

@diqiu50
Could you help review it again?

JdbcConnectorUtils.executeUpdate(connection, generateDropDatabaseSql(databaseName, cascade));
if (!cascade) {
try (Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(String.format("SHOW TABLES IN `%s`", databaseName))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You'd better use the system table to check table exists in db

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What's the side effect of using SHOW TABLES IN?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May be the table is just not in this host, if you don't want handle this case, add some comments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Querying system table does not handle this case too. you'd better Add some comments

JdbcConnectorUtils.executeUpdate(connection, generateDropDatabaseSql(databaseName, cascade));
if (!cascade) {
try (Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(String.format("SHOW TABLES IN `%s`", databaseName))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May be the table is just not in this host, if you don't want handle this case, add some comments

@yuqi1129 yuqi1129 requested a review from diqiu50 March 20, 2026 03:56
* ENGINE = MergeTree()
* ORDER BY `id`
* COMMENT 'order records\n[Gravitino] ch.cluster=ck_cluster'
*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need an end marker?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mark "\n[Gravitino] ch.cluster=ck_cluster" will always at the end of the comment, what do you mean here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if the user add some comments after \n[Gravitino] ch.cluster=ck_cluster, is it a problem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean users will update the comment without using Gravitino and add something at the end of \n[Gravitino] ch.cluster=ck_cluster?

We can't avoid such a problem as long as users can update comments without notifying Gravitino.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So we usually add an end delimiter to avoid things getting mixed together.

JdbcConnectorUtils.executeUpdate(connection, generateDropDatabaseSql(databaseName, cascade));
if (!cascade) {
try (Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(String.format("SHOW TABLES IN `%s`", databaseName))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Querying system table does not handle this case too. you'd better Add some comments

Copy link
Copy Markdown
Contributor

@diqiu50 diqiu50 left a comment

Choose a reason for hiding this comment

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

LGTM

@yuqi1129 yuqi1129 merged commit 8afb307 into apache:main Mar 20, 2026
26 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 20, 2026
…bugs (#10383)

### What changes were proposed in this pull request?

Add comprehensive integration coverage for ClickHouse alter-table
behavior in:
- `CatalogClickHouseIT`
- `CatalogClickHouseClusterIT`

The new tests exercise `ClickHouseTableOperations#generateAlterTableSql`
branches in real ClickHouse environments, including:
- supported alter branches: add/update type/update default/update
comment/update position/update nullability/delete index/delete column
- edge/no-op branches: delete missing column/index with `ifExists=true`
- unsupported branches: set/remove property, update auto increment,
nested column add

Tests also verify resulting table metadata (column
type/comment/nullability/index removal) after alter operations.

### Why are the changes needed?

To prevent regressions in ClickHouse ALTER TABLE SQL generation and
close branch-level test gaps for issues discussed in #10381 and #10378.

Fixed: #10381
Fixed: #10372 
Fixed: #10396
Fixed: #10405

### Does this PR introduce _any_ user-facing change?

N/A


Closes #10381
Closes #10378

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yuqi1129 yuqi1129 deleted the fix-10381-10378-clickhouse-alter-it branch March 20, 2026 10:20
yuqi1129 added a commit that referenced this pull request Mar 20, 2026
… Fix ClickHouse alter-table bugs (#10383) (#10487)

**Cherry-pick Information:**
- Original commit: 8afb307
- Target branch: `branch-1.2`
- Status: ✅ Clean cherry-pick (no conflicts)

Co-authored-by: Qi Yu <yuqi@datastrato.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
diqiu50 pushed a commit to diqiu50/gravitino that referenced this pull request Mar 27, 2026
…alter-table bugs (apache#10383)

### What changes were proposed in this pull request?

Add comprehensive integration coverage for ClickHouse alter-table
behavior in:
- `CatalogClickHouseIT`
- `CatalogClickHouseClusterIT`

The new tests exercise `ClickHouseTableOperations#generateAlterTableSql`
branches in real ClickHouse environments, including:
- supported alter branches: add/update type/update default/update
comment/update position/update nullability/delete index/delete column
- edge/no-op branches: delete missing column/index with `ifExists=true`
- unsupported branches: set/remove property, update auto increment,
nested column add

Tests also verify resulting table metadata (column
type/comment/nullability/index removal) after alter operations.

### Why are the changes needed?

To prevent regressions in ClickHouse ALTER TABLE SQL generation and
close branch-level test gaps for issues discussed in apache#10381 and apache#10378.

Fixed: apache#10381
Fixed: apache#10372 
Fixed: apache#10396
Fixed: apache#10405

### Does this PR introduce _any_ user-facing change?

N/A


Closes apache#10381
Closes apache#10378

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
danhuawang pushed a commit to danhuawang/gravitino that referenced this pull request Mar 30, 2026
…alter-table bugs (apache#10383)

### What changes were proposed in this pull request?

Add comprehensive integration coverage for ClickHouse alter-table
behavior in:
- `CatalogClickHouseIT`
- `CatalogClickHouseClusterIT`

The new tests exercise `ClickHouseTableOperations#generateAlterTableSql`
branches in real ClickHouse environments, including:
- supported alter branches: add/update type/update default/update
comment/update position/update nullability/delete index/delete column
- edge/no-op branches: delete missing column/index with `ifExists=true`
- unsupported branches: set/remove property, update auto increment,
nested column add

Tests also verify resulting table metadata (column
type/comment/nullability/index removal) after alter operations.

### Why are the changes needed?

To prevent regressions in ClickHouse ALTER TABLE SQL generation and
close branch-level test gaps for issues discussed in apache#10381 and apache#10378.

Fixed: apache#10381
Fixed: apache#10372 
Fixed: apache#10396
Fixed: apache#10405

### Does this PR introduce _any_ user-facing change?

N/A


Closes apache#10381
Closes apache#10378

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment