Skip to content

table: bind configurable optimize actions and their statistics - #106

Merged
Xuanwo merged 4 commits into
mainfrom
xuanwo/c-optimize-action-migration
Nov 21, 2026
Merged

Xuanwo merged 4 commits into
mainfrom
xuanwo/c-optimize-action-migration

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

What

Adds a configurable optimize entry point bound to the SDK's Table::optimize(OptimizeAction) and to the statistics it reports, for the Go migration's OptimizeWithAction / OptimizeStats.

  • lancedb_table_optimize_with_action() runs one of the existing LanceDBOptimizeType actions with that action's options and returns what the SDK reports.
  • LanceDBCompactionOptions carries the seven SDK compaction overrides behind a set_fields bitmask, so an omitted option keeps the SDK default and stays distinct from a value equal to it, including an explicit zero on the SDK's optional size fields.
  • LanceDBPruneOptions carries the age in exact nanoseconds plus delete_unverified and error_if_tagged_old_versions behind the same presence bits. A sub-second age keeps its exact length, zero with its bit set is a cutoff at now, and an unset bit keeps the SDK's default week-long age.
  • LanceDBOptimizeStats carries has_compaction with the four compaction metrics and has_prune with the bytes and old versions removed, so the SDK's optional metric groups stay separate.
  • The config's action is a raw int, so a value outside the enumerators is rejected instead of becoming an invalid Rust enum. The same holds for unknown set_fields bits, booleans other than 0 and 1, sizes that do not fit in size_t, and a negative age. All of it is validated before Table::optimize is called.
  • INDEX uses the SDK's default OptimizeOptions; index rebuild options stay in Add index rebuild options #74.
  • Header comments state the backend boundaries the SDK applies: an Enterprise compaction treats a target equal to the SDK default (1048576) as omitted and returns after submission with placeholder metrics while processing may continue; a zero prune age cuts off at now while the latest and protected versions survive, and tagged versions are retained unless error_if_tagged_old_versions refuses.

lancedb_table_optimize() keeps its signature, defaults and dispatch, so this is an additive C API addition (minor bump at release time). The Go adapter maps nil option fields to unset bits and time.Duration to nanoseconds; that replaces the JSON older_than_seconds conversion and its floor-to-1s workaround with the exact duration.

Header comments are the API reference (doxygen), so there is no docs/index.rst change.

The PR also drops the x86_64-apple-darwin package matrix entry, following the directive to drop Intel macOS, which leaves five shipped platforms. The Windows Cargo home fix from #94 is retained.

Testing

  • New C++ consumer in tests/test_index.cpp through the public header, on four 20-row fragments:
    • compact with all seven overrides: 4 fragments removed and 1 added with the expected files, a second call reports zeros, rows unchanged; an explicit materialize_deletions = false leaves the deletion on disk while omitting the bit materializes it (the SDK default), which shows the presence bit works.
    • prune: the default age removes nothing; a 1µs age removes the three old versions with bytes removed > 0, keeps the current version and rows, and a second prune removes nothing; explicit delete_unverified = 1 and error_if_tagged_old_versions = 0 are converted. The comment states that this young fixture proves pruning and no whole-second round-up, not the absence of a truncation to zero.
    • ALL reports both metric groups, INDEX neither; an action outside the enumerators, unknown bits, bad booleans and a negative age return LANCEDB_INVALID_ARGUMENT with the field in the message and leave the version, fragment count and row count unchanged.
  • A Rust unit test over the existing config conversion carries 500 ms through as exact nanoseconds when its bit is set, and leaves the SDK age unset when the bit is clear, without clock reads.
  • C tests were verified at fa20bf9 (main at 5388ca8): all nine CTest suites pass under the repo's valgrind configuration (139s); focused valgrind on both optimize cases reports 0 errors and 0 leaks. The later commits change only the workflow matrix, header comments and one C++ comment, so this evidence still covers the test code.
  • cargo fmt --check, cargo clippy (lib and tests), cargo test --lib and cargo check --lib are clean; the header compiles as C17 with gcc and clang (-Werror) and in the C++20 test build.
  • The workflow matrix change leaves five targets, keeps the ci: keep Windows Cargo git checkouts under MAX_PATH #94 Windows step, and parses as YAML.

lancedb_table_optimize stays as it is: each action runs with the SDK
defaults and the statistics are discarded. The new
lancedb_table_optimize_with_action binds the same SDK operation with the
options of the action it runs and returns the metrics the SDK reports.

* compact carries the seven SDK compaction overrides; prune carries the
  age in exact nanoseconds and the two tri-state flags
* set_fields keeps an omitted option distinct from a value that equals
  the default, and the SDK's optional size fields stay optional
* the result keeps the SDK's optional compaction and prune groups apart
* invalid input is rejected with LANCEDB_INVALID_ARGUMENT before the
  table is touched: an action outside LanceDBOptimizeType, unknown option
  bits, sizes that do not fit in size_t, booleans other than 0 and 1, and
  a negative prune age
* the action is a raw int in the config, so an out-of-range value is
  rejected instead of becoming an invalid Rust enum; the legacy function
  and its dispatch are unchanged
* the C tests check real compaction numbers, an explicit
  materialize_deletions=false against the omitted default, a sub-second
  prune age that removes three old versions, and rejection without any
  version or fragment change

Signed-off-by: Xuanwo <[email protected]>
The project no longer ships an x86_64-apple-darwin artifact, so the
package matrix keeps the five remaining platforms. The Windows Cargo home
fix from #94 stays unchanged.

Signed-off-by: Xuanwo <[email protected]>
* note that an Enterprise compaction treats a target equal to the SDK
  default as omitted and returns placeholder metrics after submission
* spell out a cutoff at now, the versions that survive it, and that tagged
  versions are retained unless error_if_tagged_old_versions refuses
* clarify what the C++ 1µs prune case can and cannot prove
* add a deterministic Rust test for the nanosecond prune age and its
  presence bit, without clock reads

Signed-off-by: Xuanwo <[email protected]>
@Xuanwo
Xuanwo merged commit 88168d1 into main Nov 21, 2026
14 checks passed
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.

1 participant