Skip to content

[VL] Offload Lance scans through lance-spark's Arrow batches - #13648

Draft
sezruby wants to merge 2 commits into
apache:mainfrom
sezruby:feat/lance-arrow-batches
Draft

sezruby wants to merge 2 commits into
apache:mainfrom
sezruby:feat/lance-arrow-batches

Conversation

@sezruby

@sezruby sezruby commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Lance scans are offloaded through lance-spark's Arrow batch reads (lance-format/lance-spark#908) instead of LanceScanTransformer, as proposed in #12958 (comment).

Builds on #13732, which moved the Lance scan into the gluten-lance module.

  • LanceArrowBatchScan, a pre-transform rule, switches a Lance BatchScanExec to Arrow batches (LanceScan.withArrowBatches()) when lance-spark can emit them and Velox imports every column type of them. VeloxLanceComponent.convFuncOverride declares those batches as ArrowJavaBatchType, so Gluten plans BatchScanExec → OffloadArrowDataExec → ArrowColumnarToVeloxColumnarExec for a Velox consumer, and only ColumnarToRowExec for a row-based one.
  • The scan stays a vanilla BatchScanExec, so it keeps lance-spark's runtime filters, output partitioning and custom metrics, which LanceScanTransformer and its RDD dropped.
  • Columns Velox doesn't import (interval columns, and the types lance-spark can't emit as Arrow batches) and scans lance-spark can't emit Arrow batches for (a pushed aggregation) stay as vanilla Spark reads them. TIMESTAMP_NTZ and null columns are offloaded.
  • ArrowColumnVectors.adopt and copy handle a NullVector, which has no allocator: adopt called getAllocator() on it and failed with Tried to get allocator from NullVector. This is decided at planning time from the Arrow schema lance-spark reports, which also covers the scans [GLUTEN-13487][VL] Fall back Lance scans the Arrow stream cannot carry #13554 keeps on vanilla Spark.
  • LanceScanTransformer, OffloadLanceScan and the FixedSizeList rewrite are removed: lance-spark's Arrow batches already carry vectors as lists. This leaves gluten-lance without sources until the Lance write code moves there. LanceArrowBatchScan is in backends-velox/src-lance because it checks the column types Velox imports.
  • OffloadArrowDataExec now closes the batches that ColumnarBatches.offload builds from Spark ArrowColumnVectors. For such a batch offload returns a new batch and leaves the input to its producer, but nothing closed the new one, so tasks ended with "There are still unreleased native columnar batches during ending the task." VeloxLanceSuite logged it 15 times before this change and doesn't now.
  • lance.version is 0.9.1-beta.2, the first lance-spark release with Import more datasource tests #908.
  • Docs: VeloxLance.md, and ArrowColumnarConversion.md, which used LanceScanTransformer as its example.

Without pruning, this path is slower than LanceScanTransformer, because adopt copies each batch: lance-spark allocates them from Spark's Arrow allocator, and Gluten's task allocator is a separate root. In an emulated benchmark the copy cost up to 21% (#12958). A follow-up removes the copy by having lance-spark build the batches in Gluten's task allocator. That follow-up is lance-format/lance-spark#966, tracked in sezruby#1. It waits for Arrow Java fixes for imports that run out of memory.

Runtime filters apply on this path because the BatchScanExec stays (LanceScanTransformer planned every partition); lance-spark takes them on Spark 4.1+ (lance-format/lance-spark#927).

Known issue on this path:

How was this patch tested?

  • VeloxLanceSuite: the existing tests now check that the Lance scan reads Arrow batches and, for a pushed aggregation, that it doesn't; a new test reads TIMESTAMP_NTZ and null columns through the offloaded scan, also under a Velox aggregate and sort. Each test compares with vanilla Spark through runQueryAndCompare.
  • ArrowColumnVectorTest: offloading a batch of Spark ArrowColumnVectors with a null column. It fails on main with Tried to get allocator from NullVector.
  • ColumnarBatchTest: OffloadArrowDataExec's iterator closes the batch it built from Spark ArrowColumnVectors when the next batch is requested and on close, and leaves a Gluten batch to its producer.

Ran them on Spark 3.5 against lance-spark 0.9.1-beta.2 and the Velox native libraries of the 2026-11-26 nightly build: VeloxLanceSuite 12, ColumnarBatchTest 8 and ArrowColumnVectorTest 7 tests pass. Compiles on Spark 4.0 / Scala 2.13.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 5.5

🤖 Generated with Claude Code

@prestodb-ci

Copy link
Copy Markdown

Failed to query issues imported from #13648:

Error 1045 (28000): Access denied for user 'presto'@'10.167.107.7' (using password: YES)

@github-actions github-actions Bot added CORE works for Gluten Core VELOX DOCS labels Nov 15, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

sezruby and others added 2 commits November 26, 2026 08:27
LanceArrowBatchScan switches a Lance BatchScanExec to lance-spark's
Arrow batch reads (LanceScan.withArrowBatches, lance-spark#908) when
Velox imports every column type of them, and VeloxLanceComponent
declares those batches as ArrowJavaBatchType, so Gluten offloads them
with its Arrow transitions. The vanilla BatchScanExec stays in the plan
and keeps lance-spark's runtime filters, output partitioning and
metrics. LanceScanTransformer and OffloadLanceScan are removed.

OffloadArrowDataExec now closes the batches that ColumnarBatches.offload
builds from Spark ArrowColumnVectors, which nothing closed before.

Generated-by: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Velox imports both, and Gluten runs TIMESTAMP_NTZ natively by default.
ArrowColumnVectors.adopt and copy now handle a NullVector, whose
getAllocator() throws.

Generated-by: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sezruby
sezruby force-pushed the feat/lance-arrow-batches branch from 3118c49 to 084ac16 Compare November 26, 2026 16:33
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants