paleolimbot commented on code in PR #45459: URL: https://github.com/apache/arrow/pull/45459#discussion_r1970039006
########## 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()) { Review Comment: We could go either way on that...I thought it might be annoying to fail for the case of WKB that we fail to parse, which at the moment just results in missing statistics for that row group. I may have missed it, but I couldn't find a place where we validate UUIDs or JSON (on the other hand, we don't generate statistics for those I don't think). I'm happy to do either 🙂 -- 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]
