Skip to content

Add Expr->String for ScalarFunction and InList - #9759

Merged
alamb merged 3 commits into
apache:mainfrom
yyy1000:port
Mar 24, 2024
Merged

alamb merged 3 commits into
apache:mainfrom
yyy1000:port

Conversation

@yyy1000

@yyy1000 yyy1000 commented Mar 23, 2024

Copy link
Copy Markdown
Contributor

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 SQL Planner label Mar 23, 2024
args: vec![col("a"), col("b")],
}),
r#"dummy_udf("a", "b")"#,
),

Copy link
Copy Markdown
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
Copy Markdown
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

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread datafusion/sql/src/unparser/expr.rs Outdated
r#"CAST("a" AS INTEGER UNSIGNED)"#,
),
(
Expr::InList(InList {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread datafusion/sql/src/unparser/expr.rs Outdated
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
Copy Markdown
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
Copy Markdown
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!

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

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
@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

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants