You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "jiangxt2 (via GitHub)" <gi...@apache.org> on 2026/06/26 08:22:36 UTC

[PR] [Bug] fix(clickhouse): add ON CLUSTER support for ALTER TABLE [gravitino]

jiangxt2 opened a new pull request, #11807:
URL: https://github.com/apache/gravitino/pull/11807

   ## What changes were proposed in this pull request?
   
   ### ALTER TABLE ON CLUSTER (`ClickHouseTableOperations.java`)
   
   - `generateAlterTableSql()` now checks if the table is on a cluster and injects `ON CLUSTER <clusterName>` into the ALTER TABLE SQL.
   - This adds one extra `getOrCreateTable` call to read cluster properties, for change types that do not otherwise require loading the table.
   - Added null-safety for `properties()` access, consistent with `generateDropTableSql()`.
   - When `ON_CLUSTER=true` and `CLUSTER_NAME` is set, generates `ALTER TABLE ... ON CLUSTER ...`; otherwise generates the standard `ALTER TABLE ...`.
   
   ### Root Cause
   
   Previously, `generateAlterTableSql()` always generated `ALTER TABLE %s \n%s;` without `ON CLUSTER`. For tables created `ON CLUSTER`, this caused schema divergence — the ALTER only affected the local node, while other cluster nodes retained the old schema.
   
   Note: Unlike `generateDropTableSql()` which uses `ON CLUSTER ... SYNC`, ALTER TABLE omits `SYNC` because ClickHouse does not support synchronous ALTER operations.
   
   ## Does this PR introduce any user-facing change?
   
   ALTER TABLE operations on clustered tables now propagate to all nodes in the cluster, preventing schema divergence.
   
   ## How was this patch tested?
   
   Unit tests:
   - `testAlterTableWithOnCluster`: ALTER TABLE SQL includes `ON CLUSTER` when table is clustered
   - `testAlterTableWithoutOnCluster`: ALTER TABLE SQL does NOT include `ON CLUSTER` when table is not clustered
   - `testAlterTableWithNullProperties`: No NPE when table properties are null
   
   Integration tests (ClickHouse cluster):
   - Existing `testAlterTableBranchCoverageInCluster` covers ALTER TABLE operations on clustered tables (add column, update type, update comment, delete index, etc.)
   
   Closes #11803
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Bug] fix(clickhouse): add ON CLUSTER support for ALTER TABLE [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11807:
URL: https://github.com/apache/gravitino/pull/11807#issuecomment-4840769026

   Could you also add some test cases in `CatalogClickHouseClusterIT`? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11803] fix(clickhouse): add ON CLUSTER support for ALTER TABLE [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11807:
URL: https://github.com/apache/gravitino/pull/11807#issuecomment-4842047025

   @jiangxt2 
   I'm going to merge this one. Could you try to modify the PR description, the following is a good example:
   <img width="1236" height="833" alt="image" src="https://github.com/user-attachments/assets/f6d2a484-91f4-4563-8482-9261e52498bd" />
   see: https://github.com/apache/gravitino/pull/11809


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Bug] fix(clickhouse): add ON CLUSTER support for ALTER TABLE [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11807:
URL: https://github.com/apache/gravitino/pull/11807#issuecomment-4841061889

   Thanks for the suggestion! I've added `testAlterTableOnClusterSqlGeneration()` in `CatalogClickHouseClusterIT`.
   
   **What it verifies**: queries `system.query_log` after ALTER TABLE operations to confirm:
   - ALTER on a cluster table (ON_CLUSTER=true) → SQL contains `ON CLUSTER` clause ✅
   - ALTER on a non-cluster table → SQL does NOT contain `ON CLUSTER` ✅
   
   **Test result**:
   ```
   CatalogClickHouseClusterIT > testAlterTableOnClusterSqlGeneration() PASSED (0.52s)
   Tests: 1 passed, 0 failed, 0 skipped
   ```
   
   This differs from the existing `testAlterTableBranchCoverageInCluster` which validates ALTER functionality (add/modify columns etc.). The new test specifically proves the ON CLUSTER clause is injected into the executed SQL — something that cannot be verified through the Gravitino API alone, since single-node clusters succeed regardless of ON CLUSTER presence.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11803] fix(clickhouse): add ON CLUSTER support for ALTER TABLE [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 merged PR #11807:
URL: https://github.com/apache/gravitino/pull/11807


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11803] fix(clickhouse): add ON CLUSTER support for ALTER TABLE [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11807:
URL: https://github.com/apache/gravitino/pull/11807#issuecomment-4842177447

   Updated the PR description to follow the standard template. PTAL, thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org