Repository navigation
[CLI/UI/Docs] Support and document geometry and geography columns - #2373
timothyw553 wants to merge 5 commits into
Conversation
b4b0baf to
1b945ae
Compare
bf39261 to
5a8969d
Compare
| } | ||
|
|
||
| #[test] | ||
| fn maps_geo_column_types() { |
There was a problem hiding this comment.
awesome. Thanks for adding these in here.
newfront
left a comment
There was a problem hiding this comment.
I looked over the changes to ui-new. These look great.
|
/review |
8922814 to
8d122f4
Compare
|
/review |
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Review of this PR's own commit, 8d122f4. It is stacked on #2369 to #2372. Those are unchanged since their reviews, so only this commit was reviewed.
Findings:
- Geo CRS and algorithm in
--columnscan be silently dropped (inline onCliUtils.java). - The legacy UI generated enum is still not regenerated.
ui/src/types/api/catalog.gen.tshas no GEOMETRY or GEOGRAPHY, and #2375 (the UI PR) is closed, so no open PR covers it. Could it be regenerated here or in an open PR? - Follow-up: add a CLI create test for a geo Delta table. The create path is not covered end to end. Delta Kernel 4.4.1 appears to enable the geospatial feature from the schema (checked by reading the class), so the test would confirm it.
- Nit:
bin/uc table create --help(CliParams.java, COLUMNS text) does not list GEOMETRY or GEOGRAPHY. - Nit: the CLI does not validate the CRS or algorithm, so a bad value is only rejected later by the server. Validating the
<authority>:<code>form andGeographyType.VALID_ALGORITHMSinparseColumnswould fail earlier.
| String precisionAndScale = setPrecisionAndScale(columnInfo, typeName, params); | ||
| if (isGeoType(typeName) && params != null) { | ||
| // GEOMETRY(<crs>) or GEOGRAPHY(<crs>[, <algorithm>]): keep the CRS and algorithm. | ||
| precisionAndScale = "(" + params.trim().replaceAll("\\s*,\\s*", ", ") + ")"; |
There was a problem hiding this comment.
[AI Assisted] This keeps the parsed CRS or algorithm only when params is non-null, but the column pattern only captures parameters that start right after the type name (GEOMETRY(). g GEOMETRY (EPSG:3857), g GEOMETRY(EPSG:3857 and g GEOMETRY() all reach here with params == null, so the column is stored as bare geometry (the default OGC:CRS84), and g GEOGRAPHY (EPSG:4326, karney) loses its algorithm. The pattern was reproduced with a standalone Java snippet. Could we accept the same \s*\( form that DECIMAL gets, and fail on parameters that are not consumed?
| String precisionAndScale = setPrecisionAndScale(columnInfo, typeName, params); | ||
| if (isGeoType(typeName) && params != null) { | ||
| // GEOMETRY(<crs>) or GEOGRAPHY(<crs>[, <algorithm>]): keep the CRS and algorithm. | ||
| precisionAndScale = "(" + params.trim().replaceAll("\\s*,\\s*", ", ") + ")"; |
There was a problem hiding this comment.
[AI Assisted] The geo parameters are put into type_json without escaping. typeJson is built with String.format around this value, so a " or \ in a CRS or algorithm produces invalid JSON. Found by reading the code, not reproduced. Could the JSON be built with a serializer, or could the parameters be rejected unless they match the CRS and algorithm forms?
| - Delta Lake support for geospatial types is a preview feature that is off by default. Enable it in the Spark session with `spark.databricks.delta.geo.preview.enabled=true`. | ||
| - Writing geo values to Parquet files needs Spark 4.2 or later. On Spark 4.1 a geo table can be created and read as a schema, but inserting rows fails. | ||
| - `bin/uc table read` shows a geo value as its well-known binary (WKB) in hex. | ||
| - The server accepts Delta's `geometry(<crs>)` and `geography(<crs>, <algorithm>)` type strings, and stores them as given. |
There was a problem hiding this comment.
[AI Assisted] type_json keeps the Delta type the user supplied, but the server stores type_text in canonical form (whitespace is trimmed and the geography algorithm is lowercased). Could this say that instead of "stores them as given"?
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]>
Iceberg 1.11 defines geometry(crs) and geography(crs, algorithm), so map them to GEOMETRY and GEOGRAPHY instead of rejecting the table, and drop the comment that said Iceberg has no such types. type_text and type_json carry the Delta form, geometry(<crs>) and geography(<crs>, <algorithm>). Iceberg accepts any CRS string, but Delta clients only parse <authority>:<code>, so another CRS is rejected up front rather than stored as a type they can't read. Signed-off-by: Timothy Wang <[email protected]>
Map Spark's geometry and geography types to GEOMETRY and GEOGRAPHY when creating a table, through a GeoTypes shim that is a no-op on Spark 4.0, which has neither type. Load a table whose geo column was stored in Delta's form, such as geometry(OGC:CRS84): Spark's DDL parser rejects that, but its JSON parser reads it, so such a column is read from type_json. Tests: unit tests for both mappings, a create-and-load test for managed Delta tables on Spark 4.1+, and geo columns in the type matrix on Spark 4.2+, where the Parquet writer can write them. Delta's geo preview flag is set in the test sessions only. Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
8d122f4 to
ac24111
Compare
🥞 Stacked PR
Use this link to review incremental changes.
PR Checklist
docsis updatedDescription of changes
GEOMETRYandGEOGRAPHY(with optional CRS and algorithm) inbin/uc table create --columns, preserving them intype_textandtype_json. When reading a Delta table withbin/uc table read, deserializes geo columns' Kernel types fromtype_jsonand prints WKB bytes as0x-prefixed hex instead of throwingUnsupportedOperationException.ui-new): AddsCOLUMN_TYPE_NAME_GEOMETRYandCOLUMN_TYPE_NAME_GEOGRAPHYtoui-new/proto/uc/v1/common.protoand maps"GEOMETRY"/"GEOGRAPHY"inui-new/server/src/mapping.rsso geo columns do not come back asUNSPECIFIED.GEOMETRYandGEOGRAPHYcolumns indocs/usage/cli.md,docs/usage/tables/deltalake.md, anddocs/usage/tables/formats.md, including--columnssyntax, defaults (OGC:CRS84,spherical), supported algorithms, WKB hex output on read, and Spark/Delta runtime requirements (Spark 4.1+,spark.databricks.delta.geo.preview.enabled=true, and Spark 4.2+ for Parquet writes).Tested with CLI column-parsing, Kernel type-deserialization, WKB hex-formatting, and table-creation unit tests, plus
buf lint,buf build, andui-new/webtests locally (ui-new/serverRust tests still need acargo testrun wherecrates.iois reachable).