Skip to content

Add initial Lance dataset support - #110548

Open
fastio wants to merge 187 commits into
ClickHouse:masterfrom
fastio:lance-storage-engine-and-table-function
Open

fastio wants to merge 187 commits into
ClickHouse:masterfrom
fastio:lance-storage-engine-and-table-function

Conversation

@fastio

@fastio fastio commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #56910

This PR adds experimental read-only support for querying existing Lance
datasets through the ClickHouse data lake object-storage stack.

It introduces:

  • LanceS3 and lanceS3 for S3-compatible object storage.
  • LanceLocal and lanceLocal for locally stored datasets.
  • lanceS3Cluster for distributed reads across a ClickHouse cluster.
  • Schema inference and explicit schema validation from the Lance Arrow schema.
  • Query-scoped snapshot pinning and snapshot-consistent reads.
  • Column projection, safe full and partial predicate pushdown, residual
    ClickHouse filtering, LIMIT pushdown, and count optimizations.
  • Arrow batch conversion, including supported nested Array, Tuple, and
    Map types.
  • Parallel read pipelines, query cancellation, and Lance-specific
    observability through ProfileEvents.
  • Unit, stateless, S3, and cluster integration test coverage.

The integration is read-only. It does not create Lance datasets, write or
mutate data, build Lance indexes, or provide vector search.

Depends on: ClickHouse/rust_vendor#71

Changelog category (leave one):

  • Experimental Feature

Changelog entry:

Add experimental read-only support for querying existing Lance datasets from
local and S3-compatible storage through the LanceLocal and LanceS3 table
engines and the lanceLocal, lanceS3, and lanceS3Cluster table functions.

Example use:

SELECT *
FROM lanceS3('https://bucket.s3.amazonaws.com/path/to/dataset.lance', 'access_key_id', 'secret_access_key');

Workflow [PR]
Sync PR [sync-upstream/pr/110548]

@fastio fastio changed the title Add lanceS3 support for Lance datasets Add initial Lance dataset support Jul 15, 2026
@scanhex12 scanhex12 self-assigned this Jul 15, 2026
@scanhex12 scanhex12 added the can be tested Allows running workflows for external contributors label Jul 15, 2026
@clickhouse-gh clickhouse-gh Bot closed this Jul 15, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Jul 15, 2026
@scanhex12
scanhex12 requested a review from Copilot July 15, 2026 12:27
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jul 15, 2026

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.

Pull request overview

This PR introduces an initial (read-only) Lance dataset adapter integrated into ClickHouse’s data lake object storage stack, enabling Lance datasets to be queried via new storage engines (LanceLocal/LanceS3) and table functions (lanceLocal/lanceS3) with a custom read pipeline.

Changes:

  • Add Lance data lake metadata + custom read pipeline support (via a new optional read hook returning a Pipe).
  • Add a Rust static library (_ch_rust_lance) exposing a C FFI (ch_lance.h) used by ClickHouse to open/scan Lance datasets (including an S3 download-to-local-cache MVP).
  • Register Lance storages/table functions and add stateless + integration tests.

Reviewed changes

