Repository navigation
[Server] Accept geometry and geography types in the UC Delta API - #2370
timothyw553 wants to merge 2 commits into
Conversation
1b1a2de to
da145f5
Compare
timothyw553
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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;There was a problem hiding this comment.
Switched to GeographyType.VALID_ALGORITHMS with TreeSet sorting in the error message and added a Delta Kernel parser parity test in ColumnUtilsTest.
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[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 |
There was a problem hiding this comment.
[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?
There was a problem hiding this comment.
Moved the note down to the resolveGeoTypeName call.
da145f5 to
b13957d
Compare
b13957d to
e87f9fc
Compare
|
/review |
timothyw553
left a comment
There was a problem hiding this comment.
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))) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)"); |
There was a problem hiding this comment.
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 )");There was a problem hiding this comment.
Updated SdkCreateTableTest to send an unnormalized geography string and assert that type_text is canonicalized while type_json preserves the raw wire value.
e87f9fc to
b694047
Compare
|
/review |
timothyw553
left a comment
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
[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.
b694047 to
2297a0b
Compare
8de3aec to
337c492
Compare
|
/review |
1 similar comment
|
/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]>
337c492 to
974d9a3
Compare
🥞 Stacked PR
Use this link to review incremental changes.
PR Checklist
docsis updated (in [CLI/UI/Docs] Support and document geometry and geography columns #2373)Description of changes
Parses Delta geospatial type strings (
geometry[(<crs>)]andgeography[(<crs>[, <algorithm>]) | (<algorithm>)], where<crs>is<authority>:<code>) inColumnUtilsinstead of rejecting them as unsupported primitives, canonicalizingtype_text(trimmed whitespace, lowercase algorithm) while keeping the Delta wire type intype_json. Unknown geography algorithms (validated against Delta Kernel'sGeographyType.VALID_ALGORITHMS) fail withINVALID_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.