Skip to content

Improve ergonomics of physical expr lit#2828

Merged
liukun4515 merged 3 commits intoapache:masterfrom
alamb:alamb/better_lit
Jul 3, 2022
Merged

Improve ergonomics of physical expr lit#2828
liukun4515 merged 3 commits intoapache:masterfrom
alamb:alamb/better_lit

Conversation

@alamb
Copy link
Copy Markdown
Contributor

@alamb alamb commented Jul 2, 2022

Which issue does this PR close?

Closes #2827

Note this is a 10 line actual code change, and then the tests get much less verbose which is why the diff is so large

Rationale for this change

See #2827

What changes are included in this PR?

Make lit in physical expr easier to use

Are there any user-facing changes?

Yes, but they are backwards compatible

@github-actions github-actions bot added core Core DataFusion crate physical-expr Changes to the physical-expr crates labels Jul 2, 2022
@alamb alamb force-pushed the alamb/better_lit branch from 0c7a179 to 0f43039 Compare July 2, 2022 10:52
expressions::col("a", &schema)?,
Operator::Gt,
expressions::lit(ScalarValue::from(1u32)),
expressions::lit(1u32),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change shows the point of this PR pretty well

/// Create a literal expression
pub fn lit(value: ScalarValue) -> Arc<dyn PhysicalExpr> {
Arc::new(Literal::new(value))
pub fn lit<T: datafusion_expr::Literal>(value: T) -> Arc<dyn PhysicalExpr> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here is the actual change. It isn't the most beautiful code but I think it is reasonable

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.

This could also be written slightly more concisely as a match:

    let scalar_value = match value.lit() {
      Expr::Literal(v) => v,
      _ => unreachable!()
    };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I implemented this suggestion in #2838

@alamb alamb marked this pull request as ready for review July 2, 2022 10:54
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #2828 (353bbc1) into master (88b88d4) will decrease coverage by 0.08%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2828      +/-   ##
==========================================
- Coverage   85.26%   85.17%   -0.09%     
==========================================
  Files         275      275              
  Lines       48830    48564     -266     
==========================================
- Hits        41633    41366     -267     
- Misses       7197     7198       +1     
Impacted Files Coverage Δ
...ore/src/physical_optimizer/aggregate_statistics.rs 100.00% <100.00%> (ø)
...atafusion/core/src/physical_plan/aggregates/mod.rs 91.16% <100.00%> (ø)
datafusion/core/src/physical_plan/filter.rs 87.64% <100.00%> (-1.36%) ⬇️
datafusion/physical-expr/src/expressions/case.rs 92.00% <100.00%> (-0.09%) ⬇️
...physical-expr/src/expressions/get_indexed_field.rs 92.93% <100.00%> (ø)
...atafusion/physical-expr/src/expressions/in_list.rs 68.20% <100.00%> (-3.33%) ⬇️
...atafusion/physical-expr/src/expressions/literal.rs 100.00% <100.00%> (ø)
datafusion/physical-expr/src/functions.rs 92.88% <100.00%> (-1.32%) ⬇️
datafusion/expr/src/window_frame.rs 92.43% <0.00%> (-0.85%) ⬇️
datafusion/core/src/physical_plan/metrics/value.rs 86.93% <0.00%> (-0.51%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88b88d4...353bbc1. Read the comment docs.

@liukun4515 liukun4515 merged commit b47ab7c into apache:master Jul 3, 2022
@alamb alamb deleted the alamb/better_lit branch July 5, 2022 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve ergonomics of physical expr lit

5 participants