-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25454][SQL] add a new config for picking minimum precision for integral literals #22494
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
Conversation
|
Maybe we should also consider to turn off DECIMAL_OPERATIONS_ALLOW_PREC_LOSS by default. |
|
I don't really agree with this. As I mentioned here, I think we can avoid to use negative scales regardless of the value of the flag, since before #20023 a negative scale here is not possible. So I think we can just add a check for avoiding a non-negative scale in Doing so, there is no need to turn the flag off by default. |
Can you open a PR for it? I did some experiments locally and this seems not work. |
|
Sure @cloud-fan, I'll do asap. |
|
oh, I see now the problem. And it is much bigger than I thought, sorry. Here we were returning a negative scale for |
|
yea, that's why I change the test to use The point is, we know there is a bug and it's hard to fix. What I'm trying to do here is not fixing the bug, but to allow users to fully turn off #20023. Thus we can avoid regressions and not make it worse. |
|
2.3.2 and 2.4.0 are both in the RC stage, I don't want to spend a lot of time to fix this long-standing bug and block 2 releases. cc @jerryshao too. |
|
yes @cloud-fan, I see your point. I am neutral to this change honestly. It is true that it avoids regressions form previous cases, but it is also true that it doesn't make the behavior better: I mean in some (weird) cases like this one it behaves better, but there are other cases when the opposite is true since we were overestimating the precision. |
|
This PR is a no-op if users don't turn off #20023 . The benefit of this PR is: before we fully fix that bug, if a user hit it, he can turn off #20023 to temporarily work around it. So I don't see any harm of this PR. Turning off #20023 by default is another story and I'd like to get more feedback before doing it. |
If the user doesn't turn off the flag, of course nothing changes. If the user does, then let's imagine this case. A user has this: It is true that after this PR, Spark will support (with the same exact precision) all the operations that worked fine before #20023. But this PR also can break some operation that started working fine after #20023 (even with the flag turned off). |
|
why do we care about breaking operations when turning off a behavior change config? The config is prepared for this case: if a user hit a problem of the new behavior, he can use this config to restore to the previous behavior. For this config, the previous behavior is the behavior before #20023. If your argument is, picking a precise precision for literal is an individual featue and not related to #20023, I'm OK to create a new config for it. |
|
Test build #96360 has finished for PR 22494 at commit
|
|
@cloud-fan The change looks fine to me. I looked at the failure. It correctly switches to old behaviour when this config is set to off. |
|
Test build #96392 has finished for PR 22494 at commit
|
|
retest this please |
Yes this is - I think - a better option. Indeed, what I meant was this: let's imagine I am a Spark 2.3.0 user and I have Using another config is therefore a better workaround IMO. |
|
I tried to add a new config, but decided to not do it. The problem is, when users hit SPARK-25454, they must turn off both the
|
If a user hits SPARK-25454, the value of
No if SPARK-25454, turning it off is helpless. The only reason to turn it off is to get |
|
Sorry my mistake. I'm talking about the specific query reported at https://issues.apache.org/jira/browse/SPARK-22036?focusedCommentId=16618104&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16618104 , which needs to turn off SPARK-25454 is a long-standing bug and currently we can't help users to work around it. My point is, to work around this regression, user must turn off both
I don't agree with it. Users can turn on The reason why this is a regression is: users have no way to get the same (and expected) result of 2.3 in 2.4. |
Yes I am talking about that too, and there is no need to turn off |
|
Test build #96406 has finished for PR 22494 at commit
|
|
sorry, I screwed up my local branch and made a wrong conclusion. Turning off the precise precision for integral literals can fix the regression. So it's better to add a config for it. |
| .doc("When integral literals are used with decimals in binary operators, Spark will " + | ||
| "pick a precise precision for the literals to calculate the precision and scale " + | ||
| "of the result decimal, when this config is true. By picking a precise precision, we " + | ||
| "can avoid wasting precision, to reduce the possibility of overflow.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to reduce the possibility of overflow actually this is not true and depends on the value of DECIMAL_OPERATIONS_ALLOW_PREC_LOSS, If DECIMAL_OPERATIONS_ALLOW_PREC_LOSS is true, the risk is to have a precision loss, but we don't overflow. If that is false, then this statement is right.
| .booleanConf | ||
| .createWithDefault(true) | ||
|
|
||
| val LITERAL_PRECISE_PRECISION = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmh... PRECISE_PRECISION sounds weird... can we look for a better one? I don't have a suggestion right now, but I'll think about it.
| buildConf("spark.sql.literal.precisePrecision") | ||
| .internal() | ||
| .doc("When integral literals are used with decimals in binary operators, Spark will " + | ||
| "pick a precise precision for the literals to calculate the precision and scale " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a precise precision -> the minimal precision required to represent the given value?
| } | ||
|
|
||
| test("SPARK-25454: decimal division with negative scale") { | ||
| // TODO: completely fix this issue even LITERAL_PRECISE_PRECISION is true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: even when
mgaido91
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM apart from a minor comment, thanks @cloud-fan.
Shall we also document this somehow in the migration guide or on the JIRA? Otherwise, how can users know about it?
nit: what about referencing SPARK-25454 in the title though? This seems more a temp fix for that specific issue than a follow-up of SPARK-22036 to me.
| .createWithDefault(true) | ||
|
|
||
| val LITERAL_PICK_MINIMUM_PRECISION = | ||
| buildConf("spark.sql.literal.pickMinimumPrecision") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I am thinking whether we can consider this as a legacy config. We can also remove it once the PR for SPARK-25454 will be merged and/or we remove the support to negative scale decimals. What do you think?
|
Test build #96423 has finished for PR 22494 at commit
|
|
retest this please |
|
Test build #96425 has finished for PR 22494 at commit
|
|
Test build #96429 has finished for PR 22494 at commit
|
|
Test build #96446 has finished for PR 22494 at commit
|
|
@mgaido91 Since we are going to merge this PR to both 2.4 and 2.3, and the default behavior is not changed. I think we don't need to add migration guide. I'll post this workaround to the JIRA ticket when this PR is merged. |
|
yes, sounds ok to me. Thanks. LGTM. |
|
Test build #96509 has started for PR 22494 at commit |
|
retest this please |
|
Test build #96533 has finished for PR 22494 at commit
|
|
retest this please |
|
Test build #96539 has finished for PR 22494 at commit
|
gatorsmile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks! Merged to master/2.4/2.3
… integral literals ## What changes were proposed in this pull request? #20023 proposed to allow precision lose during decimal operations, to reduce the possibilities of overflow. This is a behavior change and is protected by the DECIMAL_OPERATIONS_ALLOW_PREC_LOSS config. However, that PR introduced another behavior change: pick a minimum precision for integral literals, which is not protected by a config. This PR add a new config for it: `spark.sql.literal.pickMinimumPrecision`. This can allow users to work around issue in SPARK-25454, which is caused by a long-standing bug of negative scale. ## How was this patch tested? a new test Closes #22494 from cloud-fan/decimal. Authored-by: Wenchen Fan <wenchen@databricks.com> Signed-off-by: gatorsmile <gatorsmile@gmail.com> (cherry picked from commit d0990e3) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
… integral literals ## What changes were proposed in this pull request? #20023 proposed to allow precision lose during decimal operations, to reduce the possibilities of overflow. This is a behavior change and is protected by the DECIMAL_OPERATIONS_ALLOW_PREC_LOSS config. However, that PR introduced another behavior change: pick a minimum precision for integral literals, which is not protected by a config. This PR add a new config for it: `spark.sql.literal.pickMinimumPrecision`. This can allow users to work around issue in SPARK-25454, which is caused by a long-standing bug of negative scale. ## How was this patch tested? a new test Closes #22494 from cloud-fan/decimal. Authored-by: Wenchen Fan <wenchen@databricks.com> Signed-off-by: gatorsmile <gatorsmile@gmail.com> (cherry picked from commit d0990e3) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
… integral literals ## What changes were proposed in this pull request? apache#20023 proposed to allow precision lose during decimal operations, to reduce the possibilities of overflow. This is a behavior change and is protected by the DECIMAL_OPERATIONS_ALLOW_PREC_LOSS config. However, that PR introduced another behavior change: pick a minimum precision for integral literals, which is not protected by a config. This PR add a new config for it: `spark.sql.literal.pickMinimumPrecision`. This can allow users to work around issue in SPARK-25454, which is caused by a long-standing bug of negative scale. ## How was this patch tested? a new test Closes apache#22494 from cloud-fan/decimal. Authored-by: Wenchen Fan <wenchen@databricks.com> Signed-off-by: gatorsmile <gatorsmile@gmail.com>
What changes were proposed in this pull request?
#20023 proposed to allow precision lose during decimal operations, to reduce the possibilities of overflow. This is a behavior change and is protected by the DECIMAL_OPERATIONS_ALLOW_PREC_LOSS config. However, that PR introduced another behavior change: pick a minimum precision for integral literals, which is not protected by a config. This PR add a new config for it:
spark.sql.legacy.literal.pickMinimumPrecision.This can allow users to work around issue in SPARK-25454, which is caused by a long-standing bug of negative scale.
How was this patch tested?
a new test