Copilot reviewed 34 out of 38 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
utils/list-licenses/list-licenses.sh Allow a new Rust license expression string used by vendored dependencies.
tests/queries/0_stateless/04101_lance_local_readonly_mvp.sql Adds a stateless regression test for LanceLocal reads.
tests/queries/0_stateless/04101_lance_local_readonly_mvp.reference Expected output for the Lance stateless test.
tests/integration/test_s3_table_functions/test.py Adds MinIO upload helper + integration test for lanceS3.
src/TableFunctions/TableFunctionObjectStorage.h Adds Lance table function aliases when USE_LANCE is enabled.
src/TableFunctions/TableFunctionObjectStorage.cpp Registers lanceS3/lanceLocal in the DataLake table function group.
src/Storages/registerStorages.cpp Registers Lance storage engines when USE_LANCE is enabled.
src/Storages/ObjectStorage/StorageObjectStorageSource.cpp Adds support for configuration-provided custom read Pipe before format-based reading.
src/Storages/ObjectStorage/StorageObjectStorageDefinitions.h Defines LanceLocalDefinition/LanceS3Definition.
src/Storages/ObjectStorage/StorageObjectStorageConfiguration.h Adds a virtual read hook returning std::optional<Pipe>.
src/Storages/ObjectStorage/registerStorageObjectStorage.cpp Registers LanceLocal and LanceS3 engines.
src/Storages/ObjectStorage/DataLakes/Lance/tests/gtest_lance_table_state_snapshot.cpp Adds unit tests for Lance table state snapshot serde and wrapper error behavior.
src/Storages/ObjectStorage/DataLakes/Lance/LanceWrapper.h Declares the C++ wrapper around the Rust FFI (dataset/scan/schema).
src/Storages/ObjectStorage/DataLakes/Lance/LanceWrapper.cpp Implements dataset open/scan/schema export and Arrow record batch import.
src/Storages/ObjectStorage/DataLakes/Lance/LanceTableStateSnapshot.h Defines Lance table state snapshot struct for query pinning/serde.
src/Storages/ObjectStorage/DataLakes/Lance/LanceTableStateSnapshot.cpp Implements Lance snapshot serialization/deserialization.
src/Storages/ObjectStorage/DataLakes/Lance/LanceScanDescription.h Describes scan projection/predicate/count-only options for Lance.
src/Storages/ObjectStorage/DataLakes/Lance/LanceReadSource.h Introduces a pipeline source that emits ClickHouse Chunks from Lance scans.
src/Storages/ObjectStorage/DataLakes/Lance/LanceReadSource.cpp Implements batch iteration and Arrow-to-CH conversion for Lance.
src/Storages/ObjectStorage/DataLakes/Lance/LanceMetadata.h Declares Lance metadata implementation for the DataLake stack.
src/Storages/ObjectStorage/DataLakes/Lance/LanceMetadata.cpp Implements schema discovery, snapshot pinning, iterator, predicate extraction, and custom read Pipe.
src/Storages/ObjectStorage/DataLakes/IDataLakeMetadata.h Adds an optional read hook for dataset-style formats to build pipelines directly.
src/Storages/ObjectStorage/DataLakes/DataLakeTableStateSnapshot.h Extends the variant/type enum to include Lance snapshots.
src/Storages/ObjectStorage/DataLakes/DataLakeTableStateSnapshot.cpp Adds Lance snapshot serialization/deserialization dispatch.
src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h Forwards the new read hook to the active metadata implementation; adds Lance configuration typedefs.
src/configure_config.cmake Enables USE_LANCE when the Rust ch_rust::lance target is present.
src/Common/config.h.in Adds USE_LANCE compile-time define.
src/CMakeLists.txt Adds Lance sources to dbms build and links ch_rust::lance into dbms + unit tests when present.
rust/workspace/lance/src/lib.rs Implements the Rust Lance adapter + C FFI, including S3 download-to-tempdir logic and Arrow FFI output.
rust/workspace/lance/include/ch_lance.h C header for the Rust FFI used by ClickHouse.
rust/workspace/lance/Cargo.toml New Rust staticlib crate definition and dependencies.
rust/workspace/CMakeLists.txt Adds ENABLE_LANCE option and exposes ch_rust::lance target when enabled.
rust/workspace/Cargo.toml Adds the lance crate to the Rust workspace members.

Comment thread rust/workspace/CMakeLists.txt Resolved
Comment thread rust/workspace/lance/src/lib.rs Resolved
Comment thread rust/workspace/lance/src/lib.rs Resolved
alexey-milovidov and others added 3 commits November 9, 2026 03:36
# Conflicts:
#	src/Processors/QueryPlan/ReadFromObjectStorageStep.cpp
#	src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
…the natural end of the scan

With several `BatchSource` consumers, one could fail to take the last batch
(e.g. while importing it in `Scan::nextBatch`) while another one observed the
natural end of the data and set the state to `Ended`. The failing consumer
then saw a state other than `Running` and suppressed its exception, so the
query succeeded with the batch missing.

The coordinator now remembers that the scan ended because the producer
finished normally, and a consumer failure after that is still propagated
(once). Stops at the limit and cancellations keep suppressing it, because
the rows of the lost batch are not needed there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…enEphemeral` again

`static_cast<void>` does not silence the check, which still failed
`Build (arm_tidy, 3/4)`. Keep the released pointer and assert that it is
the one `Impl` holds.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110548&sha=latest&name_0=PR&name_1=Build%20(arm_tidy%2C%203%2F4)
PR: ClickHouse#110548

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master and pushed two fixes:

  • Conflicts: master dropped the keep_row_lineage_columns argument of getFormatFilter and added a second format filter info that tracks the TopK best values. The PR's make_format_filter_info lambda is kept, and an object-storage wrapper (make_object_format_filter_info) now builds both format filter infos for the object path, so reader_limit still works. In StorageObjectStorageSource::generate, the PR's getFileNameForVirtualColumns filename is kept, and the full_path that master removed together with the legacy Delta Lake reader stays removed.
  • Build (arm_tidy, 3/4): static_cast<void>(dataset.release()) still triggered bugprone-unused-return-value. The released pointer is now kept and asserted against Impl::dataset. I checked this locally with clang-tidy.
  • Review blocker (a consumer failure racing with natural EOF in ScanCoordinator::nextBatch): fixed, with a deterministic gtest.

All PR-touched translation units compile against the merged master. The full binary was not linked locally because the build machine is overloaded, and the new gtest compiles but was not run. The three remaining open threads (the contrib/rust_vendor gitlink on an unmerged rust_vendor branch, schema reload with an explicit Lance schema, and credential refresh during a scan) still need a decision from the author or a maintainer.

alexey-milovidov and others added 6 commits November 10, 2026 03:28
# Conflicts:
#	src/Processors/Formats/Impl/ArrowColumnToCHColumn.h
…of a distributed `Lance` worker

`ReadFromObjectStorageStep::createIterator` called
`StorageObjectStorageSource::ensureDataLakeTableState` unconditionally, so a
`lanceS3Cluster` worker pinned its local latest dataset version in the
`QuerySession` before requesting a task. If a writer appended a new version
between the initiator pinning its snapshot and the worker building its
pipeline, the worker then threw `LOGICAL_ERROR` from `QuerySession::getPinned`
when reading a task of the initiator's version.

The iterator of a distributed read gets the files from the task callback and
does not use the table state, and the TopK query condition cache key is not
made under distributed processing, so skip the state acquisition for formats
whose snapshot arrives in every task object, the same way
`StorageObjectStorage::read` does. The `datalake_distributed_worker_latest_snapshot`
failpoint now also guards this call, so
`test_lance_s3_cluster_worker_does_not_fetch_latest_snapshot` covers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-and-table-function

`master` moved the Rust workspace to `contrib/rust-contrib-workspace` and every crate into its own
`contrib/<name>-cmake` directory (`rust/workspace` is gone). Follow that layout for Lance:
- `rust/workspace/lance` is now `contrib/lance-cmake`, with the Lance part of the old
  `rust/workspace/CMakeLists.txt` in `contrib/lance-cmake/CMakeLists.txt`, added from `contrib/CMakeLists.txt`.
- The lz4/zstd localization and the symbol stripping use `clickhouse_postprocess_rust_lib`,
  which `master` introduced for incremental post-processing of Rust libraries.
- `contrib/rust-contrib-workspace/Cargo.toml` lists `../lance-cmake` and keeps `panic = "unwind"`.
- `contrib/rust-contrib-workspace/Cargo.lock` is `master`'s lockfile with the Lance dependencies
  added offline (`cargo metadata --offline`); only the wasm-only `wasm-bindgen` family is
  downgraded by one patch version to match `web-sys` and `wasm-bindgen-futures` in the vendor directory.
- `contrib/rust_vendor` points at `ee0f2363`, a merge of the Lance vendor commit `e2c5e2ae`
  with `master`'s `ed9f05f1` (ClickHouse/rust_vendor#83); the only conflicts were
  `.cargo-checksum.json` files differing in the `$comment` field, resolved to `master`'s version.
…Utils` header

After the merge of `master`, `VirtualColumnUtils.h` no longer includes `FormatSettings.h`, and
`filterByPathOrFile` lost its `format_settings` and `file_names` parameters. Call
`getFilterByPathAndFileIndexes` with `file_names` directly and filter with `filterSourcesByIndexes`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-and-table-function

`master` now links the whole Rust workspace as one static library
(`_ch_rust_workspace`, imported once in `contrib/rust-contrib-workspace`), with
the members as interface targets (`clickhouse_add_rust_member`). Adapt Lance
to it:
- `_ch_rust_lance` is a workspace member with the `lance` feature of the root
  package, re-exported from `src/lib.rs`, and a plain library crate.
- `clickhouse_add_rust_member` gets an `ENV` argument, applied to the one
  cargo run, for the `PROTOC` and `PROTOC_INCLUDE` the Lance build scripts
  need; `protoc` is a `BUILD_DEPENDS` when it is built natively.
- The Lance-specific lz4/zstd localization and the strip step with the list of
  `ch_lance_*` entry points are dropped: the workspace strip step now localizes
  the Rust symbols and the bundled C libraries (`zstd-sys` and `lz4-sys` are
  already in the workspace on `master`) and keeps the C entry points.
- `Cargo.lock` is `master`'s lockfile with the Lance packages added offline
  against the vendor directory; no `master` package changed version.

`ReadFromObjectStorageStep::createIterator`: keep `master`'s
`if (!iterator_metadata)` (a clone keeps its pinned snapshot) around the
distributed-worker snapshot logic of this PR. `StorageObjectStorageSource`
takes both `limit_` (this PR) and `shared_create_reader_pool_` (`master`); the
new in-order read of `master` passes no limit, as each of its sources is one
file of a merge.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (3ddad7a), which now links the Rust workspace as one static library. Lance is now a regular workspace member (clickhouse_add_rust_member(_ch_rust_lance FEATURE lance ...)). clickhouse_add_rust_member takes a new ENV argument so PROTOC/PROTOC_INCLUDE still reach the one cargo run. The Lance-specific lz4/zstd localization and strip steps were removed, because the workspace strip step already localizes the bundled C libraries and the Rust symbols. Cargo.lock is master's lockfile with the Lance packages added offline, and no master package changed version. The clickhouse binary builds with ENABLE_LANCE=ON and exports all 21 ch_lance_* entry points. The Lance stateless tests that can run under clickhouse local pass (26/33); the rest need a server (system.query_log, S3) and are left to CI. The three open review threads (the rust_vendor gitlink, schema reload for explicit schemas, credential refresh) still need a human decision.

Comment thread contrib/lance-cmake/src/lib.rs Resolved
alexey-milovidov and others added 3 commits November 14, 2026 12:01
…e-and-table-function

Conflict in `src/TableFunctions/TableFunctionObjectStorage.cpp`: keep both
`NOT_IMPLEMENTED` (used by this PR) and `LOGICAL_ERROR` (used by master).
Master now rejects the `disk` setting for data lake table functions other
than Iceberg and Delta Lake; allow `lance*` functions too, since this PR
creates `Lance` configurations over a disk.
…c links resolved

`LanceMetadata::getDatasetOptions` checks a local dataset path with
`pathStartsWith`, which compares it with symbolic links resolved, so a
dataset root that is a symbolic link out of `user_files_path` is already
rejected. But it passed the lexical path to the Rust side, which then
canonicalized it again, so a root replaced by a symbolic link after the
check would be followed.

Pass the path with symbolic links resolved, and make
`ensure_local_dataset_contained` reject a dataset whose root resolves to
a different directory than the one that was checked. Extend
`05447_lance_local_symlink_containment` with a dataset root that is a
symbolic link out of `user_files_path`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	src/Storages/ObjectStorage/IObjectIterator.h
#	src/Storages/ObjectStorage/StorageObjectStorageConfiguration.h
alexey-milovidov and others added 8 commits November 19, 2026 10:38
…e-and-table-function

Conflict resolutions:
- `contrib/rust_vendor`: merged the Lance vendor commit with master's
  `chdig v26.11.1` vendor update (new submodule commit 8a53938a). Crates that
  master pruned but the Lance dependency tree still needs are kept.
- `contrib/rust-contrib-workspace/Cargo.lock`: taken from master and re-resolved
  offline against the merged vendor directory, which only adds the Lance
  dependencies on top of master's versions.
