← Back to Pull requests

GH-50994: [C++][Compute] Implement casting from ListView to List with zero-copy fast-path #50976

Closed
unknown closed this pull request without merging on Sep 17, 2026 16:57 UTC
View on GitHub
unknown unknown commented on Aug 24, 2026 20:21 UTC
Author

Rationale for this change

This PR implements missing type-casting compute kernels to convert ListViewType and LargeListViewType arrays to standard ListType and LargeListType arrays.

Previously, these casts routed to CastList, which ignored the sizes buffer and read offsets out-of-bounds, resulting in corrupted output arrays. This PR introduces a dedicated CastListView functor to perform correct conversions.

What changes are included in this PR?

To maximize performance and optimize memory layouts, a dual-execution path was implemented in the CastListView execution functor inside scalar_cast_nested.cc:

1. Contiguous Zero-Copy Fast-Path: Triggered when the input list-view elements are contiguous and adjacent (i.e. offsets[i] + sizes[i] == offsets[i+1]). It avoids copying the child values array entirely, allocating the new output offset buffer, shifting offsets relative to the start, and slicing the child array directly to preserve zero-copy pointer semantics.
2. Non-Contiguous Fallback Path: Triggered for gapped, overlapping, or out-of-order layouts. It dynamically tracks target offsets, builds integer index mappings using an Int64Builder, and invokes Arrow's internal take compute kernel to reconstruct a new contiguous child values array.
3. Kernel Registration: Formally wired into Arrow's casting system for standard and large variants of both nested types, replacing the incorrect routing.

Are these changes tested?

Yes, added comprehensive unit test suites in scalar_cast_test.cc passing all cases. Tests explicitly cover:
Contiguous Arrays: Validated zero-copy memory behavior programmatically by ensuring the source and destination child buffers share the exact same physical memory address.
Gapped & Overlapping Arrays: Verified correct offset tracking and reconstruction when offsets intersect or contain unused slots.
Null Propagation: Checked that null validity maps propagate correctly at both the parent and child levels.
Generic/Nested Types: Validated casting on non-primitive data types (e.g. utf8 strings) and recursive child type promotions (e.g., ListView<int16> to List<int32>).
Boundary Slices: Verified that taking slices of non-contiguous arrays computes correct offsets and avoids out-of-bound errors.

Are there any user-facing changes?

No public API contracts were broken. This adds correct, declarative casting support natively to the existing internal compute framework.

GitHub Issue: #50994

Diff: 319 lines (+239 / -80) across 3 files Reviewer: Reranko05 Review duration: 34356m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 319 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
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.345
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #50976"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% 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: 40.4% (MEDIUM) · Higher = larger blast radius
40.4%
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: 60.5% · Lower = rushed or shallow review
60.5%
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: 16.0% · Safe to merge
16.0%
Repository