Repository navigation
Commit a63583c
Add dfx_udfs: the library that cannot be installed as a bundle
Second of three libraries for #1719, and the one carrying the mixed-workflow
case: it exposes no `__datafusion_session_components__`, so callers register
its three functions and install its two codecs by hand.
That is not an artificial handicap. `SessionExtensionComponents` carries codec
fields only, so a function library has nowhere to put its functions — the
rename in 5a1bfeb noted that UDF and provider fields will join later. Until
they do, this is what a function library actually looks like, and the example
should show what that costs rather than pretend every dependency has caught
up. A test asserts the shape rather than describing it: `with_extensions`
rejects this object, naming the hook it lacks.
The functions are `dfx_net_revenue` (the TPC-H revenue expression),
`dfx_weighted_avg`, and `dfx_revenue_rank`. The aggregate is written out rather
than delegating to a built-in because its state is the point: two running sums,
which is what lets DataFusion compute a partial aggregate per partition and
merge the results. An aggregate that could only be evaluated over its whole
input at once would give a different answer once split, which is exactly what a
worker does to it. A test pins that by checking the plan really is
`mode=Partial` and the answer is still right.
Both codecs are name-only — `try_encode_*` writes nothing and `try_decode_*`
rebuilds from `name`. Three worker tests, each a separate interpreter, pin what
that buys, and they disagree with each other in the useful way:
codec installed, nothing registered -> works, decode_calls == 1
functions registered, no codec -> works, decode_calls == 0
neither -> fails, naming dfx_net_revenue
So installing the codec is an *alternative* to registering the functions, not
an addition to it. The middle case is the trap worth knowing: on the driver,
where the functions are registered, the registry is tried first and the codec
is never consulted — so a codec that was broken or missing looks fine right up
until a worker needs it.
`try_decode_*` checks the name before the buffer, in that order. An empty
encoding leaves `fun_definition` unset and carries no codec id, so it is the
one path where a payload is offered to every installed codec in turn; a codec
that trusted `buf` first would answer for names it does not own. There are two
codecs because there are two plan layers and a library cannot know which one
its callers will serialize — an engine shipping physical plans exercises only
the physical one.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 29502bf commit a63583c
11 files changed
Lines changed: 1304 additions & 0 deletions
File tree
- examples/distributed/udf-library
- python/tests
- src
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| 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 | + | |
| 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 | + | |
| 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 | + | |
0 commit comments