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

Minor: Cleanup BuiltinScalarFunction's phys-expr creation #8114

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

2010YOUY01
Copy link
Contributor

Which issue does this PR close?

Cleanup for #8045

Rationale for this change

In current implementation, some function tries to generate input type specific physical expressions in
https://github.com/apache/arrow-datafusion/blob/308c35404939ed39e4e398054d6fc78c89817109/datafusion/physical-expr/src/functions.rs#L75-L204
However, this can be done inside function implementation like most other functions did, this PR would like to unify the implementation approach

What changes are included in this PR?

Move input-type-specific BuiltinScalarFunction physical expression creation to inside function implementation

Are these changes tested?

Covered by existing tests

Are there any user-facing changes?

No

@github-actions github-actions bot added the physical-expr Physical Expressions label Nov 10, 2023
@jonahgao
Copy link
Member

I wonder if this modification will lead to performance degradation.

Each time we evaluate the function expression, we have to pick an implementation based on the input type.
Previously, the picking was executed only once during compilation/planning.

@2010YOUY01
Copy link
Contributor Author

I wonder if this modification will lead to performance degradation.

Each time we evaluate the function expression, we have to pick an implementation based on the input type. Previously, the picking was executed only once during compilation/planning.

That's a good point, but I think for this case, the extra overhead is one or two function calls per batch(typically 8k rows)
I tried those functions on TPCH data, and there is no noticeable difference

select to_timestamp(l_shipdate), to_timestamp_seconds(l_commitdate), to_timestamp_millis(l_receiptdate), to_timestamp_micros(l_shipdate), to_timestamp_nanos(l_shipdate), from_unixtime(l_orderkey), abs(l_orderkey) from lineitem;

@@ -17,6 +17,8 @@

//! DateTime expressions

use crate::datetime_expressions;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
use crate::datetime_expressions;

It seems that this use may not be required 🤔.

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 but clippy did not flag it

Copy link
Member

@jonahgao jonahgao left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

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 @2010YOUY01 -- looks really good

Also thank you @jonahgao for your guidance and review

@@ -17,6 +17,8 @@

//! DateTime expressions

use crate::datetime_expressions;
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 but clippy did not flag it

@@ -927,11 +811,19 @@ pub fn create_physical_fun(
}),
BuiltinScalarFunction::Upper => Arc::new(string_expressions::upper),
BuiltinScalarFunction::Uuid => Arc::new(string_expressions::uuid),
_ => {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for removing the catchall

@alamb alamb merged commit e727bbf into apache:main Nov 10, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants