David Chaava created CALCITE-7946:
-------------------------------------
Summary: Add GEOGRAPHY type support and structural accessors
Key: CALCITE-7946
URL: https://issues.apache.org/jira/browse/CALCITE-7946
Project: Calcite
Issue Type: New Feature
Reporter: David Chaava
Calcite currently provides a planar {{GEOMETRY}} type. Calcite-based engines
need a distinct {{GEOGRAPHY}} type to preserve geographic columns through SQL
validation and relational planning without accidentally applying planar spatial
operations.
The motivating use case is Flink support for Iceberg geography columns.
h2. Scope
* Add {{GEOGRAPHY}} as an unparameterized SQL and relational type with a
distinct type family.
* Support parsing and unparsing under conformance that enables {{GEOGRAPHY}},
while keeping the keyword non-reserved.
* Preserve type identity and nullability through type derivation, nested types,
SQL/Rel conversions, and planner rewrites.
* Reject concrete casts between {{GEOGRAPHY}} and {{GEOMETRY}}, character, or
binary types.
* Reject ordering and equality-dependent operations where runtime equality and
hashing are unsupported.
* Add {{ST_IsEmpty(GEOGRAPHY)}} and {{ST_GeometryType(GEOGRAPHY)}}, with
execution on adapter-supplied values, to demonstrate end-to-end support.
The SQL type does not encode CRS/SRID, shape, coordinate layout, or storage
format. For the two accessors, the proposed local execution path uses a
JTS-backed geography wrapper and explicit adapter opt-in. Existing {{GEOMETRY}}
overloads retain their behavior, and geometry-only measurements continue to
reject {{GEOGRAPHY}} arguments.
h2. Expected behavior
Given an adapter-provided column {{g}} of type {{GEOGRAPHY}}:
* {{SELECT g}} preserves the {{GEOGRAPHY}} type.
* {{ST_IsEmpty(g)}} returns whether the value is empty.
* {{ST_GeometryType(g)}} returns its runtime shape name, such as {{POINT}} or
{{POLYGON}}.
* Both accessors return SQL {{NULL}} for a {{NULL}} argument.
* An empty value retains its concrete shape name.
* {{ST_Area(g)}} is rejected because no {{GEOGRAPHY}} measurement overload is
introduced.
Tests should cover parser conformance, validation, nullability, nested types,
SQL/Rel preservation, unsupported operations, and actual execution of both
accessors on non-NULL, empty, and NULL values.
h2. Out of scope
Geodetic measurements, geography constructors and WKT/WKB conversions,
independent shape/layout constraints, shared serialization, and database or
storage-format integrations.
h2. Discussion and design
* [Initial
discussion|https://lists.apache.org/thread/ykhbf99bggw2ylo4q1nbsyx2244m8cso]
* [Implementation
approach|https://lists.apache.org/thread/mh2w0gxho0d9kkw7pszkvo9mwjyopmlj]
* [Feedback supporting the initial scope with simple end-to-end
functions|https://lists.apache.org/thread/vk6s1lq1pdlpwnhn9zgpolt2gsxg6d3m]
* [Original design
proposal|https://docs.google.com/document/d/1Btqd0oZT8ctqIaGI_AROyAFJQe68RsVyeQbtmK4wHQw/edit]
The original proposal excluded functions. This issue incorporates the
subsequent discussion feedback by including the two structural accessors
described above.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)