Skip to content

[#11910] fix(clickhouse): fix GraphiteMergeTree classification and add missing type mappings#11915

Open
jiangxt2 wants to merge 1 commit into
apache:mainfrom
jiangxt2:fix/clickhouse-graphite-typedef
Open

[#11910] fix(clickhouse): fix GraphiteMergeTree classification and add missing type mappings#11915
jiangxt2 wants to merge 1 commit into
apache:mainfrom
jiangxt2:fix/clickhouse-graphite-typedef

Conversation

@jiangxt2

@jiangxt2 jiangxt2 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fix: #11910

What changes were proposed in this pull request?

  • Fix GraphiteMergeTree incorrectly classified as not requiring ORDER BY (single-arg → three-arg constructor)
  • Add Enum8/Enum16 normalization via startsWith guard before the type switch
  • Add type mappings for Int128/Int256/UInt128/UInt256 (→ ExternalType, preserves round-trip)
  • Add BFloat16 → ExternalType mapping (no half-precision in Gravitino)
  • Restore DATE32 → ExternalType mapping (Date32 has wider range than Date)

Why are the changes needed?

GraphiteMergeTree tables cannot be created through Gravitino at all — the engine requires ORDER BY but the catalog rejects it. Multiple ClickHouse types (Enum8/16, wide integers, BFloat16, Date32) fall through to generic ExternalType instead of being handled explicitly.

Does this PR introduce any user-facing change?

No. GraphiteMergeTree tables become creatable; other type mappings preserve existing ExternalType behavior.

How was this patch tested?

  • ./gradlew :catalogs-contrib:catalog-jdbc-clickhouse:test -PskipITs — all 46 unit tests pass
  • Type converter round-trip tests cover Enum8/Enum16, Int128/Int256/UInt128/UInt256, BFloat16, DATE32

// No type mapping for date32, we will use external type to handle it.
case DATE32:
// Date32 supports 1900-2299 vs Date's 1970-2149. Use ExternalType to preserve round-trip.
return Types.ExternalType.of(DATE32);

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.

We haven't handled most types that can't be converted to the Gravitino type, as engines like Trino will not recognize externalType. Adding this type is designed to display types that are created by the catalog itself in Gravitino. As for how to use this type uniformly in engines, there is no clear solution now. anyway, this PR is useful and valuable.

@yuqi1129

yuqi1129 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Adding some ITs is preferable.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Code Coverage Report

Overall Project 67.47% +0.83% 🟢
Files changed 78.08% 🟢

Module Coverage
aliyun 1.72% 🔴
api 46.5% 🟢
authorization-common 85.96% 🟢
aws 42.04% 🟢
azure 2.47% 🔴
catalog-common 9.92% 🔴
catalog-fileset 80.23% 🟢
catalog-glue 66.91% 🟢
catalog-hive 79.42% 🟢
catalog-jdbc-clickhouse 80.63% +1.22% 🟢
catalog-jdbc-common 44.22% 🟢
catalog-jdbc-doris 80.28% +1.13% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.23% 🟢
catalog-jdbc-oceanbase 80.91% 🟢
catalog-jdbc-postgresql 82.29% 🟢
catalog-jdbc-starrocks 78.51% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 58.53% +1.2% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.86% 🟢
catalog-lakehouse-paimon 84.25% 🟢
catalog-model 77.72% 🟢
cli 44.5% -0.15% 🟢
client-java 78.01% +2.68% 🟢
common 50.13% -1.94% 🟢
core 82.59% +0.59% 🟢
filesystem-hadoop3 77.3% 🟢
flink 0.0% 🔴
flink-common 47.09% 🟢
flink-runtime 0.0% 🔴
gcp 14.12% 🔴
hadoop-auth 66.67% 🟢
hadoop-common 12.7% 🔴
hive-metastore-common 53.29% 🟢
iceberg-common 58.3% -6.22% 🟢
iceberg-rest-server 73.94% +1.77% 🟢
idp-basic 85.71% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 20.67% 🔴
lance-rest-server 64.84% 🟢
lineage 53.02% 🟢
optimizer 83.24% 🟢
optimizer-api 21.95% 🔴
server 85.94% +0.39% 🟢
server-common 74.62% 🟢
spark 28.57% 🔴
spark-common 46.01% 🟢
tencent 69.84% 🟢
trino-connector 40.29% 🟢
Files
Module File Coverage
api Group.java 0.0% 🔴
catalog-jdbc-clickhouse ClickHouseTypeConverter.java 100.0% 🟢
ClickHouseTablePropertiesMetadata.java 77.36% 🟢
catalog-jdbc-doris DorisTableOperations.java 81.6% 🟢
catalog-lakehouse-generic LanceTableOperations.java 59.38% 🔴
cli ListGroups.java 0.0% 🔴
client-java GravitinoMetalake.java 92.31% 🟢
GravitinoClient.java 70.89% 🟢
common RemoteUriValidator.java 91.67% 🟢
GroupDTO.java 77.27% 🟢
FileFetcher.java 64.15% 🟢
DTOConverters.java 29.14% 🔴
GroupAddRequest.java 0.0% 🔴
UserAddRequest.java 0.0% 🔴
core Entity.java 100.0% 🟢
AccessControlManager.java 100.0% 🟢
OperationType.java 100.0% 🟢
GroupInfo.java 100.0% 🟢
UserInfo.java 100.0% 🟢
GroupMetaBaseSQLProvider.java 100.0% 🟢
GroupMetaH2Provider.java 100.0% 🟢
GroupMetaPostgreSQLProvider.java 100.0% 🟢
GroupMetaService.java 100.0% 🟢
TableMetaService.java 100.0% 🟢
CompatibilityUtils.java 99.34% 🟢
GroupEntity.java 98.11% 🟢
AuditLog.java 97.52% 🟢
GroupMetaSQLProviderFactory.java 95.83% 🟢
AccessControlEventDispatcher.java 92.23% 🟢
PermissionManager.java 88.99% 🟢
POConverters.java 88.21% 🟢
UserGroupExternalManager.java 80.95% 🟢
JDBCBackend.java 80.25% 🟢
GroupPO.java 64.29% 🟢
AuthorizationUtils.java 61.51% 🟢
AccessControlHookDispatcher.java 36.05% 🔴
AccessControlDispatcher.java 0.0% 🔴
GroupMetaMapper.java 0.0% 🔴
iceberg-common IcebergCatalogWrapper.java 29.15% 🔴
iceberg-rest-server IcebergNamespaceOperationExecutor.java 100.0% 🟢
IcebergNamespaceEventDispatcher.java 96.88% 🟢
IcebergConfigOperations.java 96.36% 🟢
IcebergNamespaceHookDispatcher.java 90.54% 🟢
IcebergNamespaceOperations.java 79.17% 🟢
IcebergNamespaceOperationDispatcher.java 0.0% 🔴
server GroupOperations.java 100.0% 🟢
UserOperations.java 96.08% 🟢

…and add missing type mappings

Fix GraphiteMergeTree engine incorrectly classified as not requiring
ORDER BY, and add explicit type mappings for ClickHouse types that
previously fell through to generic ExternalType.

**GraphiteMergeTree engine fix**
- Change ENGINE enum from single-arg to three-arg constructor
  (requireOrderBy=true, acceptPartition=true)
- Add graphite.config property support for GraphiteMergeTree DDL
  generation (required by ClickHouse: ENGINE = GraphiteMergeTree('config'))
- Register GRAPHITE_CONFIG_PROPERTY_ENTRY in table properties metadata

**Enum8/Enum16 normalization**
- Add startsWith('Enum') guard before the type switch to normalize
  Enum8/Enum16 to base ENUM constant, preserving full parameterized
  form as ExternalType
- Use stripped typeName (not typeBean.getTypeName()) to avoid
  Nullable/LowCardinality wrapper leakage

**New type mappings**
- Int128/Int256/UInt128/UInt256 → ExternalType (wide integers)
- BFloat16 → ExternalType (no half-precision in Gravitino)
- Date32 → ExternalType (wider range than Date)

**ClickHouseContainer JDBC URL fix**
- Use localhost + getMappedPort() instead of container internal IP
  for macOS Docker Desktop compatibility

**IT tests**
- testCreateTableWithNewTypeMappings: verify Int128/256, UInt128/256,
  Enum8/16, Date32 round-trip via SQL CREATE TABLE + loadTable
- testGraphiteMergeTreeEngineCreation: verify missing graphite.config
  property throws IllegalArgumentException
- BFloat16 excluded from IT (requires ClickHouse 24.12+, CI uses 24.8.14)

Signed-off-by: jiangxt2 <jiangxt2@vip.qq.com>
@jiangxt2 jiangxt2 force-pushed the fix/clickhouse-graphite-typedef branch from a2deb3a to aea1b99 Compare July 8, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ClickHouse catalog: GraphiteMergeTree misclassified and multiple types fall through to ExternalType

2 participants