[#12748] fix(clickhouse): preserve composite primary key on table load - #12765
Merged
yuqi1129 merged 1 commit intoSep 3, 2026
Merged
Conversation
…le load Signed-off-by: jiangxt2 <jiangxt2@vip.qq.com>
yuqi1129
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This pull request aggregates the ClickHouse primary-key metadata rows returned by
ClickHouseTableOperations.getIndexes()before constructing Gravitino indexes. Rows are grouped by the synthetic primary-key name and ordered byKEY_SEQ, soPRIMARY KEY (id, ts)is loaded as onePRIMARY_KEYindex whose fields are[[id], [ts]]instead of two independent single-column indexes.The implementation rejects null, non-positive, or duplicate key sequence values, while allowing positive sequence gaps because their relative order remains unambiguous. Existing single-column primary keys and data-skipping index loading remain unchanged.
The patch also adds direct unit coverage for grouping, ordering, invalid sequence metadata, single-column behavior, and secondary-index compatibility, plus a focused real ClickHouse create-load round-trip test for a two-column primary key.
Why are the changes needed?
The ClickHouse JDBC driver does not expose primary keys through
DatabaseMetaData.getPrimaryKeys, so the connector readssystem.tables.primary_keyand returns one metadata row per key column. The current implementation immediately converts each row into a separate Gravitino index and ignoresKEY_SEQ, which loses the identity and field order of a composite primary key.Aggregating these rows restores the same composite-index contract used by the common JDBC metadata path without changing public APIs, primary-key DDL generation, or data-skipping index parsing.
Fix: #12748
Does this PR introduce any user-facing change?
Yes. Loading a ClickHouse table with a composite primary key now returns one ordered Gravitino
PRIMARY_KEYindex instead of multiple single-column indexes with the same name. Single-column primary keys are unchanged, and no public API or property key is added or removed.How was this patch tested?
./gradlew :catalogs-contrib:catalog-jdbc-clickhouse:spotlessCheck --console=plain— passed../gradlew rat --console=plain— passed../gradlew :catalogs-contrib:catalog-jdbc-clickhouse:test -PskipITs --console=plain— passed;TestClickHouseTableOperationsUnitreported 34 tests, zero skipped, failures, or errors../gradlew :catalogs-contrib:catalog-jdbc-clickhouse:build -x test --console=plain— passed../gradlew :catalogs-contrib:catalog-jdbc-clickhouse:test --tests 'org.apache.gravitino.catalog.clickhouse.integration.test.CatalogClickHouseIT.testCreateAndLoadCompositePrimaryKey' -PskipDockerTests=false --console=plain --no-daemon— passed against ClickHouse 24.8.14 with tests=1, skipped=0, failures=0, errors=0../gradlew :catalogs-contrib:catalog-jdbc-clickhouse:test --tests 'org.apache.gravitino.catalog.clickhouse.integration.test.CatalogClickHouseClusterIT' -PskipDockerTests=false --console=plain --no-daemon— passed against ClickHouse 24.8.14 with tests=18, skipped=0, failures=0, errors=0.PRIMARY KEY (id, ts)produces metadata rowsid/1andts/2.