fix: check Parquet timestamp overflow when Spark filters after the scan #7731
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7731"
general
weight: 0.35
viirya
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 convertss.tsto microseconds while building the batch. If a row contains9223372036854776milliseconds, Spark throwsArithmeticException("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, timestamp decodingOne example is reconciling two nullable values in a change log. A query for records whose values agree, including when both are missing, could use
SELECT event_time FROM changes WHERE old_value <=> new_value. This case is narrow with default pushdown. For ordinary equality, arithmetic and many string predicates, Spark'sInferFiltersFromConstraintscan add a translatableIS NOT NULL. That disqualifies the scan even if the original comparison stays above the reader. The null-safe comparison avoids that inferred filter. Its frequency in production is unmeasured.What changes are included in this PR?
Enable Comet's existing checked conversion and file-specific error reporting for a full
collect()over a native V1 Parquet scan with filters and projections when Spark evaluates every predicate after decoding. Check the Parquet pushdown setting in the session that owns the relation, including for global temporary views. A scalar subquery is eligible when that session disables pushdown, since its resolved value could otherwise become a source filter. Capture eligibility when constructing the scan RDD so later changes to the session settings respect the original reader's pruning. Spark 3.5 can cache nested filters even earlier when displaying scan metadata, so Comet treats any translatable nested predicate as a potential source filter on that version.Require name-based field resolution with matching case sensitivity. Skip the extra overflow check for requested schemas containing Parquet field IDs. With swapped IDs, Spark can select columns by ID and then decode by name. The readers can end up scaling different physical timestamps. Also skip the check when Spark ignores corrupt files, since that setting suppresses decoding errors.
Spark and Comet can decode different numbers of rows per batch. For example,
LIMIT 1can finish before Spark reads an overflowing timestamp in the second batch. An RDD iterator can stop at the same point without a limit in the SQL plan. The newCometParquetResultExecnode scopes the check toexecuteCollect()by passing the scan ID to its tasks through a Spark local property. This also covers callers that reuse the same DataFrame for different actions. The rule matches a single scan under filters, projections and row transitions. Other plans, including limits, joins and aggregates, keep the existing filtered-scan behavior.A plan-time decision alone cannot distinguish these actions. Applying this guard to existing unfiltered reads would also suppress errors when the overflow lies inside Spark's first batch. #7784 tracks aligning both paths with the rows Spark actually decodes.
Classic PySpark collection uses
executeCollect(). Arrow-basedtoPandas()and Spark Connect collection consume an RDD. These two paths, writes and cached reads can still produce null on overflow. Classic collection, Arrow batches, Spark ConnectThe planner passes the overflow flag explicitly to the native reader. Comet can push some predicates that Spark evaluates above the reader. For those predicates, the per-file schema adapter matches the requested timestamp leaves using the decoder's field resolution rules. If a selected leaf needs millisecond-to-microsecond conversion, the adapter defers filtering to the operator above the native scan. This prevents row-group, page, or row filtering from hiding an overflow. It costs pruning on these files even when all values fit. If only an unselected sibling uses milliseconds, Comet can still prune using the predicate.
When Spark translates a source predicate, the existing safeguard still applies. The default
WHERE s.k >= 0reproduction 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 and #26282.How are these changes tested?
The Spark tests select top-level and nested timestamps separately with Comet row filtering on and off. They require native scans and check the file path, structured error and arithmetic cause. Separate cases cover
LIMIT 1, partial RDD consumption followed by full collection, and swapped nested field IDs. Another test turns onignoreCorruptFilesafter planning so the scan stays native. With one row per Spark batch, Spark returns the valid first row and skips the remainder of the file on overflow. A cross-session read with mismatched case sensitivity checks that Comet returns null when Spark treats the selected timestamp as a missing column.Two Spark 4.x regressions protect different decisions. Changing nested pushdown between planning, reader construction and reuse checks when Comet samples it. A global temporary view with different owner and query settings checks whose Parquet pushdown setting applies. Both mistakes could cause Comet to raise on a row group Spark skips.
A Rust test swaps the units of selected and unused timestamps inside a list of structs and checks when filtering is deferred. Hosted CI includes
run-all-spark-profilesfor the version-specific behavior. The fork runs Spark 4.1 Catalyst and all foursql_coreshards. I appliedrun-spark-4.1-hive-testsfor the foursql_hiveshards. The olderrun-spark-4.1-testslabel no longer schedules any jobs. Spark SQL suite selection · Fork CI · Hive CI