lxy-9602 commented on code in PR #580: URL: https://github.com/apache/paimon-cpp/pull/580#discussion_r4666817510
########## cmake_modules/arrow_geospatial.diff: ########## @@ -0,0 +1,1384 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Backport GEOMETRY/GEOGRAPHY logical types from Apache Arrow 21.0.0. Review Comment: This patch combines an Arrow backport with Paimon-specific behavior changes. Compared with Arrow 26.0.1, it differs in several areas: - It maps Binary fields with GeoArrow metadata directly to Parquet logical types, while upstream uses Arrow ExtensionType. - Its GeoArrow conversion accepts five geography edge algorithms and preserves CRS strings differently from upstream. - It adds custom null-count statistics handling that is not fully present upstream. If we introduce a backport patch, its implementation should match a specific, documented upstream Arrow release. Paimon-specific adaptations should be kept outside the Arrow patch, so that upgrading to the corresponding upstream version allows the patch to be removed without losing required behavior. The current design does not meet that requirement: removing it after an Arrow upgrade would change schema conversion, supported parameters, and statistics behavior. Please make this patch a direct backport of the implementation from a specific upstream Arrow release, and document the exact source version or commits. It should not introduce downstream behavior changes, so that it can be removed entirely once Arrow is upgraded to that release. ########## docs/source/user_guide/data_types.rst: ########## @@ -476,3 +484,51 @@ and `Arrow DataTypes <https://arrow.apache.org/docs/format/Columnar.html#data-ty types or listed in ``blob-descriptor-field`` or ``blob-view-field``. Paimon C++ does not support compacting these tables yet. See :doc:`write` for writing BLOB columns. + +Geospatial types +---------------- + +``GEOMETRY`` and ``GEOGRAPHY`` store OGC Well-Known Binary (WKB) in Arrow +``Binary`` arrays and preserve the original bytes. Both types support NULL and +can appear inside ROW, ARRAY, and MAP. An empty geometry retains its WKB encoding +as a non-null value. The table schema preserves declared MAP key nullability, +although Arrow and Parquet require every stored key to have a value. + +The schema syntax is ``GEOMETRY(crs)`` or ``GEOGRAPHY(crs, algorithm)``. +Omitting the parameters uses CRS ``OGC:CRS84`` and geography algorithm +``spherical``. ``GEOGRAPHY(crs)`` also uses ``spherical``. The other supported +algorithms are ``vincenty``, ``thomas``, ``andoyer``, and ``karney``. +CRS strings must be nonempty and compare case-insensitively, matching Java. +Quote CRS parameters containing whitespace or delimiters with single quotes. +Escape a single quote by doubling it, for example +``GEOMETRY('custom, ''quoted'' CRS')``. + +Arrow fields use ``ARROW:extension:name=geoarrow.wkb`` and JSON in +``ARROW:extension:metadata``. A geometry field uses, for example, +``{"crs":"EPSG:3857"}``, and a geography field uses +``{"edges":"karney","crs":"EPSG:4326"}``. When constructing nested schemas, +attach the metadata to each geospatial leaf. ``Schema::GetFieldType`` returns +``FieldType::GEOMETRY`` or ``FieldType::GEOGRAPHY`` for these fields. + +Set ``file.format`` to ``parquet`` (the default) and use Parquet for any +``file.format.per.level`` or ``changelog-file.format`` overrides. The bundled +Arrow 17 backport maps these fields to native Parquet ``GEOMETRY`` and +``GEOGRAPHY`` annotations on ``BYTE_ARRAY`` columns. + +Columns containing geospatial values, including nested values, cannot be primary, +partition, or bucket keys, sequence or sequence-group ordering fields, or +clustering/sort columns. Casts and schema evolution require the same logical type, +CRS, and geography algorithm. +``BYTES``, ``GEOMETRY``, and ``GEOGRAPHY`` are distinct logical types. + +Paimon and Parquet retain null counts. If a row group omits a geospatial +column's null count, the file-level count is unknown. File, row-group, and page +pruning ignore WKB min/max bounds. Use ``IS NULL`` or ``IS NOT NULL`` to filter +on nullability. + Review Comment: `If a given row group is missing the null count, then the file-level count is unknown.` This seems unrelated to the physical type? ########## src/paimon/format/parquet/parquet_field_id_converter.h: ########## @@ -45,10 +46,12 @@ class ParquetFieldIdConverter { enum class IdConvertType { PARQUET_TO_PAIMON_ID = 1, PAIMON_TO_PARQUET_ID = 2, + PAIMON_TO_PARQUET_WITH_ELEMENT_IDS, }; static arrow::Result<std::shared_ptr<arrow::Field>> ProcessField( - const std::shared_ptr<arrow::Field>& field, IdConvertType convert_type); + const std::shared_ptr<arrow::Field>& field, IdConvertType convert_type, + std::optional<int32_t> owner_id = std::nullopt, int32_t depth = 0); Review Comment: Please avoid using default parameters in the production code. ########## docs/source/user_guide/data_types.rst: ########## @@ -476,3 +484,51 @@ and `Arrow DataTypes <https://arrow.apache.org/docs/format/Columnar.html#data-ty types or listed in ``blob-descriptor-field`` or ``blob-view-field``. Paimon C++ does not support compacting these tables yet. See :doc:`write` for writing BLOB columns. + +Geospatial types +---------------- + +``GEOMETRY`` and ``GEOGRAPHY`` store OGC Well-Known Binary (WKB) in Arrow +``Binary`` arrays and preserve the original bytes. Both types support NULL and +can appear inside ROW, ARRAY, and MAP. An empty geometry retains its WKB encoding +as a non-null value. The table schema preserves declared MAP key nullability, +although Arrow and Parquet require every stored key to have a value. + +The schema syntax is ``GEOMETRY(crs)`` or ``GEOGRAPHY(crs, algorithm)``. +Omitting the parameters uses CRS ``OGC:CRS84`` and geography algorithm +``spherical``. ``GEOGRAPHY(crs)`` also uses ``spherical``. The other supported +algorithms are ``vincenty``, ``thomas``, ``andoyer``, and ``karney``. +CRS strings must be nonempty and compare case-insensitively, matching Java. +Quote CRS parameters containing whitespace or delimiters with single quotes. +Escape a single quote by doubling it, for example +``GEOMETRY('custom, ''quoted'' CRS')``. + +Arrow fields use ``ARROW:extension:name=geoarrow.wkb`` and JSON in +``ARROW:extension:metadata``. A geometry field uses, for example, +``{"crs":"EPSG:3857"}``, and a geography field uses +``{"edges":"karney","crs":"EPSG:4326"}``. When constructing nested schemas, +attach the metadata to each geospatial leaf. ``Schema::GetFieldType`` returns +``FieldType::GEOMETRY`` or ``FieldType::GEOGRAPHY`` for these fields. + +Set ``file.format`` to ``parquet`` (the default) and use Parquet for any +``file.format.per.level`` or ``changelog-file.format`` overrides. The bundled +Arrow 17 backport maps these fields to native Parquet ``GEOMETRY`` and +``GEOGRAPHY`` annotations on ``BYTE_ARRAY`` columns. + +Columns containing geospatial values, including nested values, cannot be primary, +partition, or bucket keys, sequence or sequence-group ordering fields, or +clustering/sort columns. Casts and schema evolution require the same logical type, +CRS, and geography algorithm. +``BYTES``, ``GEOMETRY``, and ``GEOGRAPHY`` are distinct logical types. + +Paimon and Parquet retain null counts. If a row group omits a geospatial +column's null count, the file-level count is unknown. File, row-group, and page +pruning ignore WKB min/max bounds. Use ``IS NULL`` or ``IS NOT NULL`` to filter +on nullability. + +The bidirectional interoperability test uses Paimon Java's Parquet reader and +writer. It requires Java 11 or later, Maven, and a Paimon Java bundle with +geospatial support. Set ``PAIMON_JAVA_VERSION`` to the available bundle version +(default ``2.2-SNAPSHOT``). Run ``test/inte/geospatial/run.sh`` after building +``paimon-parquet-format-test``. It creates temporary files in both languages and +checks nested annotations, all five edge algorithms, WKB, nulls, and statistics. Review Comment: This seems a bit odd—why does the user manual include an introduction for Java code? Could we please streamline the user documentation and remove any unnecessary sections? ########## test/inte/geospatial/GeospatialInterop.java: ########## @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.paimon.data.DataGetters; +import org.apache.paimon.data.GenericArray; +import org.apache.paimon.data.GenericMap; +import org.apache.paimon.data.GenericRow; +import org.apache.paimon.data.InternalArray; +import org.apache.paimon.data.InternalMap; +import org.apache.paimon.data.InternalRow; +import org.apache.paimon.format.FileFormat; +import org.apache.paimon.format.FormatReaderContext; +import org.apache.paimon.format.FormatWriter; +import org.apache.paimon.format.parquet.ParquetSchemaConverter; +import org.apache.paimon.format.parquet.ParquetUtil; +import org.apache.paimon.fs.Path; +import org.apache.paimon.fs.PositionOutputStream; +import org.apache.paimon.fs.local.LocalFileIO; +import org.apache.paimon.options.Options; +import org.apache.paimon.types.DataField; +import org.apache.paimon.types.DataType; +import org.apache.paimon.types.DataTypes; +import org.apache.paimon.types.EdgeAlgorithm; +import org.apache.paimon.types.RowType; +import org.apache.paimon.utils.CloseableIterator; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class GeospatialInterop { Review Comment: Why do we need to keep the Java code, `pom.xml`, and `run.sh` in the codebase? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
