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: add the concise way for matching numerics #5537

Merged
merged 2 commits into from
Mar 10, 2023
Merged

Minor: add the concise way for matching numerics #5537

merged 2 commits into from
Mar 10, 2023

Conversation

izveigor
Copy link
Contributor

@izveigor izveigor commented Mar 9, 2023

Rationale for this change

The array "NUMERICS", that are defined in the file "datafusion/expr/src/type_coercion/aggregates.rs" (see https://github.com/apache/arrow-datafusion/blob/main/datafusion/expr/src/type_coercion/aggregates.rs#L30-L41) contains all types, which found in many "match" and "matches!" cases.

I think this PR suggests more concise way for these cases.

What changes are included in this PR?

Rewritten "match" statements and "matches!" macros.

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Mar 9, 2023
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 like a nice cleanup to me -- thank you @izveigor

other => Err(DataFusionError::Plan(format!(
"VAR does not support {other:?}"
))),
if NUMERICS.contains(&arg_type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 this is very close to https://docs.rs/arrow/34.0.0/arrow/datatypes/enum.DataType.html#method.is_numeric except that is_numeric also includes Decimals.

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.

other => Err(DataFusionError::Plan(format!(
"VAR does not support {other:?}"
))),
if NUMERICS.contains(arg_type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we can reuse Datatype::is_numeric()

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 the DataType::is_numeric also includes Decimals 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, perhaps we can do a helper method checking is_numeric and exclude decimals.

Copy link
Contributor

Choose a reason for hiding this comment

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

sort of

fn is_numeric(arg_type: &DataType) -> bool {
    return arg_type.is_numeric() && match arg_type {
        Decimal128(_, _) | Decimal() => false
        _ => true
    } 
}

Copy link
Member

@jackwener jackwener left a comment

Choose a reason for hiding this comment

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

Make sense to me. A good job to cleanup

@alamb alamb merged commit ac5676f into apache:main Mar 10, 2023
@alamb
Copy link
Contributor

alamb commented Mar 10, 2023

Thanks everyone!

@ursabot
Copy link

ursabot commented Mar 10, 2023

Benchmark runs are scheduled for baseline = 8c34ca4 and contender = ac5676f. ac5676f is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants