← Back to Pull requests

fix: check Parquet timestamp overflow when Spark filters after the scan #7731

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 21, 2026 09:58 UTC
Author

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, timestamp decoding

One 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's InferFiltersFromConstraints can add a translatable IS 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 1 can 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 new CometParquetResultExec node scopes the check to executeCollect() 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-based toPandas() 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 Connect

The 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 >= 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 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 on ignoreCorruptFiles after 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-profiles for the version-specific behavior. The fork runs Spark 4.1 Catalyst and all four sql_core shards. I applied run-spark-4.1-hive-tests for the four sql_hive shards. The older run-spark-4.1-tests label no longer schedules any jobs. Spark SQL suite selection · Fork CI · Hive CI

Diff: 650 lines (+487 / -163) across 8 files Reviewer: viirya Review duration: 14869m
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
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 52% (MEDIUM) · Higher = larger blast radius
52%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 27.7% · Safe to merge
27.7%