Skip to content

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

Merged
alamb merged 5 commits into
apache:mainfrom
alamb:alamb/nicer_column_api
Apr 23, 2024
Merged

Minor: Add Column::from(Tableref, &FieldRef), Expr::from(Column) and Expr::from(Tableref, &FieldRef)#10178
alamb merged 5 commits into
apache:mainfrom
alamb:alamb/nicer_column_api

Conversation

@alamb

@alambalamb commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

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-actionsgithub-actionsBot added sql SQL Planner logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate labels Apr 22, 2024
}

/// Create a column, use qualifier and field name
impl From<(Option<&TableReference>, &FieldRef)> for Column {

Copy link
Copy Markdown
ContributorAuthor

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

Comment threadbenchmarks/src/tpch/convert.rs Outdated
.map(|(qualifier, field)| {
Expr::Column(Column::from((qualifier, field.as_ref())))
})
.map(Column::from)

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.

can we still use a single map?

Copy link
Copy Markdown
ContributorAuthor

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

@alambalamb 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
Copy Markdown
ContributorAuthor

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 ❤️

@compheadcomphead 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.

lgtm thanks @alamb
CIL testdoc keeps failing

@alamb

Copy link
Copy Markdown
ContributorAuthor

lgtm thanks @alamb CIL testdoc keeps failing

Thanks -- fixed in 4db07ee

@andygroveandygrove 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.

Thanks @alamb

@haohuaijinhaohuaijin 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.

LGTM, thank you @alamb

@alamb
alamb merged commit 089a42a into apache:mainApr 23, 2024
@alamb

Copy link
Copy Markdown
ContributorAuthor

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/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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coreCore DataFusion cratelogical-exprLogical plan and expressionsoptimizerOptimizer rulessqlSQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@alamb@andygrove@comphead@haohuaijin