Improve ergonomics of physical expr lit#2828
Merged
liukun4515 merged 3 commits intoapache:masterfrom Jul 3, 2022
Merged
Conversation
alamb
commented
Jul 2, 2022
| expressions::col("a", &schema)?, | ||
| Operator::Gt, | ||
| expressions::lit(ScalarValue::from(1u32)), | ||
| expressions::lit(1u32), |
Contributor
Author
There was a problem hiding this comment.
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> { |
Contributor
Author
There was a problem hiding this comment.
Here is the actual change. It isn't the most beautiful code but I think it is reasonable
Member
There was a problem hiding this comment.
This could also be written slightly more concisely as a match:
let scalar_value = match value.lit() {
Expr::Literal(v) => v,
_ => unreachable!()
};
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.
|
yjshen
approved these changes
Jul 3, 2022
liukun4515
approved these changes
Jul 3, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
litin physical expr easier to useAre there any user-facing changes?
Yes, but they are backwards compatible