-
Notifications
You must be signed in to change notification settings - Fork 759
[GH-2938] Push down ST_BoxIntersects / ST_BoxContains via Parquet row-group statistics #2946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jiayuasu
merged 5 commits into
apache:master
from
jiayuasu:feature/box2d-filter-pushdown
May 13, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
793d640
[GH-2938] Push down ST_BoxIntersects/ST_BoxContains to GeoParquet bbo…
jiayuasu 23829ab
Address review on GH-2938 Box2D filter pushdown
jiayuasu 3c23666
Make Box2D filter pushdown opt-in (default false)
jiayuasu d2d5644
Push down Box2D predicates via Parquet row-group statistics
jiayuasu 0d69d50
Address Copilot review on Box2D row-group pushdown
jiayuasu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| */ | ||
| package org.apache.spark.sql.sedona_sql.optimization | ||
|
|
||
| import org.apache.sedona.common.geometryObjects.Box2D | ||
| import org.apache.sedona.common.sphere.Haversine | ||
| import org.apache.sedona.core.spatialOperator.SpatialPredicate | ||
| import org.apache.sedona.sql.utils.GeometrySerializer | ||
|
|
@@ -42,10 +43,13 @@ import org.apache.spark.sql.execution.datasources.PushableColumnBase | |
| import org.apache.spark.sql.execution.datasources.geoparquet.GeoParquetFileFormatBase | ||
| import org.apache.spark.sql.execution.datasources.geoparquet.GeoParquetSpatialFilter | ||
| import org.apache.spark.sql.execution.datasources.geoparquet.GeoParquetSpatialFilter.AndFilter | ||
| import org.apache.spark.sql.execution.datasources.geoparquet.GeoParquetSpatialFilter.Box2DLeafFilter | ||
| import org.apache.spark.sql.execution.datasources.geoparquet.GeoParquetSpatialFilter.Box2DPredicateKind | ||
| import org.apache.spark.sql.execution.datasources.geoparquet.GeoParquetSpatialFilter.LeafFilter | ||
| import org.apache.spark.sql.execution.datasources.geoparquet.GeoParquetSpatialFilter.OrFilter | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.sedona_sql.UDT.GeometryUDT | ||
| import org.apache.spark.sql.sedona_sql.expressions.{ST_AsEWKT, ST_Buffer, ST_Contains, ST_CoveredBy, ST_Covers, ST_Crosses, ST_DWithin, ST_Distance, ST_DistanceSphere, ST_DistanceSpheroid, ST_Equals, ST_Intersects, ST_OrderingEquals, ST_Overlaps, ST_Touches, ST_Within} | ||
| import org.apache.spark.sql.sedona_sql.expressions.{ST_AsEWKT, ST_BoxContains, ST_BoxIntersects, ST_Buffer, ST_Contains, ST_CoveredBy, ST_Covers, ST_Crosses, ST_DWithin, ST_Distance, ST_DistanceSphere, ST_DistanceSpheroid, ST_Equals, ST_Intersects, ST_OrderingEquals, ST_Overlaps, ST_Touches, ST_Within} | ||
| import org.apache.spark.sql.sedona_sql.optimization.ExpressionUtils.splitConjunctivePredicates | ||
| import org.apache.spark.sql.types.DoubleType | ||
| import org.locationtech.jts.geom.Geometry | ||
|
|
@@ -144,6 +148,24 @@ class SpatialFilterPushDownForGeoParquet(sparkSession: SparkSession) extends Rul | |
| SpatialPredicate.INTERSECTS, | ||
| GeometryUDT.deserialize(value)) | ||
|
|
||
| // Box2D predicates push down as Parquet row-group filters on the Box2D column's underlying | ||
| // (xmin, ymin, xmax, ymax) double leaves. Pruning is done by Parquet's stats-based skipping | ||
| // against the column's recorded min/max, which is sound regardless of how the writer chose | ||
| // the per-row Box2D values. | ||
| case ST_BoxIntersects(_) => | ||
| // Intersects is symmetric — both argument orders produce the same predicate. | ||
|
Comment on lines
+151
to
+156
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR title and body were updated after this review fired — the description no longer references the removed opt-in conf or geometry-bbox metadata pruning, and now documents the Parquet row-group statistics path that is actually implemented. |
||
| for { | ||
| (name, value) <- resolveNameAndLiteral(predicate.children, pushableColumn) | ||
| queryBox <- extractBox2DLiteral(value) | ||
| } yield Box2DLeafFilter(unquote(name), Box2DPredicateKind.Intersects, queryBox) | ||
|
|
||
| case ST_BoxContains(Seq(pushableColumn(name), Literal(v, _))) => | ||
| extractBox2DLiteral(v).map(qb => | ||
| Box2DLeafFilter(unquote(name), Box2DPredicateKind.ColumnContainsLiteral, qb)) | ||
| case ST_BoxContains(Seq(Literal(v, _), pushableColumn(name))) => | ||
| extractBox2DLiteral(v).map(qb => | ||
| Box2DLeafFilter(unquote(name), Box2DPredicateKind.LiteralContainsColumn, qb)) | ||
|
|
||
| case LessThan(ST_Distance(distArgs), Literal(d, DoubleType)) => | ||
| for ((name, value) <- resolveNameAndLiteral(distArgs, pushableColumn)) | ||
| yield distanceFilter(name, GeometryUDT.deserialize(value), d.asInstanceOf[Double]) | ||
|
|
@@ -256,6 +278,24 @@ class SpatialFilterPushDownForGeoParquet(sparkSession: SparkSession) extends Rul | |
| parseColumnPath(name).mkString(".") | ||
| } | ||
|
|
||
| /** | ||
| * Extract a [[Box2D]] from a Catalyst literal value. Box2DUDT serializes to an InternalRow of | ||
| * four doubles; if the value is something else, the predicate is not pushable. Inverted bounds | ||
| * (xmin>xmax or ymin>ymax) are rejected here so the predicate falls back to runtime evaluation | ||
| * and surfaces the expected IllegalArgumentException — pushing them through Parquet would | ||
| * silently prune all matching rows before the throw fires. | ||
| */ | ||
| private def extractBox2DLiteral(value: Any): Option[Box2D] = value match { | ||
| case row: InternalRow if row.numFields == 4 => | ||
| val xmin = row.getDouble(0) | ||
| val ymin = row.getDouble(1) | ||
| val xmax = row.getDouble(2) | ||
| val ymax = row.getDouble(3) | ||
| if (xmin > xmax || ymin > ymax) None | ||
| else Some(new Box2D(xmin, ymin, xmax, ymax)) | ||
| case _ => None | ||
| } | ||
|
|
||
| private def resolveNameAndLiteral( | ||
| expressions: Seq[Expression], | ||
| pushableColumn: PushableColumnBase): Option[(String, Any)] = { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0d69d50 — gated the spatial Parquet predicate on enableParquetFilterPushDown, so disabling spark.sql.parquet.filterPushdown also disables Sedona-injected row-group predicates.