wgtmac commented on code in PR #45459: URL: https://github.com/apache/arrow/pull/45459#discussion_r1962884901
########## cpp/src/parquet/geometry_statistics.cc: ########## @@ -0,0 +1,291 @@ +// 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. + +#include "parquet/geometry_statistics.h" +#include <memory> + +#include "arrow/array.h" +#include "arrow/type.h" +#include "arrow/util/bit_run_reader.h" +#include "arrow/util/logging.h" +#include "parquet/exception.h" +#include "parquet/geometry_util_internal.h" + +using arrow::util::SafeLoad; + +namespace parquet { + +class GeospatialStatisticsImpl { + public: + GeospatialStatisticsImpl() = default; + GeospatialStatisticsImpl(const GeospatialStatisticsImpl&) = default; + + bool Equals(const GeospatialStatisticsImpl& other) const { + if (is_valid_ != other.is_valid_) { + return false; + } + + if (!is_valid_ && !other.is_valid_) { + return true; + } + + auto geospatial_types = bounder_.GeometryTypes(); + auto other_geospatial_types = other.bounder_.GeometryTypes(); + if (geospatial_types.size() != other_geospatial_types.size()) { + return false; + } + + for (size_t i = 0; i < geospatial_types.size(); i++) { + if (geospatial_types[i] != other_geospatial_types[i]) { + return false; + } + } + + return bounder_.Bounds() == other.bounder_.Bounds(); + } + + void Merge(const GeospatialStatisticsImpl& other) { + is_valid_ = is_valid_ && other.is_valid_; Review Comment: Should we skip the following if is_valid_ is false? ########## cpp/src/parquet/geometry_util_internal.h: ########## @@ -0,0 +1,184 @@ +// 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. + +#pragma once + +#include <algorithm> +#include <limits> +#include <sstream> +#include <string> +#include <unordered_set> + +#include "parquet/platform.h" + +namespace parquet::geometry { + +/// \brief Infinity, used to define bounds of empty bounding boxes +constexpr double kInf = std::numeric_limits<double>::infinity(); + +/// \brief Valid combinations of dimensions allowed by ISO well-known binary +enum class Dimensions { XY = 0, XYZ = 1, XYM = 2, XYZM = 3, MIN = 0, MAX = 3 }; + +/// \brief The supported set of geometry types allowed by ISO well-known binary +enum class GeometryType { + POINT = 1, + LINESTRING = 2, + POLYGON = 3, + MULTIPOINT = 4, + MULTILINESTRING = 5, + MULTIPOLYGON = 6, + GEOMETRYCOLLECTION = 7, + MIN = 1, + MAX = 7 +}; + +/// \brief A collection of intervals representing the encountered ranges of values +/// in each dimension. +struct BoundingBox { + using XY = std::array<double, 2>; + using XYZ = std::array<double, 3>; + using XYM = std::array<double, 3>; + using XYZM = std::array<double, 4>; + + BoundingBox(const XYZM& mins, const XYZM& maxes) : min(mins), max(maxes) {} + BoundingBox() : min{kInf, kInf, kInf, kInf}, max{-kInf, -kInf, -kInf, -kInf} {} + + BoundingBox(const BoundingBox& other) = default; + BoundingBox& operator=(const BoundingBox&) = default; + + /// \brief Update the X and Y bounds to ensure these bounds contain coord + void UpdateXY(const XY& coord) { UpdateInternal(coord); } + + /// \brief Update the X, Y, and Z bounds to ensure these bounds contain coord + void UpdateXYZ(const XYZ& coord) { UpdateInternal(coord); } + + /// \brief Update the X, Y, and M bounds to ensure these bounds contain coord + void UpdateXYM(const XYM& coord) { + min[0] = std::min(min[0], coord[0]); + min[1] = std::min(min[1], coord[1]); + min[3] = std::min(min[3], coord[2]); + max[0] = std::max(max[0], coord[0]); + max[1] = std::max(max[1], coord[1]); + max[3] = std::max(max[3], coord[2]); + } + + /// \brief Update the X, Y, Z, and M bounds to ensure these bounds contain coord + void UpdateXYZM(const XYZM& coord) { UpdateInternal(coord); } + + /// \brief Reset these bounds to an empty state such that they contain no coordinates + void Reset() { + for (int i = 0; i < 4; i++) { + min[i] = kInf; + max[i] = -kInf; + } + } + + /// \brief Update these bounds such they also contain other + void Merge(const BoundingBox& other) { + for (int i = 0; i < 4; i++) { + min[i] = std::min(min[i], other.min[i]); + max[i] = std::max(max[i], other.max[i]); + } + } + + std::string ToString() const { + std::stringstream ss; + ss << "BoundingBox [" << min[0] << " => " << max[0]; + for (int i = 1; i < 4; i++) { + ss << ", " << min[i] << " => " << max[i]; + } + + ss << "]"; + + return ss.str(); + } + + XYZM min; + XYZM max; + + private: + // This works for XY, XYZ, and XYZM + template <typename Coord> + void UpdateInternal(Coord coord) { + static_assert(coord.size() <= 4); + + for (size_t i = 0; i < coord.size(); i++) { + min[i] = std::min(min[i], coord[i]); + max[i] = std::max(max[i], coord[i]); + } + } +}; + +inline bool operator==(const BoundingBox& lhs, const BoundingBox& rhs) { + return lhs.min == rhs.min && lhs.max == rhs.max; +} + +class WKBBuffer; + +/// \brief Accumulate a BoundingBox and geometry types based on zero or more well-known +/// binary blobs +class PARQUET_EXPORT WKBGeometryBounder { + public: + WKBGeometryBounder() = default; + WKBGeometryBounder(const WKBGeometryBounder&) = default; + + /// \brief Accumulate the bounds of a serialized well-known binary geometry + /// + /// Returns SerializationError for any parse errors encountered. Bounds for + /// any encountered coordinates are accumulated and the geometry type of + /// the geometry is added to the internal geometry type list. + /// + /// Note that this method is NOT appropriate for bounding a GEOGRAPHY, + /// whose bounds are not a function purely of the vertices. Geography bounding + /// is not yet implemented. + ::arrow::Status ReadGeometry(const uint8_t* data, int64_t size); + + /// \brief Accumulate the bounds of a previously-calculated BoundingBox + void ReadBox(const BoundingBox& box) { box_.Merge(box); } + + /// \brief Accumulate a previously-calculated list of geometry types + void ReadGeometryTypes(const std::vector<int32_t>& geospatial_types) { + geospatial_types_.insert(geospatial_types.begin(), geospatial_types.end()); + } + + /// \brief Retrieve the accumulated bounds + const BoundingBox& Bounds() const { return box_; } + + /// \brief Retrieve the accumulated geometry types + std::vector<int32_t> GeometryTypes() const { Review Comment: ```suggestion std::vector<int32_t> GeospatialTypes() const { ``` ########## cpp/src/parquet/geometry_statistics.cc: ########## @@ -0,0 +1,291 @@ +// 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. + +#include "parquet/geometry_statistics.h" +#include <memory> + +#include "arrow/array.h" +#include "arrow/type.h" +#include "arrow/util/bit_run_reader.h" +#include "arrow/util/logging.h" +#include "parquet/exception.h" +#include "parquet/geometry_util_internal.h" + +using arrow::util::SafeLoad; + +namespace parquet { + +class GeospatialStatisticsImpl { + public: + GeospatialStatisticsImpl() = default; + GeospatialStatisticsImpl(const GeospatialStatisticsImpl&) = default; + + bool Equals(const GeospatialStatisticsImpl& other) const { + if (is_valid_ != other.is_valid_) { + return false; + } + + if (!is_valid_ && !other.is_valid_) { + return true; + } + + auto geospatial_types = bounder_.GeometryTypes(); + auto other_geospatial_types = other.bounder_.GeometryTypes(); + if (geospatial_types.size() != other_geospatial_types.size()) { + return false; + } + + for (size_t i = 0; i < geospatial_types.size(); i++) { + if (geospatial_types[i] != other_geospatial_types[i]) { + return false; + } + } + + return bounder_.Bounds() == other.bounder_.Bounds(); + } + + void Merge(const GeospatialStatisticsImpl& other) { + is_valid_ = is_valid_ && other.is_valid_; + bounder_.ReadBox(other.bounder_.Bounds()); + bounder_.ReadGeometryTypes(other.bounder_.GeometryTypes()); + } + + void Update(const ByteArray* values, int64_t num_values, int64_t null_count) { + if (!is_valid_) { + return; + } + + for (int64_t i = 0; i < num_values; i++) { + const ByteArray& item = values[i]; + ::arrow::Status status = bounder_.ReadGeometry(item.ptr, item.len); + if (!status.ok()) { + is_valid_ = false; + return; + } + } + } + + void UpdateSpaced(const ByteArray* values, const uint8_t* valid_bits, + int64_t valid_bits_offset, int64_t num_spaced_values, + int64_t num_values, int64_t null_count) { + DCHECK_GT(num_spaced_values, 0); + + if (!is_valid_) { + return; + } + + ::arrow::Status status = ::arrow::internal::VisitSetBitRuns( + valid_bits, valid_bits_offset, num_spaced_values, + [&](int64_t position, int64_t length) { + for (int64_t i = 0; i < length; i++) { + ByteArray item = SafeLoad(values + i + position); + ARROW_RETURN_NOT_OK(bounder_.ReadGeometry(item.ptr, item.len)); + } + + return ::arrow::Status::OK(); + }); + + if (!status.ok()) { + is_valid_ = false; + } + } + + void Update(const ::arrow::Array& values) { + if (!is_valid_) { + return; + } + + // Note that ::arrow::Type::EXTENSION seems to be handled before this is called + switch (values.type_id()) { + case ::arrow::Type::BINARY: + UpdateArrayImpl<::arrow::BinaryArray>(values); + break; + case ::arrow::Type::LARGE_BINARY: + UpdateArrayImpl<::arrow::LargeBinaryArray>(values); + break; + // This does not currently handle run-end encoded, dictionary encodings, or views + default: + throw ParquetException( + "Unsupported Array type in GeospatialStatistics::Update(Array): ", + values.type()->ToString()); + } + } + + void Reset() { + bounder_.Reset(); + is_valid_ = true; + } + + EncodedGeospatialStatistics Encode() const { + if (!is_valid_) { + return {}; + } + + const geometry::BoundingBox::XYZM& mins = bounder_.Bounds().min; + const geometry::BoundingBox::XYZM& maxes = bounder_.Bounds().max; + + EncodedGeospatialStatistics out; + out.geospatial_types = bounder_.GeometryTypes(); + + out.xmin = mins[0]; + out.xmax = maxes[0]; + out.ymin = mins[1]; + out.ymax = maxes[1]; + out.zmin = mins[2]; + out.zmax = maxes[2]; + out.mmin = mins[3]; + out.mmax = maxes[3]; + + return out; + } + + void Update(const EncodedGeospatialStatistics& encoded) { + if (!is_valid_) { + return; + } + + geometry::BoundingBox box; + box.min[0] = encoded.xmin; + box.max[0] = encoded.xmax; + box.min[1] = encoded.ymin; + box.max[1] = encoded.ymax; + + if (encoded.has_z()) { + box.min[2] = encoded.zmin; + box.max[2] = encoded.zmax; + } + + if (encoded.has_m()) { + box.min[3] = encoded.mmin; + box.max[3] = encoded.mmax; + } + + bounder_.ReadBox(box); + bounder_.ReadGeometryTypes(encoded.geospatial_types); + } + + bool is_valid() const { return is_valid_; } + + const std::array<double, 4>& GetMinBounds() const { return bounder_.Bounds().min; } + + const std::array<double, 4>& GetMaxBounds() { return bounder_.Bounds().max; } + + std::vector<int32_t> GetGeometryTypes() const { return bounder_.GeometryTypes(); } + + private: + geometry::WKBGeometryBounder bounder_; + bool is_valid_ = true; + + template <typename ArrayType> + void UpdateArrayImpl(const ::arrow::Array& values) { + const auto& binary_array = static_cast<const ArrayType&>(values); + for (int64_t i = 0; i < binary_array.length(); ++i) { + if (!binary_array.IsNull(i)) { + std::string_view byte_array = binary_array.GetView(i); + ::arrow::Status status = bounder_.ReadGeometry( + reinterpret_cast<const uint8_t*>(byte_array.data()), byte_array.length()); + if (!status.ok()) { + is_valid_ = false; + return; + } + } + } + } +}; + +GeospatialStatistics::GeospatialStatistics() + : impl_(std::make_unique<GeospatialStatisticsImpl>()) {} + +GeospatialStatistics::GeospatialStatistics(std::unique_ptr<GeospatialStatisticsImpl> impl) + : impl_(std::move(impl)) {} + +GeospatialStatistics::GeospatialStatistics(const EncodedGeospatialStatistics& encoded) + : GeospatialStatistics() { + Decode(encoded); +} + +GeospatialStatistics::GeospatialStatistics(GeospatialStatistics&&) = default; + +GeospatialStatistics::~GeospatialStatistics() = default; + +bool GeospatialStatistics::Equals(const GeospatialStatistics& other) const { + return impl_->Equals(*other.impl_); +} + +void GeospatialStatistics::Merge(const GeospatialStatistics& other) { + impl_->Merge(*other.impl_); +} + +void GeospatialStatistics::Update(const ByteArray* values, int64_t num_values, + int64_t null_count) { + impl_->Update(values, num_values, null_count); +} + +void GeospatialStatistics::UpdateSpaced(const ByteArray* values, + const uint8_t* valid_bits, + int64_t valid_bits_offset, + int64_t num_spaced_values, int64_t num_values, + int64_t null_count) { + impl_->UpdateSpaced(values, valid_bits, valid_bits_offset, num_spaced_values, + num_values, null_count); +} + +void GeospatialStatistics::Update(const ::arrow::Array& values) { impl_->Update(values); } + +void GeospatialStatistics::Reset() { impl_->Reset(); } + +bool GeospatialStatistics::is_valid() const { return impl_->is_valid(); } + +EncodedGeospatialStatistics GeospatialStatistics::Encode() const { + return impl_->Encode(); +} + +void GeospatialStatistics::Decode(const EncodedGeospatialStatistics& encoded) { + impl_->Update(encoded); Review Comment: Should we reset it before calling update? ########## cpp/src/parquet/geometry_util_internal.h: ########## @@ -0,0 +1,184 @@ +// 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. + +#pragma once + +#include <algorithm> +#include <limits> +#include <sstream> +#include <string> +#include <unordered_set> + +#include "parquet/platform.h" + +namespace parquet::geometry { + +/// \brief Infinity, used to define bounds of empty bounding boxes +constexpr double kInf = std::numeric_limits<double>::infinity(); + +/// \brief Valid combinations of dimensions allowed by ISO well-known binary +enum class Dimensions { XY = 0, XYZ = 1, XYM = 2, XYZM = 3, MIN = 0, MAX = 3 }; + +/// \brief The supported set of geometry types allowed by ISO well-known binary +enum class GeometryType { + POINT = 1, + LINESTRING = 2, + POLYGON = 3, + MULTIPOINT = 4, + MULTILINESTRING = 5, + MULTIPOLYGON = 6, + GEOMETRYCOLLECTION = 7, + MIN = 1, + MAX = 7 +}; + +/// \brief A collection of intervals representing the encountered ranges of values +/// in each dimension. +struct BoundingBox { + using XY = std::array<double, 2>; + using XYZ = std::array<double, 3>; + using XYM = std::array<double, 3>; + using XYZM = std::array<double, 4>; + + BoundingBox(const XYZM& mins, const XYZM& maxes) : min(mins), max(maxes) {} + BoundingBox() : min{kInf, kInf, kInf, kInf}, max{-kInf, -kInf, -kInf, -kInf} {} + + BoundingBox(const BoundingBox& other) = default; + BoundingBox& operator=(const BoundingBox&) = default; + + /// \brief Update the X and Y bounds to ensure these bounds contain coord + void UpdateXY(const XY& coord) { UpdateInternal(coord); } + + /// \brief Update the X, Y, and Z bounds to ensure these bounds contain coord + void UpdateXYZ(const XYZ& coord) { UpdateInternal(coord); } + + /// \brief Update the X, Y, and M bounds to ensure these bounds contain coord + void UpdateXYM(const XYM& coord) { + min[0] = std::min(min[0], coord[0]); + min[1] = std::min(min[1], coord[1]); + min[3] = std::min(min[3], coord[2]); + max[0] = std::max(max[0], coord[0]); + max[1] = std::max(max[1], coord[1]); + max[3] = std::max(max[3], coord[2]); + } + + /// \brief Update the X, Y, Z, and M bounds to ensure these bounds contain coord + void UpdateXYZM(const XYZM& coord) { UpdateInternal(coord); } + + /// \brief Reset these bounds to an empty state such that they contain no coordinates + void Reset() { + for (int i = 0; i < 4; i++) { + min[i] = kInf; + max[i] = -kInf; + } + } + + /// \brief Update these bounds such they also contain other + void Merge(const BoundingBox& other) { + for (int i = 0; i < 4; i++) { + min[i] = std::min(min[i], other.min[i]); + max[i] = std::max(max[i], other.max[i]); + } + } + + std::string ToString() const { + std::stringstream ss; + ss << "BoundingBox [" << min[0] << " => " << max[0]; + for (int i = 1; i < 4; i++) { + ss << ", " << min[i] << " => " << max[i]; + } + + ss << "]"; + + return ss.str(); + } + + XYZM min; + XYZM max; + + private: + // This works for XY, XYZ, and XYZM + template <typename Coord> + void UpdateInternal(Coord coord) { + static_assert(coord.size() <= 4); + + for (size_t i = 0; i < coord.size(); i++) { + min[i] = std::min(min[i], coord[i]); + max[i] = std::max(max[i], coord[i]); + } + } +}; + +inline bool operator==(const BoundingBox& lhs, const BoundingBox& rhs) { + return lhs.min == rhs.min && lhs.max == rhs.max; +} + +class WKBBuffer; + +/// \brief Accumulate a BoundingBox and geometry types based on zero or more well-known +/// binary blobs +class PARQUET_EXPORT WKBGeometryBounder { Review Comment: Is it able to deal with `geography` type or a separate bounder is required? ########## cpp/src/parquet/geometry_util_internal.cc: ########## @@ -0,0 +1,234 @@ +// 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. + +#include "parquet/geometry_util_internal.h" + +#include "arrow/result.h" +#include "arrow/util/endian.h" +#include "arrow/util/macros.h" +#include "arrow/util/ubsan.h" + +namespace parquet::geometry { + +/// \brief Object to keep track of the low-level consumption of a well-known binary +/// geometry +/// +/// Briefly, ISO well-known binary supported by the Parquet spec is an endian byte +/// (0x01 or 0x00), followed by geometry type + dimensions encoded as a (uint32_t), +/// followed by geometry-specific data. Coordinate sequences are represented by a +/// uint32_t (the number of coordinates) plus a sequence of doubles (number of coordinates +/// multiplied by the number of dimensions). +class WKBBuffer { + public: + WKBBuffer() : data_(NULLPTR), size_(0) {} + WKBBuffer(const uint8_t* data, int64_t size) : data_(data), size_(size) {} Review Comment: Should we use `span` instead? ########## cpp/src/parquet/geometry_util_internal.h: ########## @@ -0,0 +1,184 @@ +// 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. + +#pragma once + +#include <algorithm> +#include <limits> +#include <sstream> +#include <string> +#include <unordered_set> + +#include "parquet/platform.h" + +namespace parquet::geometry { + +/// \brief Infinity, used to define bounds of empty bounding boxes +constexpr double kInf = std::numeric_limits<double>::infinity(); + +/// \brief Valid combinations of dimensions allowed by ISO well-known binary +enum class Dimensions { XY = 0, XYZ = 1, XYM = 2, XYZM = 3, MIN = 0, MAX = 3 }; + +/// \brief The supported set of geometry types allowed by ISO well-known binary +enum class GeometryType { Review Comment: ```suggestion enum class GeospatialType { ``` Though I think `GeometryType` sounds better :) ########## cpp/src/parquet/geometry_util_internal.h: ########## @@ -0,0 +1,184 @@ +// 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. + +#pragma once + +#include <algorithm> +#include <limits> +#include <sstream> +#include <string> +#include <unordered_set> + +#include "parquet/platform.h" + +namespace parquet::geometry { + +/// \brief Infinity, used to define bounds of empty bounding boxes +constexpr double kInf = std::numeric_limits<double>::infinity(); + +/// \brief Valid combinations of dimensions allowed by ISO well-known binary +enum class Dimensions { XY = 0, XYZ = 1, XYM = 2, XYZM = 3, MIN = 0, MAX = 3 }; + +/// \brief The supported set of geometry types allowed by ISO well-known binary +enum class GeometryType { + POINT = 1, + LINESTRING = 2, + POLYGON = 3, + MULTIPOINT = 4, + MULTILINESTRING = 5, + MULTIPOLYGON = 6, + GEOMETRYCOLLECTION = 7, + MIN = 1, + MAX = 7 +}; + +/// \brief A collection of intervals representing the encountered ranges of values +/// in each dimension. +struct BoundingBox { Review Comment: This only applies to `geometry` type, right? For `geography` type, we need to deal with wraparound and edges? ########## cpp/src/parquet/geometry_statistics.cc: ########## @@ -0,0 +1,291 @@ +// 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. + +#include "parquet/geometry_statistics.h" +#include <memory> + +#include "arrow/array.h" +#include "arrow/type.h" +#include "arrow/util/bit_run_reader.h" +#include "arrow/util/logging.h" +#include "parquet/exception.h" +#include "parquet/geometry_util_internal.h" + +using arrow::util::SafeLoad; + +namespace parquet { + +class GeospatialStatisticsImpl { + public: + GeospatialStatisticsImpl() = default; + GeospatialStatisticsImpl(const GeospatialStatisticsImpl&) = default; + + bool Equals(const GeospatialStatisticsImpl& other) const { + if (is_valid_ != other.is_valid_) { + return false; + } + + if (!is_valid_ && !other.is_valid_) { + return true; + } + + auto geospatial_types = bounder_.GeometryTypes(); + auto other_geospatial_types = other.bounder_.GeometryTypes(); + if (geospatial_types.size() != other_geospatial_types.size()) { + return false; + } + + for (size_t i = 0; i < geospatial_types.size(); i++) { + if (geospatial_types[i] != other_geospatial_types[i]) { + return false; + } + } Review Comment: ```suggestion if (bounder_.GeometryTypes() != other.bounder_.GeometryTypes()) { return false; } ``` I think this should work -- 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]
