Commit a4f4cef
authored
feat: add lance_dataset_add_columns for SQL / all-null / stream column addition (#45)
## Summary
Last of three PRs against #41. Exposes upstream's `Dataset::add_columns`
through the three `NewColumnTransform` cases that translate cleanly
across the C ABI:
- **SQL expressions** — derive new columns from SQL over existing
columns.
- **All-null columns** — add nullable columns from an Arrow schema. On
the modern format this is metadata-only; the legacy format can't
represent it that way and returns `LANCE_ERR_NOT_SUPPORTED`.
- **Stream** — splice in precomputed column data from an Arrow C stream,
aligned positionally to the dataset's existing rows.
Upstream's fourth variant, `BatchUDF`, is left out on purpose: it
carries a Rust closure that can't cross the C ABI, and the stream
variant already covers the same "bring your own computed data" use case.
Each call mutates the dataset in place under an exclusive write lock;
scanners already in flight keep their pre-add view via the same Arc
clone-on-write as the `_drop_columns` (#42) / `_alter_columns` (#44)
siblings.
Three focused entry points rather than one mode-tagged function, because
the inputs are genuinely different shapes (name/expression pairs vs. a
schema pointer vs. a stream). Upstream's `read_columns` parameter isn't
exposed — it only feeds `BatchUDF`; for these three variants upstream
ignores it. `batch_size` is forwarded where it does something (SQL scan,
stream alignment) and omitted from the metadata-only all-null path.
## Surface
```c
typedef struct LanceSqlColumn {
const char* name;
const char* expression;
} LanceSqlColumn;
int32_t lance_dataset_add_columns_sql(
LanceDataset* dataset, const LanceSqlColumn* columns,
size_t num_columns, uint64_t batch_size);
int32_t lance_dataset_add_columns_nulls(
LanceDataset* dataset, const struct ArrowSchema* schema);
int32_t lance_dataset_add_columns_stream(
LanceDataset* dataset, struct ArrowArrayStream* stream,
uint64_t batch_size);
```
`batch_size` uses `0` for the upstream default and is range-checked to
`u32`. Two error-code details are worth calling out, both matching
existing behavior: a SQL expression referencing a non-existent column
surfaces as `LANCE_ERR_INTERNAL` (an upstream schema error, the same
path as `lance_dataset_delete`), whereas a syntax error is
`LANCE_ERR_INVALID_ARGUMENT`.
Because these are `unsafe extern "C"` entry points under `panic =
"abort"`, the stream variant pre-validates the mandatory CADI callbacks
before handing the stream to arrow-rs (which would otherwise abort on a
NULL `get_schema` / `get_next`), and the all-null variant rejects an
uninitialised or non-UTF-8 top-level schema `format` before arrow-rs's
`assert!`/`expect` can fire. The stream is consumed (released) on every
non-NULL return path.
## Tests
Rust integration tests cover all three variants end to end: computed
values (single and multi-column SQL, constant expressions, honored
`batch_size`), all-null backfill, and multi-fragment stream alignment —
plus the full rejection surface (NULL/empty/non-UTF-8 inputs, name
collisions, row-count mismatch, invalid `batch_size`,
released/missing-callback streams, non-nullable all-null fields, and the
legacy-format `NOT_SUPPORTED` path). Stream-consumption is proven with a
drop counter rather than a vacuous release-slot check. C and C++ smoke
tests exercise the SQL happy path and each variant's argument rejections
across the ABI.1 parent 68da0b3 commit a4f4cef
7 files changed
Lines changed: 1655 additions & 8 deletions
File tree
- include/lance
- src
- tests
- cpp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
559 | 559 | | |
560 | 560 | | |
561 | 561 | | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 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 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
562 | 670 | | |
563 | 671 | | |
564 | 672 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
139 | 149 | | |
140 | 150 | | |
141 | 151 | | |
| |||
511 | 521 | | |
512 | 522 | | |
513 | 523 | | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
514 | 596 | | |
515 | 597 | | |
516 | 598 | | |
| |||
0 commit comments