[
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
When Iceberg writes a data file, it records a bounding box for each GEOMETRY
column: the smallest
rectangle containing all values of that column in the file. These are stored in
the file's
lower_bounds / upper_bounds. Hive already writes them, and 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 these bounds when reading. A query with a spatial filter reads
every data file,
even files whose data is far away from the queried area:
{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
Pass spatial filters to Iceberg, so it can skip files whose bounding box
doesn't overlap the queried
area (the "query window").
Filters to support:
* ST_Intersects between a GEOMETRY column and a constant geometry, with the
arguments in either order.
* The ST_* functions don't accept GEOMETRY yet, so today the column appears as
ST_GeomFromWKB(CAST(col AS BINARY)). This form should be recognized first.
Once the ST_* functions
support GEOMETRY directly (separate follow-up), ST_Intersects(col, window)
should be recognized too.
* ST_Contains, ST_Within and ST_EnvIntersects can be added later in the same
way. Each of them can only
be true for rows that intersect the window, so the same file skipping applies.
How it works:
* The query window is a constant, so Hive computes its bounding box once, at
compile time.
* Hive converts the filter into Iceberg's spatial predicate,
Expressions.stIntersects(column, boundingBox).
During scan planning, Iceberg compares this box with each file's bounding box
and skips files where
the two don't overlap.
* Hive passes filters to Iceberg today through SearchArgument, which only
supports simple comparisons
(=, <, IN, IS NULL, ...) and can't express a function call. Spatial filters
need a separate conversion.
* Hive still evaluates the original ST_Intersects on every row it reads. A file
that isn't skipped can
still contain rows that don't match. Pushdown only makes the query faster;
the results stay the same.
Combining with other conditions:
* AND: push down the parts that can be converted.
* OR: push down only if every branch can be converted. Otherwise a file could
be skipped even though
another branch matches rows in it.
* NOT: don't push down. A bounding box can prove that a file has no rows in the
window, but not that all
of its rows are in the window, so NOT ST_Intersects(...) can't be used to
skip files.
* Anything that can't be converted isn't pushed down. The query still works,
just without file skipping.
h3. Dependencies
This needs spatial predicates in Iceberg's public expression API, which Iceberg
1.12.0 (used by Hive
today) doesn't have. This ticket is blocked until an Iceberg release includes
them:
* apache/iceberg#14101: adds the ST_INTERSECTS / ST_DISJOINT predicates.
* apache/iceberg#17175: uses them to skip files during scan planning
(InclusiveMetricsEvaluator).
h3. Out of scope
* Coordinate systems (CRS): the query window's coordinates are compared with
the column's bounding
boxes as plain numbers. For example, if the column is GEOMETRY('EPSG:3857'),
whose coordinates are
in metres, the window must also be given in EPSG:3857 metres, not in
longitude/latitude degrees.
Hive doesn't check this and doesn't convert between coordinate systems. This
is the same behavior
as evaluating ST_Intersects without pushdown, so pushdown doesn't change
query results.
* GEOGRAPHY: not covered until that type is added. Its bounding boxes can cross
the antimeridian, which
Iceberg's bounding-box check already handles.
h3. Testing
* Unit tests for converting Hive filters to Iceberg expressions: supported
filters, both argument orders,
combinations with 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 that:
** results are the same with pushdown on and off;
** files outside the query window are skipped (checked via EXPLAIN or the
number of scan tasks).
was:
Follow-up to HIVE-30240 (basic GEOMETRY data type support).
h3. Problem
When Iceberg writes a data file, it records a bounding box for each GEOMETRY
column: the smallest
rectangle containing all values of that column in the file. These are stored in
the file's
lower_bounds / upper_bounds. Hive already writes them, and 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 these bounds when reading. A query with a spatial filter reads
every data file,
even files whose data is far away from the queried area:
{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
Pass spatial filters to Iceberg, so it can skip files whose bounding box
doesn't overlap the queried
area (the "query window").
Filters to support:
* ST_Intersects between a GEOMETRY column and a constant geometry, with the
arguments in either order.
* The ST_* functions don't accept GEOMETRY yet, so today the column appears as
ST_GeomFromWKB(CAST(col AS BINARY)). This form should be recognized first.
Once the ST_* functions
support GEOMETRY directly (separate follow-up), ST_Intersects(col, window)
should be recognized too.
* ST_Contains, ST_Within and ST_EnvIntersects can be added later in the same
way. Each of them can only
be true for rows that intersect the window, so the same file skipping applies.
How it works:
* The query window is a constant, so Hive computes its bounding box once, at
compile time.
* Hive converts the filter into Iceberg's spatial predicate,
Expressions.stIntersects(column, boundingBox).
During scan planning, Iceberg compares this box with each file's bounding box
and skips files where
the two don't overlap.
* Hive passes filters to Iceberg today through SearchArgument, which only
supports simple comparisons
(=, <, IN, IS NULL, ...) and can't express a function call. Spatial filters
need a separate conversion.
* Hive still evaluates the original ST_Intersects on every row it reads. A file
that isn't skipped can
still contain rows that don't match. Pushdown only makes the query faster;
the results stay the same.
Combining with other conditions:
* AND: push down the parts that can be converted.
* OR: push down only if every branch can be converted. Otherwise a file could
be skipped even though
another branch matches rows in it.
* NOT: don't push down. A bounding box can prove that a file has no rows in the
window, but not that all
of its rows are in the window, so NOT ST_Intersects(...) can't be used to
skip files.
* Anything that can't be converted isn't pushed down. The query still works,
just without file skipping.
h3. Dependencies
This needs spatial predicates in Iceberg's public expression API, which Iceberg
1.12.0 (used by Hive
today) doesn't have. This ticket is blocked until an Iceberg release includes
them:
* apache/iceberg#14101: adds the ST_INTERSECTS / ST_DISJOINT predicates.
* apache/iceberg#17175: uses them to skip files during scan planning
(InclusiveMetricsEvaluator).
h3. Out of scope
* CRS handling: the query window is assumed to be in the column's CRS.
ST_GeomFromText doesn't carry
a CRS, and Hive doesn't reproject.
* GEOGRAPHY: not covered until that type is added. Its bounding boxes can cross
the antimeridian, which
Iceberg's bounding-box check already handles.
h3. Testing
* Unit tests for converting Hive filters to Iceberg expressions: supported
filters, both argument orders,
combinations with 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 that:
** results are the same with pushdown on and off;
** files outside the query window are skipped (checked via EXPLAIN or the
number of scan tasks).
> 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
> When Iceberg writes a data file, it records a bounding box for each GEOMETRY
> column: the smallest
> rectangle containing all values of that column in the file. These are stored
> in the file's
> lower_bounds / upper_bounds. Hive already writes them, and 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 these bounds when reading. A query with a spatial filter
> reads every data file,
> even files whose data is far away from the queried area:
> {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
> Pass spatial filters to Iceberg, so it can skip files whose bounding box
> doesn't overlap the queried
> area (the "query window").
> Filters to support:
> * ST_Intersects between a GEOMETRY column and a constant geometry, with the
> arguments in either order.
> * The ST_* functions don't accept GEOMETRY yet, so today the column appears as
> ST_GeomFromWKB(CAST(col AS BINARY)). This form should be recognized first.
> Once the ST_* functions
> support GEOMETRY directly (separate follow-up), ST_Intersects(col, window)
> should be recognized too.
> * ST_Contains, ST_Within and ST_EnvIntersects can be added later in the same
> way. Each of them can only
> be true for rows that intersect the window, so the same file skipping
> applies.
> How it works:
> * The query window is a constant, so Hive computes its bounding box once, at
> compile time.
> * Hive converts the filter into Iceberg's spatial predicate,
> Expressions.stIntersects(column, boundingBox).
> During scan planning, Iceberg compares this box with each file's bounding
> box and skips files where
> the two don't overlap.
> * Hive passes filters to Iceberg today through SearchArgument, which only
> supports simple comparisons
> (=, <, IN, IS NULL, ...) and can't express a function call. Spatial filters
> need a separate conversion.
> * Hive still evaluates the original ST_Intersects on every row it reads. A
> file that isn't skipped can
> still contain rows that don't match. Pushdown only makes the query faster;
> the results stay the same.
> Combining with other conditions:
> * AND: push down the parts that can be converted.
> * OR: push down only if every branch can be converted. Otherwise a file could
> be skipped even though
> another branch matches rows in it.
> * NOT: don't push down. A bounding box can prove that a file has no rows in
> the window, but not that all
> of its rows are in the window, so NOT ST_Intersects(...) can't be used to
> skip files.
> * Anything that can't be converted isn't pushed down. The query still works,
> just without file skipping.
> h3. Dependencies
> This needs spatial predicates in Iceberg's public expression API, which
> Iceberg 1.12.0 (used by Hive
> today) doesn't have. This ticket is blocked until an Iceberg release includes
> them:
> * apache/iceberg#14101: adds the ST_INTERSECTS / ST_DISJOINT predicates.
> * apache/iceberg#17175: uses them to skip files during scan planning
> (InclusiveMetricsEvaluator).
> h3. Out of scope
> * Coordinate systems (CRS): the query window's coordinates are compared with
> the column's bounding
> boxes as plain numbers. For example, if the column is
> GEOMETRY('EPSG:3857'), whose coordinates are
> in metres, the window must also be given in EPSG:3857 metres, not in
> longitude/latitude degrees.
> Hive doesn't check this and doesn't convert between coordinate systems.
> This is the same behavior
> as evaluating ST_Intersects without pushdown, so pushdown doesn't change
> query results.
> * GEOGRAPHY: not covered until that type is added. Its bounding boxes can
> cross the antimeridian, which
> Iceberg's bounding-box check already handles.
> h3. Testing
> * Unit tests for converting Hive filters to Iceberg expressions: supported
> filters, both argument orders,
> combinations with 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 that:
> ** results are the same with pushdown on and off;
> ** files outside the query window are skipped (checked via EXPLAIN or the
> number of scan tasks).
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)