Commit 8a263b2
authored
Expose
## Which issue does this PR close?
- Closes #22152
## Rationale for this change
`ExecutionPlan::partition_statistics` and `TableProvider::statistics`
are not currently transported across the DataFusion FFI boundary, so
foreign plans and providers always report `Statistics::new_unknown` /
`None`. This blocks optimizer rules that depend on statistics (e.g. join
reordering, partition pruning) from working with out-of-process plugins,
which defeats the point of exposing those hooks to plugin authors.
`Statistics` contains `Precision<ScalarValue>` for column min/max/sum.
`ScalarValue` is a large enum that's impractical to mirror in
`#[repr(C)]`, so I reuse the existing
`datafusion_proto_common::Statistics` prost encoding — the same pattern
this crate already uses for filter expressions.
## What changes are included in this PR?
- New `datafusion_ffi::statistics` module with
`[de]serialize_statistics` helpers wrapping
the`datafusion_proto_common::Statistics` round-trip.
- New `partition_statistics` field on `FFI_ExecutionPlan` and
corresponding `ExecutionPlan::partition_statistics` impl on
`ForeignExecutionPlan`
- New `statistics` field on `FFI_TableProvider` and corresponding
`TableProvider::statistics` impl on `ForeignTableProvider`. Since the
trait returns `Option<Statistics>`, the implementation cannot propagate
decode errors, it logs a `log::warn!` and triggers a `debug_assert!`.
This PR is expected to be merged after #22136 so it includes those
changes.
## Are these changes tested?
Yes:
- Unit tests in `statistics.rs` cover three round-trip cases:
`Statistics::new_unknown`, fully-exact statistics with
`ScalarValue::Int32`/`Int64`/`Utf8` min/max/sum, and mixed
`Precision::Exact`/`Inexact`/`Absent` values.
- A new round-trip integration test in `execution_plan.rs` exercises
`ForeignExecutionPlan::partition_statistics` with both `None` and
`Some(idx)` partitions, against a plan with no statistics (returns
`Statistics::new_unknown`) and a plan with concrete statistics.
- A new round-trip integration test in `table_provider.rs` uses a thin
`TableWithStats` wrapper over `MemTable` to verify both the `None` path
and the concrete `Statistics` path through
`ForeignTableProvider::statistics`.
## Are there any user-facing changes?
This is a breaking ABI change for the `datafusion-ffi` crate:
- `FFI_ExecutionPlan` gains a `partition_statistics` field.
- `FFI_TableProvider` gains a `statistics` field.
Plugins compiled against earlier versions of `datafusion-ffi` will need
to be recompiled. There are no breaking changes to the Rust trait
surface or to `Statistics` itself; downstream `ExecutionPlan` /
`TableProvider` implementations require no changes.ExecutionPlan statistics across the FFI boundary (#22157)1 parent 2c8cf23 commit 8a263b2
8 files changed
Lines changed: 500 additions & 10 deletions
File tree
- datafusion/ffi
- src
- physical_expr
- tests
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
77 | 87 | | |
78 | 88 | | |
79 | 89 | | |
| |||
195 | 205 | | |
196 | 206 | | |
197 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
198 | 219 | | |
199 | 220 | | |
200 | 221 | | |
| |||
287 | 308 | | |
288 | 309 | | |
289 | 310 | | |
| 311 | + | |
290 | 312 | | |
291 | 313 | | |
292 | 314 | | |
| |||
454 | 476 | | |
455 | 477 | | |
456 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
457 | 486 | | |
458 | 487 | | |
459 | 488 | | |
| |||
468 | 497 | | |
469 | 498 | | |
470 | 499 | | |
| 500 | + | |
471 | 501 | | |
472 | 502 | | |
473 | 503 | | |
| |||
481 | 511 | | |
482 | 512 | | |
483 | 513 | | |
| 514 | + | |
484 | 515 | | |
485 | 516 | | |
486 | 517 | | |
487 | 518 | | |
488 | 519 | | |
489 | 520 | | |
490 | 521 | | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
491 | 527 | | |
492 | 528 | | |
493 | 529 | | |
| |||
521 | 557 | | |
522 | 558 | | |
523 | 559 | | |
| 560 | + | |
524 | 561 | | |
525 | 562 | | |
526 | 563 | | |
| |||
536 | 573 | | |
537 | 574 | | |
538 | 575 | | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
539 | 585 | | |
540 | 586 | | |
541 | 587 | | |
| |||
659 | 705 | | |
660 | 706 | | |
661 | 707 | | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
662 | 756 | | |
663 | 757 | | |
664 | 758 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
217 | 217 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
| 218 | + | |
| 219 | + | |
224 | 220 | | |
225 | 221 | | |
226 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 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 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
0 commit comments