-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix bug with to_timestamp
and InitCap
logical serialization, add roundtrip test between expression and proto,
#8868
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db9fe5d
add roundtrip test between expression and proto
Weijun-H b8bb3ff
fic clippy
Weijun-H e978497
Merge remote-tracking branch 'apache/main' into add-expre-serilize-test
alamb f211c50
Fix other functions, improve test logic
alamb 0a41737
Move dependency
alamb da7fdb8
fix toml fmt
Weijun-H fc6a3cb
Update datafusion/proto/tests/cases/serialize.rs
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,3 +243,40 @@ fn context_with_udf() -> SessionContext { | |
|
||
ctx | ||
} | ||
|
||
#[test] | ||
fn test_expression_serialization_roundtrip() { | ||
use datafusion_common::ScalarValue; | ||
use datafusion_expr::expr::ScalarFunction; | ||
use datafusion_expr::BuiltinScalarFunction; | ||
use datafusion_proto::logical_plan::from_proto::parse_expr; | ||
use datafusion_proto::protobuf::LogicalExprNode; | ||
use strum::IntoEnumIterator; | ||
|
||
let ctx = SessionContext::new(); | ||
let lit = Expr::Literal(ScalarValue::Utf8(None)); | ||
for builtin_fun in BuiltinScalarFunction::iter() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍 |
||
// default to 4 args (though some exprs like substr have error checking) | ||
let num_args = match builtin_fun { | ||
BuiltinScalarFunction::Substr => 3, | ||
_ => 4, | ||
}; | ||
let args: Vec<_> = std::iter::repeat(&lit).take(num_args).cloned().collect(); | ||
let expr = Expr::ScalarFunction(ScalarFunction::new(builtin_fun, args)); | ||
|
||
let proto = LogicalExprNode::try_from(&expr).unwrap(); | ||
let deserialize = parse_expr(&proto, &ctx).unwrap(); | ||
|
||
let serialize_name = extract_function_name(&expr); | ||
let deserialize_name = extract_function_name(&deserialize); | ||
|
||
assert_eq!(serialize_name, deserialize_name); | ||
} | ||
|
||
/// Extracts the first part of a function name | ||
/// 'foo(bar)' -> 'foo' | ||
fn extract_function_name(expr: &Expr) -> String { | ||
let name = expr.display_name().unwrap(); | ||
name.split('(').next().unwrap().to_string() | ||
} | ||
} |
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.
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.
💯 for testing @Weijun-H -- your test also found two other functions with similar problems to #8847 👏
I took the liberty of fixing them