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

Fix Float and Decimal coercion #14273

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

findepi
Copy link
Member

@findepi findepi commented Jan 24, 2025

Which issue does this PR close?

Closes #14272

Rationale for this change

Before the change, Float* and Decimal* would coerce to a decimal type. However, decimal cannot store all the float values: different range, NaN, and infinity. Coercing to floating point is more desirable and also what other systems typically do.

What changes are included in this PR?

Numeric coercion rules change

Are these changes tested?

yes

Are there any user-facing changes?

yes

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jan 24, 2025
@findepi findepi force-pushed the findepi/fix-float-and-decimal-coercion-b58e78 branch from 4e8e850 to 0f69629 Compare January 24, 2025 14:52
@github-actions github-actions bot added the core Core DataFusion crate label Jan 24, 2025
@findepi findepi force-pushed the findepi/fix-float-and-decimal-coercion-b58e78 branch from 0f69629 to 056e2d0 Compare January 24, 2025 14:57
@findepi findepi force-pushed the findepi/fix-float-and-decimal-coercion-b58e78 branch from 056e2d0 to 52f19ee Compare January 24, 2025 21:05
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.

Thanks @findepi -- this area is a bit out of my league here to understand the repercussions of this change

@jonahgao @berkaysynnada and @ozankabak and I have been discussing coercion related to @nuno-faria s (very) recent change here:

Perhaps they can weigh in here. I feel like there is a tension here and that we are in serious danger of the behavior oscillating 🤔

I feel like in some past version of DataFusion we used to coerce to Floats and that was changed to Decimal for some reason

Maybe what we can do is write down

  1. What the current coercion behavior is
  2. What we want it to be (and why we want to change it)
  3. Get agreement on to goal
  4. Then make the code match the agreement

Before the change, Float* and Decimal* would coerce to a decimal type.
However, decimal cannot store all the float values: different range,
NaN, and infinity. Coercing to floating point is more desirable and also
what other systems typically do.
@findepi findepi force-pushed the findepi/fix-float-and-decimal-coercion-b58e78 branch from 52f19ee to bed8a43 Compare January 24, 2025 21:34
@findepi
Copy link
Member Author

findepi commented Jan 24, 2025

@alamb thanks for your feedback. I agree it's important to avoid back-and-forth with a change, so the broader review the better.

What the current coercion behavior is

#14272

What we want it to be (and why we want to change it)

I don't think this particular change should be controversial though.

See issue, but also:

  1. we as the project primarily follow PostreSQL behavior and this is what this PR does (i think this rule is kind of well established, even if not well documented, but i see Document SQL dialect guidance #13706 is not merged)
  2. PostgreSQL aside, the implicit coercions should generally not fail (but alas, i've seen systems violating this common sense rule). Casting from float to decimal obviously may mail

Get agreement on to goal

let's do it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate sqllogictest SQL Logic Tests (.slt)
Projects
None yet
2 participants