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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to