- `StorageObjectStorageStableTaskDistributor.cpp`: taken master's version, which
  calls `iterator->next` outside the distributor lock (ClickHouse#131-series change
  "Do not hold the lock of the cluster task distributor while iterating
  files"). The PR's single critical section is dropped: `LanceDatasetIterator`
  is internally synchronized, and files queued for a replica that already got
  an empty task are picked up by the work stealing in `getAnyUnprocessedFile`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ScanCoordinator::nextBatch` treated a batch with zero rows like an exhausted
row limit: `claimRows(0)` returned zero, so it called `finishAtLimit` and
cancelled the whole scan. An empty batch is not the end of the data: the Lance
legacy reader applies deletion vectors with `filter_record_batch` and forwards
a possibly empty result, so a fragment whose first rows are deleted could yield
an empty batch followed by the surviving rows, which were silently lost.

Empty batches are now released and skipped; `finishAtLimit` is reached only
when the row limit is exhausted. Add a unit test with an empty batch before
and after a non-empty one, with and without a row limit.

Address review: ClickHouse#110548 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mark the accessors and query functions added by this PR with `[[nodiscard]]`
(`modernize-use-nodiscard`), and replace the `if constexpr ... else` chain that
was split across `#if` blocks in `TableFunctionObjectStorage::parseArgumentsImpl`
with independent blocks followed by `if (!configuration)` around the `switch`
(`readability-misleading-indentation`).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110548&sha=5b735f9ff8743e649eaa062fd0b5eb7db3c4dfeb&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29
PR: ClickHouse#110548

Note: the review link in the previous commit is wrong; the review comment
about empty Arrow batches is
ClickHouse#110548 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gsSecretString` in the `Lance` code

The setting is declared as `SecretString` in `S3AuthSettings.cpp`, but `LanceMetadata.cpp` referred to it
as `S3AuthSettingsString`, which the style check rejects.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110548&sha=4e41fcaea31fc1aa9915342d4bba5393e4b5d620&name_0=PR&name_1=Style%20check
ClickHouse#110548

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… host platform

`contrib/lance-cmake` pointed `PROTOC` at the `protoc` of the nested native build whenever `USE_MUSL` was set.
The nested native build exists only when cross-compiling (see the root `CMakeLists.txt`), and musl is now
the default libc of the Linux toolchain files, so in a musl build for the host platform that path does not
exist and the build script of `lance-encoding` failed with "Could not find `protoc`". This broke
every `arm_tidy` build. Use the same condition as the nested native build, so such builds run the statically
linked `protoc` of the main build, the same way `protobuf_generate` does.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110548&sha=4e41fcaea31fc1aa9915342d4bba5393e4b5d620&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29
ClickHouse#110548

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…e-and-table-function

Conflict resolutions:
- `src/Core/ProtocolDefines.h`, `src/Interpreters/ClusterFunctionReadTask.{h,cpp}`: `master` took
  cluster processing protocol version 16 for `DBMS_CLUSTER_PROCESSING_PROTOCOL_VERSION_WITH_DATA_LAKE_FILE_SIZE`,
  so the `Lance` versions are now 17 (`..._WITH_LANCE_METADATA`) and 18 (`..._WITH_LANCE_SNAPSHOT_IDENTITY`).
  The file size hint is written before the `Lance` trailer, in the order of the versions.
  A `Lance` object info takes precedence over `ObjectInfoWithFileSizeHint` in `getObjectInfo`.
- `contrib/corrosion-cmake/CMakeLists.txt`: both sides kept (the `Lance` C flags and
  `-fno-sanitize=unsigned-integer-overflow` for UBSan builds).
- `contrib/rust-contrib-workspace/Cargo.toml`: both sides kept (`panic = "unwind"` and the
  `[patch.crates-io]` section for the `arrow-rs` and `ipnet` forks). `Cargo.lock` merged cleanly and
  `cargo update --workspace` leaves it unchanged.
- `contrib/rust_vendor`: points at `fff8c1fd`, a merge of the `Lance` vendor commit `8a53938a` with
  `master`'s `431d6180` (ClickHouse/rust_vendor#87), plus the crates that `master` pruned but the
  `Lance` dependency tree still locks (`arrayvec` 0.7.8, `crossbeam-deque` 0.8.8, `libredox` 0.1.25,
  `memmap2` 0.9.11, `num_cpus` 1.17.0, `rawpointer` 0.2.1, `toml_edit` 0.25.13, `unicase` 2.10.0),
  taken from `cargo vendor --locked`.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (the PR was conflicting) and fixed the Style check failure:

Verification: the Rust workspace builds with ENABLE_LANCE=ON against the new vendor directory, and all PR-touched translation units compile against the merged master. The full clickhouse binary was not linked locally (the build machine is overloaded), so the Lance tests were not run here and are left to CI.

The three open review threads (the contrib/rust_vendor gitlink on a rust_vendor branch that is not on main, schema reload with an explicit Lance schema, and credential refresh during a scan) still need a decision from the author or a maintainer. The Finish Workflow check stays red until they are resolved.

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

can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. external Author is not a member of the ClickHouse organization manual approve Manual approve required to run CI pr-experimental Experimental Feature submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lance data format support

6 participants