-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Improve ergonomics of physical expr lit
#2828
Conversation
@@ -525,7 +525,7 @@ mod tests { | |||
expressions::binary( | |||
expressions::col("a", &schema)?, | |||
Operator::Gt, | |||
expressions::lit(ScalarValue::from(1u32)), | |||
expressions::lit(1u32), |
There was a problem hiding this comment.
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
@@ -74,8 +74,13 @@ impl PhysicalExpr for Literal { | |||
} | |||
|
|||
/// 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> { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!()
};
There was a problem hiding this comment.
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
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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 useAre there any user-facing changes?
Yes, but they are backwards compatible