zeroshade commented on code in PR #1504:
URL: https://github.com/apache/arrow-go/pull/1504#discussion_r4530993783


##########
parquet/internal/geospatial/bounder.go:
##########
@@ -0,0 +1,287 @@
+// 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.
+
+// Package geospatial computes the bounding box and geometry type set of
+// WKB-encoded geometries for Parquet geospatial statistics. It has no
+// dependency on any geometry library: it only walks WKB coordinates.
+package geospatial
+
+import (
+       "encoding/binary"
+       "math"
+       "slices"
+)
+
+// Coordinate dimensions, in the order they are indexed in a Bounder.
+const (
+       DimX = iota
+       DimY
+       DimZ
+       DimM
+       numDims
+)
+
+const (
+       ewkbZ    = 0x80000000
+       ewkbM    = 0x40000000
+       ewkbSRID = 0x20000000
+
+       maxNesting = 64
+)
+
+// Bounder accumulates the per-dimension min/max and the set of ISO WKB 
geometry
+// type codes of the geometries it is given. NaN ordinates are ignored, so they
+// never appear in the bounds. If any value is not valid WKB the Bounder 
becomes
+// invalid and its results must not be written.
+//
+// The zero value is not usable, use NewBounder.
+type Bounder struct {
+       min, max [numDims]float64
+       types    map[int32]struct{}
+       invalid  bool
+}
+
+// NewBounder returns an empty, valid Bounder.
+func NewBounder() *Bounder {
+       b := &Bounder{}
+       b.Reset()
+       return b
+}
+
+// NewBounderFrom builds a Bounder from previously computed results, such as
+// those read back from a file footer. A dimension is considered present
+// when min <= max.
+func NewBounderFrom(min, max [4]float64, types []int32) *Bounder {
+       b := &Bounder{min: min, max: max, types: make(map[int32]struct{}, 
len(types))}
+       for _, t := range types {
+               b.types[t] = struct{}{}
+       }
+       return b
+}
+
+// Reset clears all accumulated state and makes the Bounder valid again.
+func (b *Bounder) Reset() {
+       for i := range b.min {
+               b.min[i], b.max[i] = math.Inf(1), math.Inf(-1)
+       }
+       b.types = make(map[int32]struct{})
+       b.invalid = false
+}
+
+// Invalidate marks the results as unusable, for example when values were
+// written that cannot be inspected.
+func (b *Bounder) Invalidate() { b.invalid = true }
+
+// Valid reports whether every value seen so far was valid WKB.
+func (b *Bounder) Valid() bool { return !b.invalid }
+
+// HasDim reports whether at least one coordinate was seen in dimension dim.
+func (b *Bounder) HasDim(dim int) bool { return b.min[dim] <= b.max[dim] }
+
+// Min returns the minimum for dim, only meaningful if HasDim(dim).
+func (b *Bounder) Min(dim int) float64 { return b.min[dim] }
+
+// Max returns the maximum for dim, only meaningful if HasDim(dim).
+func (b *Bounder) Max(dim int) float64 { return b.max[dim] }
+
+// Types returns the sorted ISO WKB geometry type codes seen
+// (e.g. 1 = Point, 1001 = Point Z, 2003 = LineString M, 3001 ...).
+func (b *Bounder) Types() []int32 {
+       out := make([]int32, 0, len(b.types))
+       for t := range b.types {
+               out = append(out, t)
+       }
+       slices.Sort(out)
+       return out
+}
+
+// Empty reports whether no geometry has been seen at all.
+func (b *Bounder) Empty() bool { return len(b.types) == 0 }
+
+// Merge folds other into b.
+func (b *Bounder) Merge(other *Bounder) {

Review Comment:
   nit: with `GeoStatistics.Merge` gone, nothing outside `TestBounderMerge` 
calls this. It's an internal package, so it's harmless, but this and its test 
could go until file-level aggregation needs them.



-- 
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]

Reply via email to