Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Nov 8, 2022

Draft as it builds on #4148

Which issue does this PR close?

Closes #3702

Rationale for this change

This will make predicate evaluation on unsigned columns faster in some cases

What changes are included in this PR?

  1. Add support for unsigned columns
  2. Add tests (using the harness I wrote in Add additional testing for unwrap_cast_in_comparison #4147)

Are these changes tested?

Yes

Are there any user-facing changes?

Predicates on unsigned columns should be faster

@github-actions github-actions bot added optimizer Optimizer rules core Core DataFusion crate labels Nov 8, 2022
@alamb alamb force-pushed the alamb/unwrap_unsigned_casts branch from d8fa119 to 23ca07a Compare November 12, 2022 11:22
@alamb alamb marked this pull request as ready for review November 12, 2022 11:24
@alamb alamb requested a review from liukun4515 November 12, 2022 11:24
@alamb
Copy link
Contributor Author

alamb commented Nov 12, 2022

Here is the next PR for unwrapping casts for your review @liukun4515

"Explain [plan_type:Utf8, plan:Utf8]",
" Projection: t1.t1_id, t1.t1_name, t1.t1_int, t2.t2_id, t2.t2_name, t2.t2_int [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" Inner Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" Filter: CAST(t1.t1_id AS Int64) < Int64(100) [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🎉 the casts have been removed!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the original regression noted in #3699 (comment) that lead to #3702

/// Until https://github.com/apache/arrow-rs/issues/1043 is done
/// (support for unsigned <--> decimal casts) we also don't do that
/// kind of cast in this optimizer
fn is_unsupported_cast(dt1: &DataType, dt2: &DataType) -> bool {
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 found this with the test (which failed when it tried to invoke the arrow cast kernels for decimal <--> unsigned)

Copy link
Contributor

Choose a reason for hiding this comment

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

Casting for unsigned value <-> decimal is not supported now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will try to implement them recently.

Copy link
Contributor

@liukun4515 liukun4515 Nov 14, 2022

Choose a reason for hiding this comment

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

// the rewriter will not throw error and just return the original expr
let schema = expr_test_schema();
let expr_input = cast(col("c6"), DataType::Int64).eq(lit(0i64));
let expr_input = cast(col("c6"), DataType::Float64).eq(lit(0f64));
Copy link
Contributor

@liukun4515 liukun4515 Nov 14, 2022

Choose a reason for hiding this comment

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

the comment of "c6 > 0" will be cast to `cast(c6 as int64) > 0 should be change to "c6 > 0"` will be cast to `cast(c6 as float64) > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c6946f0

Copy link
Contributor

@liukun4515 liukun4515 left a comment

Choose a reason for hiding this comment

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

LGTM @alamb Thanks for your test
There is a bit comments.

@alamb alamb merged commit 4653df4 into apache:master Nov 15, 2022
@ursabot
Copy link

ursabot commented Nov 15, 2022

Benchmark runs are scheduled for baseline = c9361e0 and contender = 4653df4. 4653df4 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

core Core DataFusion crate optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support unsigned numeric data type in UnwrapCastInBinaryComparison rule

3 participants