Skip to content

fix: preserve scheduling and evaluation properties across FFI - #25245

Open
0utsights wants to merge 2 commits into
apache:mainfrom
0utsights:fix/ffi-plan-properties-25153
Open

0utsights wants to merge 2 commits into
apache:mainfrom
0utsights:fix/ffi-plan-properties-25153

Conversation

@0utsights

Copy link
Copy Markdown

Which issue does this PR close?

Closes #25153.

Rationale for this change

A foreign execution plan loses its scheduling and evaluation properties when converted into native PlanProperties. A cooperative, eager producer becomes noncooperative and lazy on the consumer side, changing the metadata used by EnsureCooperative.

What changes are included in this PR?

Add FFI enums and producer callbacks for scheduling_type and evaluation_type, and restore both values during foreign plan-property reconstruction. Preserve the existing local-marker shortcut and ownership/release paths.

This is AI-assisted work and remains a draft pending the contributor's end-to-end review of the implementation and ABI implications.

What is the testing strategy for this PR?

Unit tests exercise every scheduling/evaluation variant through local and forced foreign conversions. A separate-library integration test checks both nondefault properties on a ForeignExecutionPlan and verifies that EnsureCooperative leaves the already cooperative leaf unwrapped. The foreign regressions fail on the baseline and pass with the fix.

Validation on Linux x86_64 with Rust 1.97.0:

  • Workspace formatting and Clippy with all targets, all features, and warnings denied pass.
  • Default FFI tests: 121 passed. FFI tests with integration-tests: 156 passed, including the separately loaded .so regression.
  • The complete extended workspace test command from AGENTS.md passes, including the core fuzz and SQL logic suites.
  • Workspace Rust documentation with warnings denied, documentation formatting, and workflow policy checks pass. License, spelling, and TOML checks also pass on the same patch.

The FFI integration suite also passes on Windows with a separately loaded DLL. Both sides use the same source/toolchain in each test; mixed-toolchain compatibility and a runtime speedup were not measured.

Are there any user-facing changes?

Foreign execution plans retain their producer's scheduling and evaluation metadata. This changes the FFI_PlanProperties layout and requires downstream libraries to rebuild for the new major version. This PR targets main and must not be backported to a patch release. Please apply the api change label before merge.

@github-actions github-actions Bot added the ffi Changes to the ffi crate label Sep 12, 2026
@0utsights
0utsights marked this pull request as ready for review September 14, 2026 02:25
@github-actions

Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).

Details
     Cloning apache/main
    Building datafusion-ffi v55.1.0 (current)
       Built [  50.278s] (current)
     Parsing datafusion-ffi v55.1.0 (current)
      Parsed [   0.053s] (current)
    Building datafusion-ffi v55.1.0 (baseline)
       Built [  44.117s] (baseline)
     Parsing datafusion-ffi v55.1.0 (baseline)
      Parsed [   0.054s] (baseline)
    Checking datafusion-ffi v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   0.284s] 223 checks: 221 pass, 1 fail, 1 warn, 31 skip

--- failure constructible_struct_adds_field: struct exhaustively constructible through public API adds field ---

Description:
A pub struct that could be exhaustively constructed with a literal using only public API has a new pub field, breaking existing exhaustive literals.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field FFI_PlanProperties.scheduling_type in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/plan_properties.rs:51
  field FFI_PlanProperties.evaluation_type in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/plan_properties.rs:54

--- warning repr_c_plain_struct_fields_reordered: struct fields reordered in repr(C) struct ---

Description:
A public repr(C) struct had its fields reordered. This can change the struct's memory layout, possibly breaking FFI use cases that depend on field position and order.
        ref: https://doc.rust-lang.org/reference/type-layout.html#reprc-structs
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/repr_c_plain_struct_fields_reordered.ron

Failed in:
  FFI_PlanProperties.output_ordering moved from position 4 to 6, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/plan_properties.rs:57
  FFI_PlanProperties.schema moved from position 5 to 7, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/plan_properties.rs:61
  FFI_PlanProperties.release moved from position 6 to 8, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/plan_properties.rs:64
  FFI_PlanProperties.private_data moved from position 7 to 9, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/plan_properties.rs:68
  FFI_PlanProperties.library_marker_id moved from position 8 to 10, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/plan_properties.rs:73

     Summary semver requires new major version: 1 major and 0 minor checks failed
     Warning produced 1 major and 0 minor level warnings
    Finished [  96.791s] datafusion-ffi

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Sep 15, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.80519% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.90%. Comparing base (38d58ed) to head (c7b5913).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/ffi/src/plan_properties.rs 93.65% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25245      +/-   ##
==========================================
- Coverage   81.90%   81.90%   -0.01%     
==========================================
  Files        1134     1134              
  Lines      425217   425288      +71     
  Branches   425217   425288      +71     
==========================================
+ Hits       348289   348341      +52     
- Misses      56288    56299      +11     
- Partials    20640    20648       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The FFI ABI change requires a major-version compatibility gate and human review.

Pull request overview

Preserves scheduling and evaluation metadata across the DataFusion FFI boundary.

Changes:

  • Adds FFI enums and callbacks for scheduling/evaluation types.
  • Restores both properties during foreign-plan reconstruction.
  • Adds local and cross-library regression tests.

Blocking review note: The FFI layout changes without a corresponding major-version compatibility gate, risking ABI corruption for existing consumers.

File summaries
File Description
datafusion/ffi/tests/ffi_execution_plan.rs Verifies metadata preservation and optimizer behavior across libraries.
datafusion/ffi/src/tests/mod.rs Configures test plans with nondefault properties.
datafusion/ffi/src/plan_properties.rs Implements metadata transport, reconstruction, and round-trip tests.
datafusion/ffi/src/execution_plan.rs Adds test-plan property builders.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread datafusion/ffi/src/plan_properties.rs

@timsaucer timsaucer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty clean, just one question. I'll also let the AI take a look before hitting the approve. Thank you for the contribution.

Comment on lines +598 to +612
pub fn with_scheduling_type(
mut self,
scheduling_type: datafusion_physical_plan::execution_plan::SchedulingType,
) -> Self {
Arc::make_mut(&mut self.props).scheduling_type = scheduling_type;
self
}

pub fn with_evaluation_type(
mut self,
evaluation_type: datafusion_physical_plan::execution_plan::EvaluationType,
) -> Self {
Arc::make_mut(&mut self.props).evaluation_type = evaluation_type;
self
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this all necessary? EmptyExec is just a test execution plan - is there any reason not to just set those properties by default?

@timsaucer timsaucer added the api change Changes the API exposed to users of the crate label Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the API exposed to users of the crate auto detected api change Auto detected API change ffi Changes to the ffi crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FFI_PlanProperties drops scheduling_type and evaluation_type, so every plan crossing FFI misreports both

4 participants