-
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
Add Expr->String for ScalarFunction and InList #9759
Conversation
args: vec![col("a"), col("b")], | ||
}), | ||
r#"dummy_udf("a", "b")"#, | ||
), |
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 think for ScalarFunction
, it's better to add test cases for UDF
and BuiltIn
.
But since the function port work is going to be finished, I doubt whether it's necessary to do that. :)
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.
Since there is no code specific to BuiltInScalarFunction
in the unparser code, I agree there is no reason to add a specific test here
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.
Thank you @yyy1000 -- I think this PR could be merged as is. I left some suggested improvements, but I also think they could be done as follow on PRs
datafusion/sql/src/unparser/expr.rs
Outdated
@@ -561,6 +636,31 @@ mod tests { | |||
}), | |||
r#"CAST("a" AS INTEGER UNSIGNED)"#, | |||
), | |||
( | |||
Expr::InList(InList { |
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 think you can write this more concisely with the expr API -- https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html#method.in_list
Something like
col("a").in(vec![lit(1), lit(2), lit(3)])
Likewise for NOT IN
col("a").not_in(vec![lit(1), lit(2), lit(3)])
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.
That's very cool!
args: vec![col("a"), col("b")], | ||
}), | ||
r#"dummy_udf("a", "b")"#, | ||
), |
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.
Since there is no code specific to BuiltInScalarFunction
in the unparser code, I agree there is no reason to add a specific test here
datafusion/sql/src/unparser/expr.rs
Outdated
Expr::ScalarFunction(ScalarFunction { | ||
func_def: ScalarFunctionDefinition::UDF(Arc::new( | ||
ScalarUDF::new_from_impl(DummyUDF::new()), | ||
)), | ||
args: vec![col("a"), col("b")], | ||
}), |
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.
How about using the call API https://docs.rs/datafusion/latest/datafusion/logical_expr/struct.ScalarUDF.html#method.call
ScalarUDF::new_from_impl(DummyUDF::new())
.call(vec![col("a"), col("b")])
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.
Love this, more concise!
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.
Looks great -- thanks again @yyy1000
Which issue does this PR close?
Related #9726.
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?