[Cherry-pick to branch-1.3] [#11879] fix(clickhouse): fix type conversion for Decimal, DateTime64, LowCardinality, and IPv4/IPv6 (#11884)#11894
Merged
Conversation
…, LowCardinality, and IPv4/IPv6 (#11884) ### What changes were proposed in this pull request? Fix four type conversion issues in the ClickHouse catalog's `ClickHouseTypeConverter`: 1. **Decimal(precision > 38) → ExternalType**: ClickHouse supports Decimal up to precision 76 (Decimal128/Decimal256), but Gravitino core `DecimalType` enforces precision ≤ 38. Tables with `Decimal(50, 10)` etc. previously threw `IllegalArgumentException` on `loadTable`. Now mapped to `ExternalType` for precision > 38, consistent with the existing pattern for non-standard types. 2. **DateTime64(N) precision preserved on round-trip**: `TypeUtils.extractDateTimePrecision()` regex did not match `DateTime64(3)` — the entire type fell through to `ExternalType`. Extended the regex to `^DateTime(?:64)?\((\d+)\)$`. In `fromGravitino`, `TimestampType` with precision > 0 now returns `DateTime64(N)` instead of bare `DateTime`. 3. **LowCardinality wrapper stripped before Nullable**: For `LowCardinality(Nullable(String))`, the outermost wrapper is `LowCardinality`. Added `TypeUtils.stripLowCardinality()` and call it before `stripNullable()` in `toGravitino()`. 4. **IPv4/IPv6 mapped to ExternalType**: Constants `IPV4` and `IPV6` were declared but had no `case` branches. Added `case IPV4:` / `case IPV6:` returning `ExternalType.of(...)`. ### Why are the changes needed? Fix: #11879 These issues cause ClickHouse tables with common column types (Decimal(50,x), DateTime64, LowCardinality, IPv4/IPv6) to either crash on `loadTable` or lose type semantics on round-trip. ### Does this PR introduce _any_ user-facing change? Yes. Tables with Decimal(precision > 38), DateTime64(N), LowCardinality(Nullable(...)), IPv4, or IPv6 columns can now be loaded without errors. Type round-trip fidelity is improved. ### How was this patch tested? - New unit tests in `TestClickHouseTypeConverter`: `./gradlew :catalogs-contrib:catalog-jdbc-clickhouse:test -PskipITs` (7 test scenarios: 4 toGravitino assertions — IPv6, DateTime64(3), LowCardinality(Nullable(String)), Decimal(50,10); 3 fromGravitino direction checks — DateTime64(3), IPv4, IPv6) - Updated existing Docker IT assertion in `TestClickHouseTableOperations.testTypeConversionAgainstCluster`: `c_dt64` column type changed from `ExternalType.of("DateTime64(3)")` to `TimestampType.withoutTimeZone(3)` to match the new `toGravitino()` behavior - Docker integration tests: `./gradlew :catalogs-contrib:catalog-jdbc-clickhouse:test -PskipDockerTests=false --tests "TestClickHouseTableOperations"` Signed-off-by: jiangxt2 <jiangxt2@vip.qq.com>
yuqi1129
approved these changes
Jul 4, 2026
yuqi1129
approved these changes
Jul 4, 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.
Cherry-pick Information:
branch-1.3