Skip to content

Hive: Map geometry and geography type to binary in HiveSchemaUtil#17112

Open
csringhofer wants to merge 1 commit into
apache:mainfrom
csringhofer:hive_geom_geog_to_binary
Open

Hive: Map geometry and geography type to binary in HiveSchemaUtil#17112
csringhofer wants to merge 1 commit into
apache:mainfrom
csringhofer:hive_geom_geog_to_binary

Conversation

@csringhofer

Copy link
Copy Markdown

Add GEOMETRY and GEOGRAPHY cases to HiveSchemaUtil.convertToTypeString, mapping them to "binary".

"binary" was chosen instead of "unknown" because geometry/geography are WKB-encoded byte arrays - older readers not familiar with Iceberg/Parquet GEOMETRY can still read the created Parquet files by reading the column as BINARY and converting from WKB to their representation (st_GeomFromWKB() in Hive).

Motivation:
Bumped into this while integrating Iceberg geometry support into Apache Impala, which uses the Hive catalog for tests. Creating a table with a geometry column would throw UnsupportedOperationException from the default
branch of the switch. By patching HiveSchemaUtil in Iceberg I as able to create tables with GEOMETRY columns.

@github-actions github-actions Bot added the hive label Jul 6, 2026

@steveloughran steveloughran 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.

commented

public void testGeometryTypeConvertToHiveSchema() {
Schema schema = new Schema(optional(0, "geometry_field", Types.GeometryType.crs84()));
List<FieldSchema> hiveSchema = HiveSchemaUtil.convert(schema);
assertThat(hiveSchema).containsExactly(new FieldSchema("geometry_field", "binary", null));

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.

add a .describedAs("hive schema %s", schema) before the .containsExactly() for even better assertion details.

return "timestamp";
case FIXED:
case BINARY:
case GEOMETRY:

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.

as noted by the automated review, consider moving this switch statement to the java17
case key -> value style. The codebase moved to it entirely last month, then moved back to ease cherrypicking; if you look at the file history you can find the diff so see what to bring over, just for this switch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants