Skip to content

feat(dataframe): add column to a dataframe (#25298) - #25299

Open
cj-zhukov wants to merge 1 commit into
apache:mainfrom
cj-zhukov:cj-zhukov/add-column-to-dataframe
Open

cj-zhukov wants to merge 1 commit into
apache:mainfrom
cj-zhukov:cj-zhukov/add-column-to-dataframe

Conversation

@cj-zhukov

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

DataFrame::with_column only adds an Expr. Appending an ArrayRef today means collecting the frame, concatenating columns, and calling read_batch. That executes the plan just to change the schema. Related #9672

This PR adds a lazy API for that case: the array is stored on the plan and attached when the new DataFrame runs. No collect at the call site.

let df = DataFrame::from_columns([("id", id), ("data", data)])?;
let df = df.with_array_columns([("new_col", new_col)])?;
let df = df.filter(col("id").gt(lit(1)))?;
df.collect().await?;

What changes are included in this PR?

  • DataFrame::with_array_columns - same shape as from_columns (name + ArrayRef).
  • AddColumnProvider (TableProvider) wraps the current LogicalPlan and the new columns.
  • AddColumnExec (ExecutionPlan) zips each input batch with array.slice(offset, n) at execution time.

What is the testing strategy for this PR?

Yes. Tests cover:

  • appending a column and collecting
  • filter / select after append (still lazy)
  • length mismatch at execution
  • duplicate column name

Are there any user-facing changes?

Yes - new DataFrame::with_array_columns method. Not a breaking change. Docs and an example are included.

@github-actions github-actions Bot added the core Core DataFusion crate label Sep 14, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.28571% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.91%. Comparing base (c149764) to head (6d3f379).

Files with missing lines Patch % Lines
datafusion/core/src/dataframe/mod.rs 74.28% 38 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25299      +/-   ##
==========================================
- Coverage   81.91%   81.91%   -0.01%     
==========================================
  Files        1134     1134              
  Lines      425703   425878     +175     
  Branches   425703   425878     +175     
==========================================
+ Hits       348725   348848     +123     
- Misses      56300    56342      +42     
- Partials    20678    20688      +10     

☔ 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.

@cj-zhukov

Copy link
Copy Markdown
Contributor Author

hey @alamb @Omega359 @yyy1000
you might be interested in taking a look at this because it addresses feature that was discussed in #9672

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

Labels

core Core DataFusion crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants