Skip to content

refactor(datafusion): group node conversion logic by expression - #11507

Open
danking wants to merge 1 commit into
dk/one-step-expression-converterfrom
dk/one-step-expression-converter-cleanup
Open

danking wants to merge 1 commit into
dk/one-step-expression-converterfrom
dk/one-step-expression-converter-cleanup

Conversation

@danking

@danking danking commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

I basically introduce two result type aliases: MayConvert and MustConvert. They have different ? semantics: May is, effectively, Result<Unsupported, Result<T, Err>> so it bails out on the first successful conversion. Must is, effectively, Result<T, Result<Unsupported, Err>> so it bails out when something is unsupported or error.

That lets me write conversions like:

    ConvertRowIndex::recognize_boxed(expr, ctx)?;
    ConvertBinary::recognize_boxed(expr, ctx)?;

And the first one that converts successfully returns.

Those types are also exposed so you can either use default_convert which tries all Vortex defaults in Vortex order or you can build your conversion function yourself directly from the individual conversions.

The conversions are just some state plus a convert (which checks for a convertible DF type) and a construct (which consumes the state and the converted children to produce the Vortex expression).

@codspeed

codspeed Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 2052 untouched benchmarks
⏩ 142 skipped benchmarks1


Comparing dk/one-step-expression-converter-cleanup (7fceb7d) with dk/one-step-expression-converter (2ec7528)

Open in CodSpeed

Footnotes

  1. 142 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@danking
danking force-pushed the dk/one-step-expression-converter branch from dfa887b to aac7b1e Compare November 16, 2026 20:12
@danking
danking force-pushed the dk/one-step-expression-converter-cleanup branch from 2d72f0c to 2847d23 Compare November 16, 2026 20:12
@danking danking changed the title refactor(datafusion): organize node conversion with Convertible refactor(datafusion): split Convertible implementations by expression Nov 16, 2026
@danking
danking force-pushed the dk/one-step-expression-converter-cleanup branch from 2847d23 to e7979f2 Compare November 16, 2026 21:00
@danking
danking force-pushed the dk/one-step-expression-converter branch from aac7b1e to 08a9966 Compare November 16, 2026 21:00
@danking danking changed the title refactor(datafusion): split Convertible implementations by expression refactor(datafusion): group conversion with typed Convertible implementations Nov 16, 2026
@danking
danking force-pushed the dk/one-step-expression-converter branch from 08a9966 to 65ea32a Compare November 16, 2026 21:34
@danking
danking force-pushed the dk/one-step-expression-converter-cleanup branch from e7979f2 to 583e699 Compare November 16, 2026 21:34
@danking danking changed the title refactor(datafusion): group conversion with typed Convertible implementations refactor(datafusion): group node conversion logic by expression Nov 16, 2026
@danking
danking force-pushed the dk/one-step-expression-converter branch from 65ea32a to 65117ce Compare November 16, 2026 21:56
@danking
danking force-pushed the dk/one-step-expression-converter-cleanup branch 7 times, most recently from 3a6a18a to d1994a2 Compare November 17, 2026 21:47

danking commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @danking's task in 1m 57s —— View job


Review of #11507: per-expression converters

  • Gather context (diff vs dk/one-step-expression-converter)
  • Review convertible/mod.rs
  • Review convertible/impls.rs
  • Review exprs/mod.rs and tests
  • Post findings

The design works well. Scoped::{Same, With} keeps lambda scope with the child that needs it, so ConvertArrayTransform is no longer a special case in convert_tree. The MayConvert/MustConvert pair with ? makes the default_convert* dispatch chains easy to read. Most conversions behave the same as on the base branch. The ConvertArrayTransform element-dtype check after substitution is a good addition. I found one performance regression, a few likely lint/fmt failures, and some API gaps.

Issues

1. IN-list deduplication removed (performance regression on hash-join filters). impls.rs:555-563
The base branch deduplicated elements before import:

// The list of a hash join filter holds every build-side key, which repeat. Each element
// converts through Arrow, so equal values with equal metadata are converted once.
.unique_by(|element| element.downcast_ref::<df_expr::Literal>().cloned())

ConvertInList::convert now calls import_literal_for_operand for every element. Each call builds an Arrow array and creates an execution context, so a dynamic join filter with thousands of repeated build keys does that much more work. test_in_list_drops_repeated_elements still passes because in_list_of deduplicates the output, so no test catches this. The 62 CodSpeed regressions are not evidence either way: that report compared against develop in a different environment, and none of the regressed benchmarks touch this code. Fix this →

2. The IN-list fallback path is effectively dead. impls.rs:566-573
If an element import returns Unsupported, the code re-selects the literals as children and converts them through ConvertLiteral.

  • When the operand has no extension, import_literal_for_operand makes the same import_literal call that ConvertLiteral would, so the retry fails the same way.
  • When the operand has an extension, the literal is re-imported as plain storage, and in_list_of then rejects it against the extension value_dtype.

Both cases end as Unsupported after doing the work twice. Propagating Unsupported directly would let you drop the Option<Vec<Scalar>>, the n_children bookkeeping and the as_opt::<Literal> branch in construct. Also, None => Err(Ok(Unsupported)) at line 560 can never run, because line 538 already checks that every element is a Literal.

3. Likely clippy -D warnings failures (useless_conversion). Err(Err(exec_datafusion_err!(..).into())) converts DataFusionError into itself. This happens at impls.rs:838, 879, 920, 958 and 1054. The stack's CI only ran a skipped matrix, so these have not been checked yet.

4. The files do not look rustfmt-clean. Several lines are over 100 columns: impls.rs:184, 206, 212, 219, 226, 280, 360, 591, 627, 664, 682, 719 and 1076. Imports are also out of order: use super::Scoped; comes before Constructible (impls.rs:68), and use self::convertible::Scoped; comes before ConvertibleCtx (exprs/mod.rs:32). use crate::convert::exprs::convertible::may; could be super::may and grouped with the other super:: imports. Running cargo +nightly-<pinned> fmt -p vortex-datafusion should fix all of this.

5. The public API is not quite enough to compose a custom dispatch chain. The PR description says the goal is to let callers compose converters, but:

  • must and may are pub(super). Convertible::convert_recursive returns MustConvert, so a downstream crate writing its own version of default_convert_recursive (for example, default converters plus a custom UDF) has to re-implement may.
  • ConvertibleCtx::node_dtype, import_literal and import_literal_for_operand are private or pub(super). Downstream construct implementations can't run the same dtype checks (ensure_string, the comparison dtype match) as the built-in converters.

Consider making must, may and node_dtype pub, or wrapping them in methods. A doctest that composes ConvertBinary with a custom converter would cover this. Also, pub use exprs::convertible::* re-exports the module glob into vortex_datafusion::convert. The glob will also pick up anything later made pub, so an explicit list may be safer.

Smaller points

  • Unreachable binary arm: ConvertBinary (Some(left), Some(right)) (impls.rs:181, 224). recognize_literal returns Some only when this side is a literal with no extension and the other side has one. Both sides can't satisfy that at once, so the arm can be unreachable! or merged away.
  • Duplicated converters: ConvertContains, ConvertStartsWith and ConvertEndsWith are about 40 lines each and differ only in the function type and pattern format. A generic ConvertLikePattern<F> (or a shared helper for convert_fixed) would shrink them. The base branch shared this logic through like_pattern: fn(&str) -> String.
  • Lost explanatory comments. These from the base branch were non-obvious and worth restoring:
    • Cast nullability: "DataFusion casts preserve input nulls even when the target field is declared non-nullable…". The new TODO(DK): why are we able to ignore nullability? at impls.rs:373 asks the question this comment answered.
    • CASE: conditions and values are evaluated lazily, so fallible children keep DataFusion's short-circuit behaviour. This is why ConvertCase alone skips the is_infallible check.
    • GetFieldFunc flattens nested access into one call with multiple path arguments.
    • The array_sum doc on null and NaN semantics.
    • Strpos: DataFusion only returns Int32 for strings with 32-bit offsets, so the narrowing cast can't overflow.
    • "Only a literal needle becomes a LIKE pattern that encodings and stats can use."
  • Confusing trait method names: Convertible::convert and ConvertibleFixedArity::convert_fixed don't convert anything. They select children and capture state, while recognize wraps the downcast. Something like select/select_fixed would make the recognize → recurse → construct steps clearer to implementors.
  • Element dtype source in ConvertArrayTransform: ConvertArrayTransform::convert_fixed now derives the element dtype from DataFusion's list.return_field instead of the converted list's Vortex dtype. The check in construct_fixed (impls.rs:1018) covers mismatches, so this is fine. The nullability-insensitive comparison does mean the body may have been typed against an element nullability that differs from the substituted list's; that is probably harmless, but worth a sentence in the comment.
  • Unresolved FIXME: // FIXME(DK): this should resolve by index into the schema (impls.rs:284). This is OK for now because convert_checked checks that names match indices, but it should get a tracking issue or be removed before merge.

Verification

I did not run clippy, fmt or tests; per CLAUDE.md, checks are your call. I suggest cargo clippy -p vortex-datafusion --all-targets --all-features -- -D warnings and the pinned-nightly fmt -p vortex-datafusion to confirm points 3 and 4.

@danking
danking force-pushed the dk/one-step-expression-converter-cleanup branch 3 times, most recently from 813cef5 to 1bac715 Compare November 19, 2026 18:08
@danking
danking force-pushed the dk/one-step-expression-converter branch from 65117ce to cd0142b Compare November 19, 2026 18:08
@danking
danking marked this pull request as ready for review November 19, 2026 19:12
@danking danking added the changelog/feature A new feature label Nov 23, 2026
Expose per-expression Convertible implementations with typed DataFusion matching, fixed-arity construction, and caller-owned recursion. Use MustConvert and MayConvert to distinguish unsupported expressions from conversion errors, with shared schema, session, and scope supplied through ConvertibleCtx. Return Scoped::Same and Scoped::With inputs to the recursion callback and convert array_transform through the same protocol. Provide both concrete and boxed construction paths while preserving the established ExpressionConverter interface.

Signed-off-by: Daniel King <dan@spiraldb.com>
@danking
danking force-pushed the dk/one-step-expression-converter branch from cd0142b to 2ec7528 Compare November 23, 2026 22:29
@danking
danking force-pushed the dk/one-step-expression-converter-cleanup branch from 1bac715 to 7fceb7d Compare November 23, 2026 22:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant