Commit 8561bd9
authored
feat: add LanceWriteParams and lance_dataset_write_with_params (#20)
## Summary
- Adds `LanceWriteParams` (`max_rows_per_file`, `max_rows_per_group`,
`max_bytes_per_file`, `data_storage_version`, `enable_stable_row_ids`)
and `lance_dataset_write_with_params`. Pass `params = NULL` to inherit
upstream defaults.
- `lance_dataset_write` is now a thin delegator to `_with_params` with
`params = NULL`. Its FFI signature and ABI are unchanged vs
`upstream/main`.
- C++ gets a `lance::WriteParams` struct and a 5-arg
`lance::Dataset::write(...)` overload; the existing 4-arg overload
delegates to it with a default-constructed `WriteParams{}`.
## Motivation
`lance_dataset_write` uses upstream's defaults for everything.
Production callers need to tune output file/group sizes and the Lance
file format version; stable row ids are also a common opt-in. This
exposes those knobs without touching the simple-path API.
Closes #15.
## Design notes
- `data_storage_version` takes a string (`"2.0"`, `"2.1"`, `"stable"`,
`"legacy"`, ...) parsed via `LanceFileVersion::from_str`. Empty or
invalid strings → `LANCE_ERR_INVALID_ARGUMENT`.
- Numeric fields use `0` as a "keep upstream default" sentinel.
- `enable_stable_row_ids` is `bool` and so has **no default sentinel** —
whatever the caller writes is forwarded verbatim. Today upstream's
default is `false`, so a zero-init `LanceWriteParams` is a no-op;
struct-level docs in Rust and C/C++ headers call this out so a future
upstream flip won't be silent.
- Lance's `WriteParams` has more advanced fields (commit handlers,
progress callbacks, blob/base internals) intentionally not exposed —
they belong in Rust, not a thin C FFI.
## Review fixes (jja725's pass)
- **Stream consumption ordering** (#20 (comment) on `_with_params`): the
stream is now consumed via `from_raw` before validating
`uri`/`schema`/`mode`, so the documented "consumed regardless of return
code" contract holds on every error path. Mirrors what landed for plain
`lance_dataset_write` in #16.
- **`enable_stable_row_ids` semantics**: doc-only fix as suggested —
Rust struct, C header, and C++ header all call out that this field is
strictly an override.
- **`u64 → usize` truncation on 32-bit**: replaced silent `as usize`
casts with a `u64_to_usize(v, field)` helper that uses `usize::try_from`
and surfaces the offending field name + value as
`LANCE_ERR_INVALID_ARGUMENT` on overflow.
## Merge with `upstream/main`
Resolved conflicts in `Cargo.toml`, `include/lance/lance.{h,hpp}`,
`src/writer.rs`, `tests/c_api_test.rs`, and
`tests/cpp/{test_c_api.c,test_cpp_api.cpp}`. Adopted upstream's:
- `lance` 4.0.1 dependency set (added `lance-file` for
`LanceFileVersion` parsing).
- `int32_t mode` FFI signature (ABI-safe against `-fshort-enums` on the
consumer side).
- RAII `StreamGuard` / `SchemaGuard` pattern in the C++ `Dataset::write`
wrappers.
- `RwLock<Arc<Dataset>>` shape for `LanceDataset.inner`.
Diff vs `upstream/main`: 466 insertions across 5 files (`Cargo.toml`,
`include/lance/lance.h`, `include/lance/lance.hpp`, `src/writer.rs`,
`tests/c_api_test.rs`).
## Test plan
- `cargo test` — **103 passed**, 0 failed. 8 new tests for
`_with_params`: NULL params behaves like plain `write`,
`max_rows_per_file` splits fragments (100 / 20 → ≥5),
`max_rows_per_group` plumbed, `max_bytes_per_file` plumbed, known
versions (`"2.0"` / `"2.1"` / `"stable"`) accepted, empty version
rejected, invalid version rejected, `enable_stable_row_ids` toggle
accepted.
- `cargo clippy --all-targets -- -D warnings` clean.
- `cargo fmt --check` clean.
- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps` clean.
- `cargo test --test compile_and_run_test -- --ignored` — C and C++
integration tests pass.1 parent 82efe6b commit 8561bd9
5 files changed
Lines changed: 466 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
584 | 626 | | |
585 | 627 | | |
586 | 628 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
106 | 123 | | |
107 | 124 | | |
108 | 125 | | |
| |||
145 | 162 | | |
146 | 163 | | |
147 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
148 | 177 | | |
149 | 178 | | |
150 | 179 | | |
151 | 180 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
156 | 185 | | |
157 | 186 | | |
158 | 187 | | |
| |||
219 | 248 | | |
220 | 249 | | |
221 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
222 | 259 | | |
223 | 260 | | |
224 | 261 | | |
225 | 262 | | |
226 | 263 | | |
227 | 264 | | |
228 | | - | |
| 265 | + | |
229 | 266 | | |
230 | 267 | | |
231 | 268 | | |
232 | 269 | | |
| 270 | + | |
233 | 271 | | |
234 | 272 | | |
235 | 273 | | |
| |||
240 | 278 | | |
241 | 279 | | |
242 | 280 | | |
243 | | - | |
| 281 | + | |
244 | 282 | | |
245 | 283 | | |
246 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
77 | 109 | | |
78 | 110 | | |
79 | 111 | | |
| |||
88 | 120 | | |
89 | 121 | | |
90 | 122 | | |
| 123 | + | |
| 124 | + | |
91 | 125 | | |
92 | 126 | | |
93 | 127 | | |
| |||
97 | 131 | | |
98 | 132 | | |
99 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
100 | 159 | | |
101 | 160 | | |
102 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
103 | 164 | | |
104 | 165 | | |
105 | 166 | | |
| |||
109 | 170 | | |
110 | 171 | | |
111 | 172 | | |
| 173 | + | |
112 | 174 | | |
113 | 175 | | |
114 | 176 | | |
| |||
198 | 260 | | |
199 | 261 | | |
200 | 262 | | |
201 | | - | |
| 263 | + | |
202 | 264 | | |
203 | 265 | | |
204 | 266 | | |
205 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
206 | 275 | | |
207 | | - | |
| 276 | + | |
208 | 277 | | |
209 | 278 | | |
210 | 279 | | |
| |||
221 | 290 | | |
222 | 291 | | |
223 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
0 commit comments