Skip to content

feat(gluten): export a Lance fragment scan as an Arrow C stream - #12

Closed
sezruby wants to merge 8 commits into
mainfrom
feat/gluten-arrow-stream-forwarding
Closed

feat(gluten): export a Lance fragment scan as an Arrow C stream#12
sezruby wants to merge 8 commits into
mainfrom
feat/gluten-arrow-stream-forwarding

Conversation

@sezruby

@sezruby sezruby commented Aug 17, 2026

Copy link
Copy Markdown
Owner

What

Adds LanceArrowStreamScanner to the base module: it plans a Lance fragment scan through the existing LanceFragmentScanner and re-exports the scan's ArrowReader as an Arrow C Data Interface stream (ArrowArrayStream).

Only the stream's C-struct address (LanceArrowStream#streamAddress()) crosses the JVM/native boundary, so a native consumer such as Apache Gluten / Velox does not need to match lance-spark's Arrow build or classloader.

Why

This is step 2 of the JVM Arrow-in/Arrow-out read path for Gluten support (apache/gluten#12263, Approach 2): lance-spark hands a native engine an Arrow C stream over a planned fragment scan. A gluten-side scan-offload rule that consumes streamAddress() is the remaining piece.

Details

  • All scan planning — column projection, filter pushdown, limit/offset, row-id/row-address, batch size — is delegated to LanceFragmentScanner, so the exported stream yields the same rows in the same order as the Spark columnar reader.
  • The scan is materialized one Arrow batch at a time as the consumer pulls, so peak JVM Arrow memory is bounded by a single batch rather than the whole fragment.
  • The returned LanceArrowStream handle owns the exported stream and the scanner behind it. exportArrayStream transfers ownership of the reader to the stream, so close() releases the stream (which closes the reader via the C release callback) and then the scanner and dataset — it never closes the reader itself.
  • A TODO(lance#7259) marks a one-line swap to LanceScanner#exportArrowStream(long) once that lands upstream: the Rust core would populate the caller's stream directly and skip the JVM-side Arrow materialization. The LanceArrowStream contract is unchanged, so no consumer needs to be touched.

Test

LanceArrowStreamScannerTest exports each fragment of the bundled test table, re-imports it via Data.importArrayStream (standing in for a native consumer), drains it, and asserts the rows match the Spark columnar reader. Closing the imported reader and then the handle under the leak-checking RootAllocator also verifies the export/reader/scanner lifecycle releases cleanly.

mvn -pl lance-spark-base_2.12 -am -DskipTests install
mvn -pl lance-spark-base_2.12 test -Dtest=LanceArrowStreamScannerTest

🤖 Generated with Claude Code

jerryjch and others added 8 commits August 17, 2026 16:11
…nce-format#528)

## Lance dependency — required to compile

* Depends on lance-format/lance#6748, which adds
`Update.Builder.updatedFragmentOffsets(...)` /
`Update.updatedFragmentOffsets()` and JNI
FromJava + IntoJava so the driver commit passes matched offsets into
Rust.

Bump **`lance.version`** in `pom.xml` to a release that includes
lance#6748 before building or merging this PR; otherwise build fails on
the new API calls.

## Summary

* Fixes lance-format#418.
* `UpdateColumnsWriter.processFragment`: after each
`fragment.updateColumns()` call, reads
`result.getUpdatedRowOffsets()` and accumulates a `Map<Long, long[]>` of
fragment id →
  matched physical row offsets.
* `TaskCommit`: carries the per-fragment offset map alongside the
existing
  `updatedFragments` and `fieldsModified` fields.
* `UpdateColumnsBackfillBatchWrite.commit()`: merges offset maps from
all task commits and
passes them to `Update.builder().updatedFragmentOffsets(...)`. Lance's
`build_manifest`
then calls the partial `_row_last_updated_at_version` refresh only for
the matched rows,
  leaving unmatched rows and untouched fragments unchanged.
* `BaseUpdateColumnsBackfillTest`: flips

`testUpdateColumnsPreservesCreatedAtAndAdvancesLastUpdatedWithStableRowIds`
from the
  "known gap" pin (assertEquals, no change) to the correct assertion
  (`assertTrue(after > before)`); updates Javadoc accordingly.


## Background

`UPDATE COLUMNS FROM` rewrites column data in place via Lance's
`Operation::Update` with
`RewriteColumns` mode. Lance's `build_manifest` can partially refresh
`_row_last_updated_at_version` for only the matched rows — but only when
the
`updated_fragment_offsets` map is non-empty on the commit. Previously
`UpdateColumnsBackfillBatchWrite` never populated this map, so the
partial refresh never
activated and `_row_last_updated_at_version` stayed stale after every
UPDATE COLUMNS
commit, breaking CDF consumers.

The matched row offsets are already computed inside Lance during
`fragment.updateColumns()`
and surfaced via `FragmentUpdateResult.getUpdatedRowOffsets()`
(lance#6650). The missing
piece was wiring those offsets from the executor task result through
`TaskCommit` to the
driver commit, and then setting them on the `Update` operation — which
this PR does.

## Test plan

*
`BaseUpdateColumnsBackfillTest#testUpdateColumnsPreservesCreatedAtAndAdvancesLastUpdatedWithStableRowIds`
— creates a stable-row-id table, runs UPDATE COLUMNS over all rows, and
asserts
  `_row_last_updated_at_version` strictly increases for each row while
  `_row_created_at_version` is unchanged.

---------

Co-authored-by: Jing chen He <jingh@adobe.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Daniel Rammer <hamersaw@protonmail.com>
… raw version number (lance-format#770)

Related lance-format#713

### Description
This PR refactors Spark read and write options to use LanceRef instead
of passing around raw version numbers directly. The goal is to make
reference handling more explicit and extensible, especially for future
branch and tag support.

The change updates the Spark option model and related call sites to
carry reference information through the connector, while preserving the
ability to resolve snapshot versions where needed. This lays the
groundwork for consistent handling of main, versioned, branch, and tag
references across read, scan, blob/search, and write paths.

### Summary

1. Replace raw version-based Spark options with LanceRef.
2. Update read/write option APIs and affected Spark call sites.
3. Align test utilities with the new reference model.
4. Prepare the connector for branch/tag-aware reference handling.

---------

Co-authored-by: fangbo <fangbo.0511@bytedance.com>
Related lance-format#713

# Motivation

In some use cases, users need to run DQL against a specific tag rather
than relying on the default resolution behavior. Tags are read-only.
Tags could just stay on time travel.

# How to query

```SQL
SELECT * FROM lance.users VERSION AS OF 'specific_tag';
```

# Changes

* Add support for executing DQL against a specific tag.
* Enable more explicit tag-scoped reads in query workflows.
* Improve flexibility for scenarios where users need to access data from
a designated tag.

# Testing

* Added/updated tests for DQL queries with a specific tag.
* Verified that existing query behavior remains unchanged when no tag is
specified.
* Validated the new tag-specific query path works as expected.

---------

Co-authored-by: fangbo <fangbo.0511@bytedance.com>
…t#777)

Branch identifiers were failing on Glue because we first tried to
resolve the full branch shaped identifier as a literal table. Glue only
accepts database.table, so that lookup failed before we could fall back
to the parent table and branch.

This changes branch identifier resolution so the literal table lookup is
just a probe. If it does not resolve as a real table, we load the parent
table and apply the branch instead. Literal tables still win on catalogs
that support them.

The collision test is skipped on Glue since Glue cannot represent that
table shape.
The Arrow C stream export path added in the following commit calls
LanceScanner#exportArrowStream(long), which is first available in
lance-core 11.0.0-beta.21 (lance-format/lance#7259).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add LanceArrowStreamScanner, which plans a fragment scan via the existing
LanceFragmentScanner and exports it as an Arrow C Data Interface stream
(ArrowArrayStream) for native consumers such as Apache Gluten / Velox.

Only the ArrowArrayStream C-struct address crosses the JVM/native boundary,
so the consumer's Arrow build and classloader do not need to match
lance-spark's (Gluten builds Arrow 15 to match Spark 3.5 / Velox, while the
Lance Java SDK is on Arrow 18). The Lance native core populates the
caller-owned stream directly through LanceScanner#exportArrowStream(long),
so no Arrow data is materialized on the JVM heap on this path.

All scan planning (column projection, filter pushdown, limit/offset,
row-id / row-address, batch size) is delegated to LanceFragmentScanner, so
the exported stream yields exactly the same rows in the same order as the
Spark columnar reader. LanceArrowStream owns the exported stream and the
scan behind it; closing it releases the native scan (via the stream's
release callback) and then the scanner and dataset handles.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sezruby
sezruby force-pushed the feat/gluten-arrow-stream-forwarding branch from 2a7f762 to d94b5c6 Compare August 23, 2026 16:09
@sezruby

sezruby commented Aug 23, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the upstream PR lance-format#778, which uses the direct LanceScanner#exportArrowStream(long) (lance-core 11.0.0-beta.21) instead of the double-hop staged here.

@sezruby sezruby closed this Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants