Repository navigation
[GLUTEN-13487][VL] Offload Lance scans with vector columns - #13488
Conversation
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>
|
@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 |
There was a problem hiding this comment.
🟢 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
FixedSizeListvectors 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
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.
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'sArrowColumnVector, which rejectsFixedSizeList, so reading a vector column with Gluten enabled fails at runtime (#13487):Velox's Arrow import (
importFromArrowImpl) has noFixedSizeList(+w:N) case either, so the type has to be rewritten before the batch reaches either of them.This PR rewrites
FixedSizeListvectors as variable-sizeLists whenLanceFragmentIteratoremits a batch:Listholds the same values and matches theArrayTypethat lance-spark already declares for the column, so both Spark'sArrowColumnVectorand the offload to Velox read it.iof aFixedSizeListof sizenoccupies child range[i * n, (i + 1) * n), also for null entries, so the offsets arei * nthroughout. The child values are moved without copying; the only new buffer is the offsets buffer (4 bytes per row).FixedSizeListkeep the existing transfer path unchanged.This covers the vector part of #13487. The other column types listed there (
FixedSizeBinary, millisecondDate, 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 withrunQueryAndCompareand 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 (OffloadArrowDataExecover 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 aRootAllocatorthat 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
VeloxLanceSuitetests fail withUNSUPPORTED_ARROWTYPEor aVeloxRuntimeError, 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