Skip to content

[GLUTEN-13487][VL] Offload Lance scans with vector columns - #13488

Merged
zhouyuan merged 1 commit into
apache:mainfrom
sezruby:feat/lance-vector-scan
Nov 3, 2026
Merged

zhouyuan merged 1 commit into
apache:mainfrom
sezruby:feat/lance-vector-scan

Conversation

@sezruby

@sezruby sezruby commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Lance stores vector (embedding) columns as Arrow FixedSizeList. The offloaded Lance scan wraps every Arrow vector it imports from lance-spark in Spark's ArrowColumnVector, which rejects FixedSizeList, so reading a vector column with Gluten enabled fails at runtime (#13487):

org.apache.spark.SparkUnsupportedOperationException: [UNSUPPORTED_ARROWTYPE] Unsupported arrow type FixedSizeList(4).

Velox's Arrow import (importFromArrowImpl) has no FixedSizeList (+w:N) case either, so the type has to be rewritten before the batch reaches either of them.

This PR rewrites FixedSizeList vectors as variable-size Lists when LanceFragmentIterator emits a batch:

  • A List holds the same values and matches the ArrayType that lance-spark already declares for the column, so both Spark's ArrowColumnVector and the offload to Velox read it.
  • Element i of a FixedSizeList of size n occupies child range [i * n, (i + 1) * n), also for null entries, so the offsets are i * n throughout. The child values are moved without copying; the only new buffer is the offsets buffer (4 bytes per row).
  • Nested vectors (a vector inside a struct, a list of vectors) are rewritten recursively. Columns without a FixedSizeList keep the existing transfer path unchanged.

This covers the vector part of #13487. The other column types listed there (FixedSizeBinary, millisecond Date, JSON, blob, unsigned integers, LargeList, metadata columns, empty projections) still need the plan-time fallback.

How was this patch tested?

VeloxLanceSuite, each test checked against vanilla Spark with runQueryAndCompare and against expected rows:

  • lance scan offloads vector columns: float and double vectors, including null vectors.
  • lance scan offloads nested vector columns: a vector inside a struct and a list of vectors, with null structs, null vectors inside a struct, null and empty lists.
  • lance vector columns feed Velox operators: element access and aggregation over top-level and nested vectors run in Velox, which reads the scan's batches directly (OffloadArrowDataExec over the scan, no row conversion).
  • lance vector columns pass through a Velox filter, shuffle and sort: a filter Lance does not push down, a columnar shuffle, and a sort over rows carrying vectors.
  • lance scan reads vector batches that are all null or empty.
  • lance scan reads vectors across fragments and batches: 1000 rows written as several fragments (max_row_per_file=300) and read in batches of 64.

LanceFixedSizeListsSuite, unit tests on Arrow vectors (each on a RootAllocator that fails on leaks): values and offsets with null rows, no-null/all-null/empty batches, values moved without copying, nested vectors, and release of partial results when the rewrite or a later column fails.

Ran both suites on Spark 3.5 and Spark 4.0 against the Velox native libraries of the current nightly build. On main, the new VeloxLanceSuite tests fail with UNSUPPORTED_ARROWTYPE or a VeloxRuntimeError, and the existing tests still pass.

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

Generated-by: Claude Opus 5.5

🤖 Generated with Claude Code

Lance stores vector (embedding) columns as Arrow FixedSizeList. The offloaded
Lance scan wraps every Arrow vector it imports in Spark's ArrowColumnVector,
which rejects FixedSizeList, so reading a vector column with Gluten enabled
failed at runtime with UNSUPPORTED_ARROWTYPE. Velox's Arrow import does not
support FixedSizeList either.

Rewrite FixedSizeList vectors as variable-size Lists when the scan emits a
batch, recursing into structs and lists. A List holds the same values and
matches the ArrayType lance-spark already declares for the column. The child
values are moved without copying; only an offsets buffer is allocated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sezruby

sezruby commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

@FelixYBW could you take a look when you have time? This fixes the crash on vector columns in the current Lance scan (#13487) by rewriting FixedSizeList vectors as Lists, without copying values. It's the short-term fix for 1.8: branch-1.8 has the same Lance scan code, so it needs this too, and the commit cherry-picks onto it cleanly. Once Gluten reads Lance through lance-spark's Arrow batches (#12958 (comment)), this rewrite moves to lance-spark and the code here is removed.

@sezruby

sezruby commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@zhouyuan could you take a look when you have time? This is a follow-up to #12958: it fixes the crash on vector columns in the Lance scan (#13487) by rewriting FixedSizeList vectors as Lists, without copying values. CI is green.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the changes enabling vector-column support in Velox-backed Lance scans.

No open issues 🎉

What changed in this PR

Enables Velox-backed Lance scans to read vector columns, addressing the vector portion of #13487. Other unsupported Lance column types remain outside this PR’s scope.

Changes:

  • Recursively rewrites Arrow FixedSizeList vectors as variable-size lists without copying child values, with cleanup on conversion failures.
  • Adds unit and integration coverage for nulls, nested vectors, multiple batches, memory ownership, and downstream Velox operators.
  • Documents vector-column offload support.
File Description
docs/​backends/​velox/​get-started/​VeloxLance.md Documents vector support and list conversion.
backends-velox/​src-lance/​test/​scala/​org/​apache/​gluten/​execution/​VeloxLanceSuite.scala Tests vector scans and downstream Velox execution.
backends-velox/​src-lance/​test/​scala/​org/​apache/​gluten/​execution/​LanceFixedSizeListsSuite.scala Tests conversion correctness, buffer reuse, and failure cleanup.
backends-velox/​src-lance/​main/​scala/​org/​apache/​gluten/​execution/​LanceScanTransformer.scala Converts fixed-size lists recursively before wrapping scan batches.

Review effort: Balanced

@zhouyuan
zhouyuan merged commit d64a51d into apache:main Nov 3, 2026
69 checks passed
malinjawi added a commit to malinjawi/incubator-gluten that referenced this pull request Nov 5, 2026
Since the Lance scan offload was added in apache#12958, isExportable has only
rejected a pushed aggregation and a full-text query. Other scans that
the Arrow C stream cannot serve are offloaded and then fail on their
first batch (apache#13487). apache#13488 makes vector columns readable; this covers
the rest.

isExportable now also checks the scan's columns at plan time, following
what LanceArrowStreamScanner.export and LanceFragmentScanner do:

- Columns that lance-spark's own reader fixes up after the native scan
  fall back. Blob (v1 and v2) and JSON columns come back in their stored
  form. The _rowid, _rowaddr, _fragid, row-version, _score and blob
  position and size columns are left out of the native projection.
- A scan that reads no columns falls back: the native scan returns
  _rowid instead.
- Every other column is mapped to Arrow with lance-spark's
  LanceArrowUtils, the mapping the export enforces, with vectors
  rewritten as lists as the scan emits them. An empty vector of that
  type is wrapped in ArrowColumnVector, as the scan will. FixedSizeBinary,
  Date(MILLISECOND) and Float16 vector columns fall back this way. Other
  vector columns stay offloaded.

With lance-spark 0.8.0, unsigned integer, LargeList, time and
non-microsecond timestamp columns still fail at execution: its Spark
schema does not record these Arrow types, so they cannot be told apart
at plan time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants