[
https://issues.apache.org/jira/browse/HIVE-30292?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dmitriy Fingerman updated HIVE-30292:
-------------------------------------
Description:
Follow-up to HIVE-30240 (basic GEOMETRY data type support).
h3. Problem
Iceberg stores a per-file bounding box for each GEOMETRY column (lower_bounds /
upper_bounds).
Hive already writes these bounds; they can be seen in the files metadata table:
{code:sql}
SELECT readable_metrics.geom.lower_bound, readable_metrics.geom.upper_bound
FROM db.places.files;
{code}
Hive doesn't use them, so a spatial filter reads every data file:
{code:sql}
SELECT * FROM places
WHERE ST_Intersects(ST_GeomFromWKB(CAST(geom AS BINARY)),
ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'));
{code}
h3. Proposed design
Push spatial filters on GEOMETRY columns down to Iceberg scan planning, so that
files whose bounding
box doesn't intersect the query window are skipped.
* *Recognize the predicate:* ST_Intersects(<geometry column>, <constant
geometry>), in either argument order.
** For now this means the ST_GeomFromWKB(CAST(col AS BINARY)) wrapper.
** After the ESRI-functions follow-up, also the direct form ST_Intersects(col,
...).
** Candidates for later: ST_Contains, ST_Within and ST_EnvIntersects. The
column side must intersect the window for all of them, so they can be pruned
with the same bounding-box test.
* *Build the query window:* compute the constant's bounding box at compile time.
* *Convert the filter:* translate it to Iceberg's spatial predicate
(Expressions.stIntersects(column, BoundingBox)) in the Iceberg filter
conversion.
** Iceberg's existing filter path goes through SearchArgument, which can't
express this, so it needs a separate conversion path.
* *Keep the original filter:* pruning only skips whole files, so the exact
ST_Intersects must still run on the remaining rows.
* *Pass through safely:* AND/OR/NOT should combine correctly. Anything that
can't be converted is simply not pushed down.
h3. Dependencies
* Iceberg spatial predicates in the public expression API:
** apache/iceberg#14101 (ST_INTERSECTS / ST_DISJOINT)
** apache/iceberg#17175 (pruning in InclusiveMetricsEvaluator)
* Neither is available in Iceberg 1.12.0, which Hive uses today. This ticket is
blocked until a release includes them.
h3. Scope notes
* *CRS:* the query window is assumed to be in the column's CRS. ST_GeomFromText
has no CRS, and Hive does no reprojection.
* *GEOGRAPHY:* out of scope until that type exists. Its bounding boxes can wrap
around the antimeridian; Iceberg's evaluator already handles that.
h3. Testing
* Unit tests for the Hive-expression-to-Iceberg-expression conversion:
supported shapes, argument order, nested AND/OR/NOT, and filters that must not
be converted.
* A q-file test with several data files whose bounding boxes don't overlap,
checking:
** query results are unchanged with pushdown on and off;
** non-matching files are skipped, through EXPLAIN or scan task counts.
was:
Follow-up to HIVE-30240 (basic GEOMETRY data type support).
h3. Problem
Iceberg stores a per-file bounding box for each GEOMETRY column (lower_bounds /
upper_bounds).
Hive already writes these bounds; they can be seen in the files metadata table:
{code:sql}
SELECT readable_metrics.geom.lower_bound, readable_metrics.geom.upper_bound
FROM db.places.files;
{code}
Hive doesn't use them, so a spatial filter reads every data file:
{code:sql}
SELECT * FROM places
WHERE ST_Intersects(ST_GeomFromWKB(CAST(geom AS BINARY)),
ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'));
{code}
h3. Proposal
Push spatial filters on GEOMETRY columns down to Iceberg scan planning, so that
files whose bounding
box doesn't intersect the query window are skipped.
* *Recognize the predicate:* ST_Intersects(<geometry column>, <constant
geometry>), in either argument order.
** For now this means the ST_GeomFromWKB(CAST(col AS BINARY)) wrapper.
** After the ESRI-functions follow-up, also the direct form ST_Intersects(col,
...).
** Candidates for later: ST_Contains, ST_Within and ST_EnvIntersects. The
column side must intersect the window for all of them, so they can be pruned
with the same bounding-box test.
* *Build the query window:* compute the constant's bounding box at compile time.
* *Convert the filter:* translate it to Iceberg's spatial predicate
(Expressions.stIntersects(column, BoundingBox)) in the Iceberg filter
conversion.
** Iceberg's existing filter path goes through SearchArgument, which can't
express this, so it needs a separate conversion path.
* *Keep the original filter:* pruning only skips whole files, so the exact
ST_Intersects must still run on the remaining rows.
* *Pass through safely:* AND/OR/NOT should combine correctly. Anything that
can't be converted is simply not pushed down.
h3. Dependencies
* Iceberg spatial predicates in the public expression API:
** apache/iceberg#14101 (ST_INTERSECTS / ST_DISJOINT)
** apache/iceberg#17175 (pruning in InclusiveMetricsEvaluator)
* Neither is available in Iceberg 1.12.0, which Hive uses today. This ticket is
blocked until a release includes them.
* Optional: native GEOMETRY support in the ESRI ST_* functions (separate
follow-up), for the direct ST_Intersects(col, ...) form.
h3. Possible interim option
Iceberg 1.12.0 already exposes BoundingBox and
GeospatialPredicateEvaluators.intersects().
Hive could filter planned file scan tasks against the query window itself,
without waiting for the
expression API. This would be Hive-only code that becomes redundant once
Iceberg ships the
predicate, so it should be decided whether it's worth it.
h3. Scope notes
* *CRS:* the query window is assumed to be in the column's CRS. ST_GeomFromText
has no CRS, and Hive does no reprojection.
* *GEOGRAPHY:* out of scope until that type exists. Its bounding boxes can wrap
around the antimeridian; Iceberg's evaluator already handles that.
h3. Testing
* Unit tests for the Hive-expression-to-Iceberg-expression conversion:
supported shapes, argument order, nested AND/OR/NOT, and filters that must not
be converted.
* A q-file test with several data files whose bounding boxes don't overlap,
checking:
** query results are unchanged with pushdown on and off;
** non-matching files are skipped, through EXPLAIN or scan task counts.
> Iceberg: Spatial predicate pushdown for GEOMETRY columns
> --------------------------------------------------------
>
> Key: HIVE-30292
> URL: https://issues.apache.org/jira/browse/HIVE-30292
> Project: Hive
> Issue Type: New Feature
> Reporter: Dmitriy Fingerman
> Assignee: Dmitriy Fingerman
> Priority: Major
>
> Follow-up to HIVE-30240 (basic GEOMETRY data type support).
> h3. Problem
> Iceberg stores a per-file bounding box for each GEOMETRY column (lower_bounds
> / upper_bounds).
> Hive already writes these bounds; they can be seen in the files metadata
> table:
> {code:sql}
> SELECT readable_metrics.geom.lower_bound, readable_metrics.geom.upper_bound
> FROM db.places.files;
> {code}
> Hive doesn't use them, so a spatial filter reads every data file:
> {code:sql}
> SELECT * FROM places
> WHERE ST_Intersects(ST_GeomFromWKB(CAST(geom AS BINARY)),
> ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0
> 0))'));
> {code}
> h3. Proposed design
> Push spatial filters on GEOMETRY columns down to Iceberg scan planning, so
> that files whose bounding
> box doesn't intersect the query window are skipped.
> * *Recognize the predicate:* ST_Intersects(<geometry column>, <constant
> geometry>), in either argument order.
> ** For now this means the ST_GeomFromWKB(CAST(col AS BINARY)) wrapper.
> ** After the ESRI-functions follow-up, also the direct form
> ST_Intersects(col, ...).
> ** Candidates for later: ST_Contains, ST_Within and ST_EnvIntersects. The
> column side must intersect the window for all of them, so they can be pruned
> with the same bounding-box test.
> * *Build the query window:* compute the constant's bounding box at compile
> time.
> * *Convert the filter:* translate it to Iceberg's spatial predicate
> (Expressions.stIntersects(column, BoundingBox)) in the Iceberg filter
> conversion.
> ** Iceberg's existing filter path goes through SearchArgument, which can't
> express this, so it needs a separate conversion path.
> * *Keep the original filter:* pruning only skips whole files, so the exact
> ST_Intersects must still run on the remaining rows.
> * *Pass through safely:* AND/OR/NOT should combine correctly. Anything that
> can't be converted is simply not pushed down.
> h3. Dependencies
> * Iceberg spatial predicates in the public expression API:
> ** apache/iceberg#14101 (ST_INTERSECTS / ST_DISJOINT)
> ** apache/iceberg#17175 (pruning in InclusiveMetricsEvaluator)
> * Neither is available in Iceberg 1.12.0, which Hive uses today. This ticket
> is blocked until a release includes them.
> h3. Scope notes
> * *CRS:* the query window is assumed to be in the column's CRS.
> ST_GeomFromText has no CRS, and Hive does no reprojection.
> * *GEOGRAPHY:* out of scope until that type exists. Its bounding boxes can
> wrap around the antimeridian; Iceberg's evaluator already handles that.
> h3. Testing
> * Unit tests for the Hive-expression-to-Iceberg-expression conversion:
> supported shapes, argument order, nested AND/OR/NOT, and filters that must
> not be converted.
> * A q-file test with several data files whose bounding boxes don't overlap,
> checking:
> ** query results are unchanged with pushdown on and off;
> ** non-matching files are skipped, through EXPLAIN or scan task counts.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)