Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Add Column::from(Tableref, &FieldRef), Expr::from(Column) and Expr::from(Tableref, &FieldRef) #10178

Merged
merged 5 commits into from
Apr 23, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Apr 22, 2024

Which issue does this PR close?

Follow on to #9595 from @haohuaijin

Rationale for this change

@appletreeisyellow and I noticed this while upgrading IOx -- there are times when the code would like to create Expr::Column that reference each of the columns in a schema

To do so it would be nice to be able to create a Column directly from a &FieldRef rather than having to to first call .as_ref() on the `FieldRef

What changes are included in this PR?

Changes:

  1. Add Column::from(Tableref, &FieldRef)
  2. Add Expr::from(Column)
  3. Add Expr::from(Tableref, &FieldRef)
  4. Change some code to use the new API
  5. Add example

Are these changes tested?

By existing tests

Are there any user-facing changes?

@github-actions github-actions bot added sql SQL Planner logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate labels Apr 22, 2024
@@ -346,6 +348,13 @@ impl From<(Option<&TableReference>, &Field)> for Column {
}
}

/// Create a column, use qualifier and field name
impl From<(Option<&TableReference>, &FieldRef)> for Column {
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 new API -- the rest of this PR updates the code to use it when possible

.map(|(qualifier, field)| {
Expr::Column(Column::from((qualifier, field.as_ref())))
})
.map(Column::from)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we still use a single map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call -- I added some more Expr::from impls in c4bc7e3 and now this looks pretty nice

@alamb alamb changed the title Minor: Add Column::from(Tableref, &FieldRef) Minor: Add Column::from(Tableref, &FieldRef), Expr::from(Column) and Expr::from(Tableref, &FieldRef) Apr 22, 2024
.map(|(qualifier, field)| {
Expr::Column(Column::from((qualifier, field.as_ref())))
})
.map(Expr::from)
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 now pretty nice I think given @comphead 's suggestion ❤️

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

lgtm thanks @alamb
CIL testdoc keeps failing

@alamb
Copy link
Contributor Author

alamb commented Apr 22, 2024

lgtm thanks @alamb CIL testdoc keeps failing

Thanks -- fixed in 4db07ee

Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

Thanks @alamb

Copy link
Contributor

@haohuaijin haohuaijin left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @alamb

@alamb alamb merged commit 089a42a into apache:main Apr 23, 2024
23 checks passed
@alamb
Copy link
Contributor Author

alamb commented Apr 23, 2024

Thanks everyone for the reviews ❤️

@alamb alamb deleted the alamb/nicer_column_api branch April 23, 2024 13:15
ccciudatu pushed a commit to hstack/arrow-datafusion that referenced this pull request Apr 26, 2024
…and `Expr::from(Tableref, &FieldRef)` (apache#10178)

* Minor: Add `Column::from(Tableref, &FieldRef)`

* Add Expr::from()

* fix docs

* Fix doc test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants