Skip to content

fix(ffi): forward ScalarUDF propagate_constraints across FFI - #27889

Open
hieuvu0611 wants to merge 1 commit into
apache:mainfrom
hieuvu0611:fix/issue-22330-ffi-propagate-constraints
Open

hieuvu0611 wants to merge 1 commit into
apache:mainfrom
hieuvu0611:fix/issue-22330-ffi-propagate-constraints

Conversation

@hieuvu0611

@hieuvu0611 hieuvu0611 commented Dec 1, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

FFI_ScalarUDF did not carry a function pointer for ScalarUDFImpl::propagate_constraints, so ForeignScalarUDF fell back to the default trait implementation (Ok(Some(vec![]))). Any scalar UDF loaded across the FFI boundary silently lost producer-defined interval constraint propagation during optimization.

What changes are included in this PR?

  • Append pub propagate_constraints to the end of FFI_ScalarUDF (after output_ordering to avoid reordering existing #[repr(C)] fields) using the existing FFI_Interval, SVec, FFI_Option, and FFI_Result wrappers—matching the signature and conventions of FFI_PhysicalExpr::propagate_constraints.
  • Add propagate_constraints_fn_wrapper, wire it in From<Arc<ScalarUDF>> for FFI_ScalarUDF, and implement ScalarUDFImpl::propagate_constraints on ForeignScalarUDF.
  • Add unit tests in datafusion/ffi/src/udf/mod.rs covering local-bypass, forced-foreign (mock_foreign_marker_id), multi-input bound tightening in argument order, unbounded endpoints, infeasible Ok(None), error propagation, and default Ok(Some(vec![])) (AbsFunc).
  • Extend the existing PlacementUDF test fixture (datafusion/ffi/src/tests/udf_udaf_udwf.rs) and cross-library cdylib integration test (datafusion/ffi/integration-tests/tests/cases/udf.rs) to verify the same cases across an actual dlopen FFI boundary.

What is the testing strategy for this PR?

  • Unit tests (cargo test -p datafusion-ffi): udf::tests::test_ffi_udf_propagate_constraints_round_trip and udf::tests::test_round_trip_scalar_udf (131 passed).
  • Cross-library cdylib integration tests (cargo test -p datafusion-ffi -p datafusion-ffi-integration-tests --features integration-tests): cases::udf::tests::test_scalar_udf_placement (134 unit + 37 integration tests passed; re-verified locally on Rust 1.100.1, full 1.99.1 matrix covered by fork CI).
  • Formatting and lints: cargo fmt --all -- --check and cargo clippy --no-deps -p datafusion-ffi -p datafusion-ffi-integration-tests --all-targets --all-features -- -D warnings.

Are there any user-facing changes?

Yes — this adds a new field to #[repr(C)] pub struct FFI_ScalarUDF, which is an ABI/layout break for datafusion-ffi targeting main only (no backport).

  • Request for committers: could you please add the api change label? (As an external fork PR, I cannot apply labels directly.)
  • Disclosure per ai-policy.md: AI tooling was used to assist with research and drafting; I have reviewed and verified all changes end-to-end.

@github-actions github-actions Bot added the ffi Changes to the ffi crate label Dec 1, 2026
Plumb `ScalarUDFImpl::propagate_constraints` through `FFI_ScalarUDF` and
`ForeignScalarUDF` using the existing `FFI_Interval` wrapper so producer
constraint-propagation overrides survive the FFI boundary instead of
falling back to the default `Ok(Some(vec![]))`.

Part of apache#22330.
@hieuvu0611
hieuvu0611 force-pushed the fix/issue-22330-ffi-propagate-constraints branch from de85329 to 40dd0bf Compare December 3, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ffi Changes to the ffi crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant