Hello Jason Fehr, Balazs Hevele, Peter Rozsa, Impala Public Jenkins,

I'd like you to reexamine a change. Please visit

    https://gerrit.cloudera.org/24553

to look at the new patch set (#20).

Change subject: IMPALA-15163: Add geometry bounding box predicate pushdown for 
Parquet
......................................................................

IMPALA-15163: Add geometry bounding box predicate pushdown for Parquet

Implement Parquet row group skipping based on GEOMETRY column
bounding box statistics. This commit stays entirely within Parquet
metadata, writing the bounding box to Iceberg is left to IMPALA-15883.

Writer side: the Parquet table writer tracks the envelope of all
geometries written to each column chunk and stores it in
ColumnMetaData.geospatial_statistics.bbox, holding xmin/xmax/ymin/ymax
as doubles (see parquet-format Geospatial.md). It also writes the WKB
type codes of the values as geospatial_types. The generic Statistics
min/max are left unset, as geometry has no sort order and the spec
leaves them undefined for it; only null_count is written there.

The box has to cover every value in the column chunk, or a reader
pruning on it would drop matching rows, so collection fails safe: if
any non-NULL geometry cannot be bounded, no geospatial statistics
(neither box nor types) are written for that row group at all. The
writer relies on ComputeWkbBBox() reporting EMPTY and MALFORMED
separately (IMPALA-15878), as the two need opposite handling - an empty
geometry has no extent and adds nothing to the box (but its type is
recorded), while an unparseable value abandons the statistics. This also
covers values Impala can store but not bound, since ParseWkbHeader()
accepts only the six 2D WKB types: the Z/M/ZM variants (st_pointz()
writes WKB type 1001) and GEOMETRYCOLLECTION. Bounding those rather
than skipping them is left to a follow-up; IMPALA-15168 tracks support
for non-2D geometries.

NaN coordinates are skipped per dimension, as the Parquet spec requires
(Arrow's parquet-cpp does the same), so the box is only written if both
X and Y got a value. Impala's own functions never produce half-NaN
values like POINT (1 NaN).

Reader side: HdfsScanNode.tryComputeGeoBBoxPredicate() recognizes
st_envintersects(CONST, geom_col) and the relations that imply it
(st_intersects, st_contains, ... but not st_disjoint), computes the
constant geometry's envelope via ESRI, and emits TGeoBBoxPredicate to
the backend. EvaluateGeoBBoxPredicates() in the Parquet scanner checks
bbox overlap against the row group's geospatial statistics and
increments NumStatsFilteredRowGroups on miss. The check is exact, so it
ignores the tolerance of the ESRI relations, as the planned C++
implementation of the relations will not have it either
(https://gerrit.cloudera.org/#/c/24540/).

Iceberg does not support predicate pushdown for geometry types yet
(see https://github.com/apache/iceberg/pull/14101), so the filtering
has to happen at the Parquet level. Once the bounds are written to
Iceberg's DataFile metadata (IMPALA-15883), files could be pruned
during planning as well.

The geospatial rewrite rules NormalizeGeospatialRelations and
PointEnvIntersects are now also enabled in the default WKB_EXPERIMENTAL
mode, not only in HIVE_ESRI, and PointEnvIntersects also handles
relations like st_intersects(CONST, st_point(x, y)).
NormalizeGeospatialRelations now also changes st_within(a, CONST) to
st_contains(CONST, a), so the constant is first in all relations.
AddEnvIntersects is not enabled in WKB mode, as it would make queries
slower: st_envintersects is a Java function there, so it would be an
extra call per row. This also uncovered a precondition in
PointEnvIntersectsRule that only accepted BINARY constants and would
have failed on GEOMETRY ones.

Testing:
- create table with Impala and verify that bbox is written and used
- check relations that do pushdown (st_envintersects, etc..) in both
  argument orders and st_disjoint that must not do pushdown
- planner test of the rewrites in WKB mode, HIVE_ESRI planner test
  unchanged
- unit tests of the bbox and type collection, including half-NaN
  coordinates that SQL cannot produce
- verify that geospatial_types is written
- verify that a row group holding only empty/NULL geometries does
  not get a bounding box, but gets geospatial_types
- verify that a row group holding a value that cannot be bounded (a Z
  point) gets no geospatial statistics at all, and that the row is still
  returned by a query whose window covers only that value
- no interop tests yet, would need to find an engine that writes
  statistics

Assisted-by: Claude Opus 5 (Claude Code)
Change-Id: I7265a00caba698a122bc15ecb433c507f36d166f
---
M be/src/exec/parquet/CMakeLists.txt
M be/src/exec/parquet/hdfs-parquet-scanner.cc
M be/src/exec/parquet/hdfs-parquet-scanner.h
M be/src/exec/parquet/hdfs-parquet-table-writer.cc
M be/src/exec/parquet/hdfs-parquet-table-writer.h
A be/src/exec/parquet/parquet-geo-stats-test.cc
A be/src/exec/parquet/parquet-geo-stats.cc
A be/src/exec/parquet/parquet-geo-stats.h
M common/thrift/PlanNodes.thrift
M fe/src/main/java/org/apache/impala/analysis/Analyzer.java
M fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java
M fe/src/main/java/org/apache/impala/rewrite/AddEnvIntersectsRule.java
M 
fe/src/main/java/org/apache/impala/rewrite/NormalizeGeospatialRelationsRule.java
M fe/src/main/java/org/apache/impala/rewrite/PointEnvIntersectsRule.java
M 
java/hive-geospatial-functions/src/main/java/org/apache/impala/hive/geospatial/esri/GeometryUtils.java
M 
testdata/workloads/functional-query/queries/QueryTest/geospatial-esri-planner.test
A 
testdata/workloads/functional-query/queries/QueryTest/geospatial-wkb-planner.test
A 
testdata/workloads/functional-query/queries/QueryTest/iceberg-geometry-bbox.test
M tests/query_test/test_geospatial_functions.py
19 files changed, 1,195 insertions(+), 39 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/53/24553/20
--
To view, visit https://gerrit.cloudera.org/24553
To unsubscribe, visit https://gerrit.cloudera.org/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I7265a00caba698a122bc15ecb433c507f36d166f
Gerrit-Change-Number: 24553
Gerrit-PatchSet: 20
Gerrit-Owner: Csaba Ringhofer <[email protected]>
Gerrit-Reviewer: Balazs Hevele <[email protected]>
Gerrit-Reviewer: Csaba Ringhofer <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Jason Fehr <[email protected]>
Gerrit-Reviewer: Peter Rozsa <[email protected]>

Reply via email to