Skip to content

Conversation

@jayzhan211
Copy link
Contributor

Which issue does this PR close?

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 optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Apr 5, 2025
@jayzhan211 jayzhan211 marked this pull request as draft April 5, 2025 07:34
@jayzhan211 jayzhan211 marked this pull request as ready for review April 5, 2025 13:03
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.

FYI @shehabgamin

Do you have some time to review this PR

@shehabgamin
Copy link
Contributor

FYI @shehabgamin

Do you have some time to review this PR

Yes! Will carve out some time on Monday.

Thanks @jayzhan211 !!

Copy link
Contributor

@shehabgamin shehabgamin left a comment

Choose a reason for hiding this comment

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

@jayzhan211 Nice job! Just left some minor comments :)

match BinaryTypeCoercer::new(&left_type, op, &right_type).get_result_type() {
Ok(result_type) => {
// Only cast if the types differ
if left_type != result_type {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might as well check if right_type != result_type too to be extra safe, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since we only care about left side expr, whatever right side is the result doesn't change

match BinaryTypeCoercer::new(&left_type, op, &right_type).get_result_type() {
Ok(result_type) => {
// Only cast if the types differ
if right_type != result_type {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might as well check if left_type != result_type too to be extra safe, right?

{
Ok(result_type) => {
// Only cast if the types differ
if left_type != result_type {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might as well check if right_type != result_type too to be extra safe, right?

// Check if resulting type would be different due to coercion
let left_type = info.get_data_type(&left)?;
let right_type = info.get_data_type(right)?;
match BinaryTypeCoercer::new(&left_type, &Operator::Divide, &right_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 should be op instead of &Operator::Divide

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 function is only used in Divide not other op, different op may behave differently.
In Multiple case, I switch left and right instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jayzhan211 Got it! Was going to suggest to rename the function for clarity but it looks like you did that in your latest commit!

info: &S,
left: Box<Expr>,
right: &Expr,
) -> Result<Transformed<Expr>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Pass in op: &Operator,

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 op is required if it fits well more then 1 op

Copy link
Contributor

@shehabgamin shehabgamin left a comment

Choose a reason for hiding this comment

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

@jayzhan211 jayzhan211 requested a review from alamb April 9, 2025 00:55
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.

@alamb alamb merged commit 5fa90df into apache:main Apr 10, 2025
27 checks passed
@jayzhan211 jayzhan211 deleted the simplify-bug branch April 12, 2025 01:16
nirnayroy pushed a commit to nirnayroy/datafusion that referenced this pull request May 2, 2025
…che#15588)

* fix decimal precision

* return expr if fail to find the casted type

* move fn out

* comment

* fmt

* fix

* fix name and doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comparison Operators for Decimals of Different Precisions and Scales

3 participants