← Back to Pull requests

Slice v1 scan batches for input_file_name() [databricks] #16794

Closed
unknown closed this pull request without merging on Nov 16, 2026 15:49 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 19:08 UTC
Author

Fixes #16743.
Short term fix for #13918.

Description

GpuInputFileName builds its column with ColumnVector.fromScalar(path, numRows), so a batch needs numRows utf8PathBytes bytes of string data and cudf caps that at 2 GiB. A single scan batch with ~16M+ rows and a ~135-byte path fails with CudfColumnSizeOverflowException. Delta MERGE adds input_file_name() itself, so users cannot avoid it, and reader batch size configs are soft limits that do not reliably prevent it. The only workaround today is spark.rapids.sql.expression.InputFileName=false.

After these changes, when a v1 file scan (GpuFileSourceScanExec) feeds a bare input_file_name(), the scan slices any batch whose rows pathBytes would exceed the string limit into row slices of at most maxRows rows (maxRows = max(1, (Int.MaxValue - 1MiB) / max(1, pathBytes))). Smaller batches pass through unchanged. The projection stays on the GPU. This covers the reported case: Delta MERGE and Spark's default useV1SourceList both use v1 scans.

How it works:

  • The path length is read from InputFileBlockHolder once per source batch. While slices are pending, the scan iterator does not touch the reader, so the path cannot change under us.

  • An oversized batch is made spillable, and slices are cut lazily under a retry block. Each slice is a copy (cudf slice copies), so the source batch can be spilled or closed independently.

  • Zero column batches (all columns pruned) are sliced by row count.

  • The pending batch is closed on task completion and when exhausted or abandoned.

  • Only plans containing InputFileName trigger slicing, not input_file_block_start/length.
  • Not covered by this short term fix (to be tracked on #13918):

  • v2 file scans (GpuBatchScanExec, e.g. Iceberg).

  • Expressions that build a longer string from the name, such as concat(input_file_name(), 'x') or upper(input_file_name()) (see the comment on HEADROOM_BYTES).

  • Rows added between the scan and the project, and a filter on input_file_name().

  • Iceberg _file, which the reader builds itself.
  • Testing:

  • New InputFileNameBatchSlicerSuite (unit) and InputFileNameLongPathSuite (end to end), plus test_parquet_input_file_name_sliced_large_batch and test_delta_merge_input_file_name_sliced_large_batch. The suites cover:

  • - slice boundaries, order and path capture across files of different path lengths;
    - zero column batches;
    - the source not being advanced while slices are pending;
    - cleanup on abandon and on task completion;
    - retry OOM;
    - multi-byte paths;
    - the Delta MERGE plan shape, with an inner monotonically_increasing_id() project under an outer input_file_name() project;
    - the PERFILE and MULTITHREADED Parquet readers (COALESCING falls back to MULTITHREADED when the query uses input_file_name()).
  • The end to end tests use a lowered string cap (internal test conf spark.rapids.sql.test.inputFileName.maxStringBytes) and assert batch counts, so they fail if slicing is disabled. An earlier, larger Delta MERGE run (not included in this PR because it needs gigabytes of GPU memory) reproduced the original CudfColumnSizeOverflowException without the fix.

  • The Python tests compare GPU and CPU results with the lowered cap. They are wiring checks and would also pass without slicing; slicing itself is asserted in the Scala suites.

  • InputFileNameLongPathSuite runs in the en_US.UTF-8 premerge step because one test uses a multi-byte directory name. That test is skipped when sun.jnu.encoding is not UTF-8.

  • Run on Spark 3.3.0 (Scala tests) and Spark 3.5.7 with OSS Delta 3.3.0 (integration tests). sql-plugin also compiles on Scala 2.13 with Spark 4.1.1. Databricks is not verified locally; [databricks] is in the title so the MERGE test runs there.
  • Performance (Spark2a, 8 workers, NDS sf3k, GPU old jar vs new jar, 10 runs per jar, no slicing triggered): the median run time of each input_file_name() query was within 1.5% between the two jars, and the differences were not statistically significant (p ≥ 0.2). A control query with no input file expression was also unchanged (5848 vs 5846 ms over 16 runs per jar, p = 0.75). With default 2 GB partitions, where slicing did fire on the new jar, the old jar fails three string queries with CudfColumnSizeOverflowException and the new jar completes them (3.9, 2.9 and 4.2 s; one run, earlier build). The cost of slicing itself (each slice is a copy of its rows) was not separately measured, and Delta MERGE was not timed. The timings were taken before the trigger was narrowed to input_file_name().

    Checklists

    Documentation

  • Updated for new or modified user-facing features or behaviors

  • No user-facing change
  • Testing

  • Added or modified tests to cover new code paths

  • Covered by existing tests

  • (Please provide the names of the existing tests in the PR description.)
  • Not required
  • Performance

  • Tests ran and results are added in the PR description

  • Issue filed with a link in the PR description

  • Not required
  • Diff: 640 lines (+480 / -160) across 8 files Reviewer: gerashegalov Review duration: 9880m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 640 lines diff across 8 files
    0.52
    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.387
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #16794"
    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: 51.9% (MEDIUM) · Higher = larger blast radius
    51.9%
    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: 20.5% · Safe to merge
    20.5%