Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Dec 15, 2025

Which issue does this PR close?

  • Closes #.

Rationale for this change

While reviewing the code from @pepijnve in #19287 I noticed it was a little awkward to create ProjectionExpr from constants. Let's add a nicer signature for that.

Instead of

                ProjectionExpr::new(lit("0"), "l".to_string()),

Do

                ProjectionExpr::new(lit("0"), "l"),

What changes are included in this PR?

  1. Add new method and simplicy some tests

Are these changes tested?

By CI

Are there any user-facing changes?

A slightly nicer API

@github-actions github-actions bot added physical-expr Changes to the physical-expr crates core Core DataFusion crate datasource Changes to the datasource crate labels Dec 15, 2025
impl ProjectionExpr {
/// Create a new projection expression
pub fn new(expr: Arc<dyn PhysicalExpr>, alias: String) -> Self {
pub fn new(expr: Arc<dyn PhysicalExpr>, alias: impl Into<String>) -> Self {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the actual code change, the rest of the PR is cleaning up callsites

let proj_expr = vec![ProjectionExpr::new(
Arc::new(Column::new_with_schema("value", &input_schema)?) as _,
"value".to_string(),
"value",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The underlying ProjectionExpr is still the same, this PR just makes it easier to make them

let projection: Arc<dyn ExecutionPlan> = Arc::new(ProjectionExec::try_new(
vec![
ProjectionExpr::new(Arc::new(Column::new("d", 2)), "d".to_string()),
ProjectionExpr::new(Arc::new(Column::new("e", 3)), "e".to_string()),
Copy link
Member

Choose a reason for hiding this comment

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

Why d and e are not simplified here ?
They look exactly the same as a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is an excellent catch -- done in 99edf9d

@alamb
Copy link
Contributor Author

alamb commented Dec 17, 2025

Thank you @adriangb and @martin-g

@alamb alamb added this pull request to the merge queue Dec 17, 2025
Merged via the queue into apache:main with commit 2e95f26 Dec 17, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate datasource Changes to the datasource crate physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants