Skip to content

[Server] Accept geometry and geography types in the UC Delta API - #2370

Open
timothyw553 wants to merge 2 commits into
unitycatalog:mainfrom
timothyw553:stack/geotypes-delta-api
Open

timothyw553 wants to merge 2 commits into
unitycatalog:mainfrom
timothyw553:stack/geotypes-delta-api

Conversation

@timothyw553

@timothyw553 timothyw553 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


PR Checklist

Description of changes

Parses Delta geospatial type strings (geometry[(<crs>)] and geography[(<crs>[, <algorithm>]) | (<algorithm>)], where <crs> is <authority>:<code>) in ColumnUtils instead of rejecting them as unsupported primitives, canonicalizing type_text (trimmed whitespace, lowercase algorithm) while keeping the Delta wire type in type_json. Unknown geography algorithms (validated against Delta Kernel's GeographyType.VALID_ALGORITHMS) fail with INVALID_ARGUMENT; other malformed strings fall through to the existing unsupported-primitive error.

Tested with ColumnUtilsTest (including a Delta Kernel parser parity test) and an SDK create/get table test covering valid geo columns and an unsupported algorithm.

@timothyw553 timothyw553 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser logic looks solid overall. left two comments on type_text spark compatibility and reusing kernel's algorithm list.

ColumnTypeName typeName = resolveColumnTypeName(type);
// A geo type keeps its CRS and algorithm in the text, e.g. geometry(OGC:CRS84).
boolean isGeo = typeName == ColumnTypeName.GEOMETRY || typeName == ColumnTypeName.GEOGRAPHY;
return isGeo ? type.getType() : getTypeText(typeName);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

storing type.getType() directly in type_text breaks the existing native spark reader since DataType.fromDDL in spark 4.1/4.2 rejects geometry(OGC:CRS84) and geography(OGC:CRS84, spherical), and this also diverges from the spark path by preserving raw caller whitespace and casing. should we coordinate this with follow-up #2372 and agree on one canonical type_text format while keeping the full string in type_json? could we also update the toCatalogString javadoc that promises spark catalogString output and add an e2e test for creating via delta api and reading via native spark?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canonicalized geo type_text (trimmed whitespace, lowercase algorithm) while keeping the raw wire type in type_json, updated the toCatalogString Javadoc, and synced the Spark E2E test in #2372.

private static final Pattern GEOGRAPHY_TYPE =
Pattern.compile("geography(?:\\(\\s*(?:\\w+:-?\\w+(?:\\s*,\\s*(\\w+))?|(\\w+))\\s*\\))?");
private static final Set<String> GEOGRAPHY_ALGORITHMS =
Set.of("spherical", "vincenty", "thomas", "andoyer", "karney");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we reuse GeographyType.VALID_ALGORITHMS from kernel instead of duplicating the algorithm list? we could also sort it with new TreeSet<>(GEOGRAPHY_ALGORITHMS) in the error message so the order stays deterministic, and add a test comparing our regexes against kernel's parser so future dependency bumps don't drift.

+import io.delta.kernel.types.GeographyType;
+
-  private static final Set<String> GEOGRAPHY_ALGORITHMS =
-      Set.of("spherical", "vincenty", "thomas", "andoyer", "karney");
+  private static final Set<String> GEOGRAPHY_ALGORITHMS = GeographyType.VALID_ALGORITHMS;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to GeographyType.VALID_ALGORITHMS with TreeSet sorting in the error message and added a Delta Kernel parser parity test in ColumnUtilsTest.

@yili-db

yili-db commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] The geometry and geography parsing matches the forms Delta Kernel accepts (geometry[(crs)], geography[(crs[, algorithm]) | (algorithm)]), so no change is needed there.

// - CHAR / UDT: Spark's Delta writer normalizes CHAR/VARCHAR to STRING (via
// CharVarcharUtils) and unwraps UDTs to their underlying sqlType before persisting, so
// Delta clients never send "char(n)" or {"type":"udt",...}.
// - GEOMETRY / GEOGRAPHY: matched by resolveGeoTypeName above, since the type string carries

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] This bullet says geo types are matched above, but the call to resolveGeoTypeName is below this comment. Could we drop the bullet and put a short note at the call instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the note down to the resolveGeoTypeName call.

@timothyw553
timothyw553 force-pushed the stack/geotypes-delta-api branch from da145f5 to b13957d Compare November 30, 2026 10:13
@timothyw553
timothyw553 requested a review from yili-db November 30, 2026 18:38
@timothyw553
timothyw553 force-pushed the stack/geotypes-delta-api branch from b13957d to e87f9fc Compare November 30, 2026 18:59
@yili-db

yili-db commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

/review

@timothyw553 timothyw553 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no new comments on this pass. still holding until we sort out the type_text spark compatibility.

