Skip to content
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

Merged
merged 3 commits into from
Mar 24, 2024
Merged

Conversation

yyy1000
Copy link
Contributor

@yyy1000 yyy1000 commented Mar 23, 2024

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?

@github-actions github-actions bot added the sql label Mar 23, 2024
args: vec![col("a"), col("b")],
}),
r#"dummy_udf("a", "b")"#,
),
Copy link
Contributor Author

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. :)

Copy link
Contributor

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

Copy link
Contributor

@alamb alamb left a 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

@@ -561,6 +636,31 @@ mod tests {
}),
r#"CAST("a" AS INTEGER UNSIGNED)"#,
),
(
Expr::InList(InList {
Copy link
Contributor

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)])

Copy link
Contributor Author

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")"#,
),
Copy link
Contributor

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

Comment on lines 656 to 661
Expr::ScalarFunction(ScalarFunction {
func_def: ScalarFunctionDefinition::UDF(Arc::new(
ScalarUDF::new_from_impl(DummyUDF::new()),
)),
args: vec![col("a"), col("b")],
}),
Copy link
Contributor

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")])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Love this, more concise!

Copy link
Contributor

@alamb alamb left a 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

@alamb alamb merged commit cb9da2b into apache:main Mar 24, 2024
23 checks passed
@yyy1000 yyy1000 deleted the port branch March 24, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants