[SPARK-58315][SQL] Refactor DSv2 scan statistics handling #57487
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.42) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 347 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.350
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #57487"
general
weight: 0.35
yyanyy
Refactor how a DataSource V2 (DSv2) scan reports statistics, aligning it with
the v1 (
LogicalRelation/CatalogStatistics.toPlanStats) path.computeStatsgates oncboEnabled || planStatsEnabled: full statisticsonly when needed, otherwise a cheaper size-only estimate via the new
SupportsReportStatistics.estimateSizeInBytes()default method.SupportsReportStatistics.reflectsFullyPushedDownFilters()default method(
true). When a connector returnsfalse,V2ScanRelationPushDownre-addsthe fully pushed, deterministic filters above the scan so
FilterEstimationadjusts the stats. The rewrite is row-equivalent, idempotent, and best-effort
under column pruning (pruned-reference predicates are dropped).
transformV2StatsinferssizeInBytesfrom the row count when no size isreported (matching v1); the dead
defaultRowCountparameter is removed.V1ScanWrapperimplementsSupportsReportStatistics, delegating to thewrapped v1 scan so its stats are no longer dropped.
V2StatisticsUtils(null-safe).Both new methods have defaults that preserve existing behavior, so existing
connectors need no change.
Why are the changes needed?
To let DSv2 connectors produce statistics more cheaply and let Spark plan on
more accurate statistics, matching v1:
sizeInBytes, so a connector can skip the expensive row/column statistics.FilterEstimationinstead of planning on too-large estimates, improving plan choices.
now used instead of the default size, at no extra cost to the connector.
Does this PR introduce _any_ user-facing change?
New API introduced but no behavior change by default except for the following cases:
default size was used)
SupportsReportStatisticsnow has its reported statistics surfaced (previously dropped).Both changes make the estimates more accurate and align with the v1 path.
How was this patch tested?
New unit and end-to-end tests in
DataSourceV2RelationSuiteandDataSourceV2Suitecover: the CBO / plan-stats gating, size inference(including the zero-row case), null/empty statistics handling,
V1ScanWrapperdelegation, and the post-pushdown filter re-adding (including the recursion
through stacked residual filters).
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code