Matcher geography = GEOGRAPHY_TYPE.matcher(primitive);
if (!geography.matches()) return null;
String algorithm = geography.group(2) != null ? geography.group(2) : geography.group(3);
if (algorithm != null && !GEOGRAPHY_ALGORITHMS.contains(algorithm.toLowerCase(Locale.ROOT))) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we validate the algorithm case-insensitively here, but preserve the original case in type_json. to my understanding kernel compares geography algorithms case-sensitively (e.g. spherical vs spark's SPHERICAL), so could a managed-table rename fail kernel's schema evolution check if only the algorithm case differs? should we normalize algorithm case in both schemas compared for evolution checks and add a rename test for it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalized geography algorithm names to lowercase before Kernel evolution checks and added regression tests for both casing-only renames and actual algorithm changes.

// -------- geo columns keep their CRS and algorithm, and a bad algorithm is rejected --------
String geoName = "tbl_geo";
String geoLocation = "s3://test-bucket0/external-path/tbl_geo";
List<String> geoTypes = List.of("geometry(OGC:CRS84)", "geography(OGC:CRS84, spherical)");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since both inputs here are already normalized and we only assert typeName and typeText below, a bug that overwrites type_json with normalized text wouldn't be caught end-to-end. could we use a non-normalized input here and also check getTypeJson() on geoTable.getColumns()?

- List<String> geoTypes = List.of("geometry(OGC:CRS84)", "geography(OGC:CRS84, spherical)");
+ List<String> geoTypes =
+     List.of("geometry(OGC:CRS84)", "geography( OGC:CRS84 , SPHERICAL )");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated SdkCreateTableTest to send an unnormalized geography string and assert that type_text is canonicalized while type_json preserves the raw wire value.

@timothyw553
timothyw553 force-pushed the stack/geotypes-delta-api branch from e87f9fc to b694047 Compare November 30, 2026 20:12
@yili-db

yili-db commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

/review

@timothyw553 timothyw553 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left one comment on normalizeGeoAlgorithms dropping map field history. still holding on sorting out the type_text spark compatibility too.

DataType val = normalizeGeoAlgorithms(m.getValueType());
return (key == m.getKeyType() && val == m.getValueType())
? m
: new MapType(key, val, m.isValueContainsNull());

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to my understanding new MapType(key, val, ...) creates fresh key and value fields and drops their typeChanges history. if a map has a widened primitive key and a geography value, could normalizing only one schema wrongly reject a valid rename, or normalizing both erase differing histories? should we keep the existing fields instead and add a regression test for both cases?

-          : new MapType(key, val, m.isValueContainsNull());
+          : new MapType(
+              m.getKeyField().withDataType(key),
+              m.getValueField().withDataType(val));

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Approving. The parsing matches Delta Kernel's forms, and the case-insensitive algorithm handling for schema evolution is needed (Kernel compares algorithms case-sensitively) and covered by tests.

@timothyw553
timothyw553 force-pushed the stack/geotypes-delta-api branch from b694047 to 2297a0b Compare December 1, 2026 17:49
@timothyw553 timothyw553 closed this Dec 1, 2026
@timothyw553 timothyw553 reopened this Dec 1, 2026
@timothyw553
timothyw553 requested a review from shba24 December 1, 2026 23:48
@timothyw553
timothyw553 force-pushed the stack/geotypes-delta-api branch 2 times, most recently from 8de3aec to 337c492 Compare December 2, 2026 07:08
@yili-db

yili-db commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

/review

1 similar comment
@yili-db

yili-db commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

/review

Add GEOMETRY and GEOGRAPHY to ColumnTypeName in api/all.yaml (appended so existing ordinals stay unchanged).

Widen the ordinal CHECK constraints on uc_functions.data_type and uc_function_params.type_name from 0..21 to 0..23 across H2, PostgreSQL, and MySQL:
- V24 / V26 (SQL): add named CHECK (0..23) constraints on uc_functions and uc_function_params.
- V25 / V27 (Java migrations): look up and drop the old unnamed 0..21 CHECK constraints by clause so upgrades work on both fresh and repaired databases.

Update SchemaMigrator, MigrationStepRulesTest, docs/server/upgrades.md, and schema-effects for all three databases, and add SdkFunctionCRUDTest coverage for GEOMETRY and GEOGRAPHY function parameters and return types.

Signed-off-by: Timothy Wang <[email protected]>
Resolve the geo type strings Delta Kernel parses (geometry[(crs)],
geography[(crs[, algorithm])|(algorithm)]) to GEOMETRY and GEOGRAPHY, and
keep the string as type_text so the CRS and algorithm survive. type_json
already carries it. Without this a Delta table with a geo column is
rejected at create time as an unsupported primitive.

A geography algorithm Delta does not define is rejected with
INVALID_ARGUMENT, as Kernel does; other malformed forms fall through to the
existing unsupported-primitive error.

Signed-off-by: Timothy Wang <[email protected]>
@timothyw553
timothyw553 force-pushed the stack/geotypes-delta-api branch from 337c492 to 974d9a3 Compare December 2, 2026 19:27

This branch has not been deployed

No deployments
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.

3 participants