sunchao opened a new pull request, #7731:
URL: https://github.com/apache/datafusion-comet/pull/7731
## Which issue does this PR close?
Partially addresses #5739. Related to #5553.
## Rationale for this change
In `SELECT s.ts FROM t WHERE id <=> match_id`, Spark compares the two
columns above its V1 Parquet scan. Its reader converts `s.ts` to microseconds
while building the batch. If a row contains `9223372036854776` milliseconds,
Spark throws `ArithmeticException("long overflow")` even when the two IDs in
that row differ. Comet currently treats the presence of a Catalyst filter as
evidence that Spark might prune the row. It converts the timestamp to null or
skips the row through native filtering, and the query succeeds. [Spark V1
filter
translation](https://github.com/apache/spark/blob/v4.1.3/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala#L604-L615),
[timestamp
decoding](https://github.com/apache/spark/blob/v4.1.3/sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/VectorizedColumnReader.java#L165-L173)
## What changes are included in this PR?
For a native V1 scan that requests a timestamp, use Spark's filter
translation after scalar subqueries resolve to determine whether Spark can pass
a predicate to Parquet. Late predicates also honor
`spark.sql.parquet.filterPushdown`. If Spark has no source predicate, use the
existing checked conversion and file-specific error reporting.
Comet can push some predicates that Spark evaluates above the reader. For
those predicates, the per-file schema adapter checks the requested timestamp
roots. If a corresponding physical root contains a millisecond timestamp, the
adapter defers the predicate to the filter above the native scan. This prevents
row-group, page, or row filtering from hiding an overflow. The decision is
conservative within a struct and applies even to files whose millisecond values
all fit. For microsecond files the adapter restores the original predicate.
When Spark translates a source predicate, the existing safeguard still
applies. The default `WHERE s.k >= 0` reproduction in #5739 falls into this
case. Matching Spark's pruning decisions there requires further work on nested
statistics and conversion-aware predicates. See [DataFusion
#20871](https://github.com/apache/datafusion/issues/20871) and
[#26282](https://github.com/apache/datafusion/pull/26282).
## How are these changes tested?
The Spark regression reads a two-row Parquet file with an overflowing nested
timestamp and asserts native execution with Comet row filtering both enabled
and disabled. It checks the structured file-read error, path, and arithmetic
cause for a column comparison, nested predicates with nested pushdown disabled,
and a scalar subquery with Parquet pushdown disabled. With nested pushdown
enabled, Spark can prune the group for `s.k < 0` and the test expects an empty
result.
A Rust adapter test applies the same predicate to two physical schemas and
checks that only the millisecond file defers it. `rustfmt --check` and `git
diff --check` passed. Execution validation is delegated to hosted CI.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]