Skip to content

[#12104] fix(spark-connector): Map ExternalType to StringType to prevent UnsupportedOperationException#12105

Open
jiangxt2 wants to merge 3 commits into
apache:mainfrom
jiangxt2:fix/spark-external-type
Open

[#12104] fix(spark-connector): Map ExternalType to StringType to prevent UnsupportedOperationException#12105
jiangxt2 wants to merge 3 commits into
apache:mainfrom
jiangxt2:fix/spark-external-type

Conversation

@jiangxt2

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Add ExternalType → DataTypes.StringType mapping in SparkTypeConverter.toSparkType() base class. This prevents tables with ExternalType columns from throwing UnsupportedOperationException during loadTable() in the Spark connector.

Placing the fix in the base class covers all subclasses across Spark versions 3.3/3.4/3.5 (JDBC, Hive, and Glue connectors) with a single change.

Why are the changes needed?

SparkTypeConverter.toSparkType() handles ~20 Gravitino native types but has no branch for Types.ExternalType. When a JDBC catalog table contains database-specific types (e.g. ClickHouse IPv4/IPv6, Doris LARGEINT/BITMAP), the Gravitino server maps them to ExternalType, which then falls through to the final throw in toSparkType() — crashing the entire table load.

Affected catalogs include ClickHouse (16+ types), Doris (7 types), MySQL, PostgreSQL, OceanBase, Hologres, and Glue.

The fix follows the existing pattern used for UUID (also mapped to StringType because Spark has no native UUID type).

Fix: #12104

Does this PR introduce any user-facing change?

Yes — tables with ExternalType columns are now loadable in Spark. The columns are presented as StringType, and users can CAST to the desired type as needed, e.g. CAST(ip AS STRING).

How was this patch tested?

  • Unit tests: TestSparkJdbcTypeConverter.testConvertExternalTypeToSparkString (spark-common) + TestSparkJdbcTypeConverter34 (v3.4), covering LARGEINT/BITMAP/IPv4
  • Docker integration tests:
    • CatalogClickHouseIT.testIPv4ColumnIsExternalType — verifies ClickHouse IPv4 columns are exposed as ExternalType in Gravitino metadata
    • CatalogDoris4xIT.testLargeintColumnIsExternalType — verifies Doris LARGEINT columns round-trip correctly

…o prevent UnsupportedOperationException

Add ExternalType → StringType mapping in SparkTypeConverter.toSparkType()
base class. This prevents tables with ExternalType columns (e.g. ClickHouse
IPv4/IPv6, Doris LARGEINT/BITMAP, Glue unknown types) from throwing
UnsupportedOperationException during loadTable() in the Spark connector.

Placing the fix in the base class covers all subclasses across Spark
versions 3.3/3.4/3.5, including JDBC, Hive, and Glue connectors.

Signed-off-by: jiangxt2 <jiangxt2@vip.qq.com>

Copilot AI left a comment

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.

Pull request overview

This PR updates the Spark connector’s type conversion logic to safely handle Gravitino Types.ExternalType by mapping it to Spark StringType, preventing UnsupportedOperationException during table loads across Spark 3.3/3.4/3.5 connectors.

Changes:

  • Add ExternalType -> DataTypes.StringType handling in the shared SparkTypeConverter.toSparkType() implementation.
  • Add/extend unit coverage for JDBC type converters (including Spark 3.4-specific converter).
  • Document the ExternalType mapping behavior and add integration tests that exercise real-world “external” types (ClickHouse IPv4, Doris LARGEINT).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/SparkTypeConverter.java Add ExternalType handling to avoid Spark table-load crashes.
spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcTypeConverter.java Add unit test ensuring ExternalType converts to StringType.
spark-connector/v3.4/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcTypeConverter34.java Add Spark 3.4-specific unit test coverage for ExternalType conversion.
docs/spark-connector/spark-connector.md Document UUID and ExternalType being represented as StringType.
catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDoris4xIT.java Add docker IT verifying LARGEINT round-trip/load behavior doesn’t break table loading.
catalogs-contrib/catalog-jdbc-clickhouse/src/test/java/org/apache/gravitino/catalog/clickhouse/integration/test/CatalogClickHouseIT.java Add docker IT verifying ClickHouse IPv4 is exposed as ExternalType in metadata.

Comment thread docs/spark-connector/spark-connector.md Outdated
@github-actions

Copy link
Copy Markdown

Code Coverage Report

Overall Project 67.9% +0.16% 🟢
Files changed 82.3% 🟢

Module Coverage
aliyun 1.72% 🔴
api 47.82% 🟢
authorization-common 85.96% 🟢
aws 42.04% 🟢
azure 2.47% 🔴
catalog-common 9.92% 🔴
catalog-fileset 79.77% 🟢
catalog-glue 66.91% 🟢
catalog-hive 79.42% 🟢
catalog-jdbc-clickhouse 81.74% +5.01% 🟢
catalog-jdbc-common 44.81% 🟢
catalog-jdbc-doris 81.6% 🟢
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 59.18% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.87% 🟢
catalog-lakehouse-paimon 84.25% 🟢
catalog-model 77.72% 🟢
cli 44.5% 🟢
client-java 78.27% 🟢
common 51.95% 🟢
core 82.51% 🟢
filesystem-hadoop3 77.28% 🟢
flink 0.0% 🔴
flink-common 47.09% 🟢
flink-runtime 0.0% 🔴
gcp 14.12% 🔴
hadoop-auth 68.0% 🟢
hadoop-common 12.7% 🔴
hive-metastore-common 53.4% 🟢
iceberg-common 63.77% 🟢
iceberg-rest-server 74.9% 🟢
idp-basic 86.02% 🟢
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 86.05% 🟢
server-common 75.98% -1.28% 🟢
spark 40.0% 🟢
spark-common 46.11% +3.52% 🟢
tencent 69.84% 🟢
trino-connector 40.29% 🟢
Files
Module File Coverage
catalog-jdbc-clickhouse ClickHouseTableOperations.java 85.73% 🟢
server-common MetadataAuthzHelper.java 54.67% 🔴
spark-common SparkTypeConverter.java 95.31% 🟢

jiangxt2 and others added 2 commits July 21, 2026 11:30
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…merge duplicate comments

- Replace CAST(ip AS STRING) with CAST(col AS BIGINT) in docs, since
  ExternalType is already mapped to StringType
- Collapse two redundant "Verify that..." comments into one line

Signed-off-by: jiangxt2 <jiangxt2@vip.qq.com>
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.

fix(spark-connector): Map ExternalType to StringType to prevent UnsupportedOperationException

2 participants