You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/11/22 12:46:26 UTC

[GitHub] [spark] ulysses-you opened a new pull request, #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

ulysses-you opened a new pull request, #38760:
URL: https://github.com/apache/spark/pull/38760

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Add one more check before decimal.changePrecision return false.
   0 is a special case for decimal which data type can be Decimal(0, 0), then changePrecision to Decimal(0, 0) should return true if value is 0.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   fix data correctness.
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   yes, bug fix
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   add test


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1409716946

   thanks, merging to master/3.4!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1409665435

   @viirya I think we need but it's a breaking change so how about creating a new pr for master


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1031035938


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala:
##########
@@ -420,7 +420,11 @@ final class Decimal extends Ordered[Decimal] with Serializable {
       // have overflowed our Long; in either case we must rescale dv to the new scale.
       dv = dv.setScale(scale, roundMode)
       if (dv.precision > precision) {

Review Comment:
   what is the precision of `BigDecimal` in this case?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1031035738


##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala:
##########
@@ -3537,6 +3537,12 @@ class DataFrameSuite extends QueryTest
       }.isEmpty)
     }
   }
+
+  test("SPARK-41219: Decimal changePrecision should work with decimal(0, 0)") {
+    val df = Seq("0.5944910").toDF("a")
+    checkAnswer(df.selectExpr("cast(a as decimal(7,7)) div 100"), Row(0))
+    checkAnswer(df.select(lit(BigDecimal(0)) as "c").selectExpr("cast(c as decimal(0,0))"), Row(0))

Review Comment:
   Now `cast(a as decimal(7,7)) div 100` fails and we want to fix it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1324619462

   cc @srielau @viirya 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1408446317

   > It happened in branch-3.4 after we refactor decimal binary operater.
   
   Before the refactor, what was the return type of the integral divide? also `decimal(1, 0)`?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1409618212

   @cloud-fan sure, has updated the description !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1408399457

   The fix LGTM, thanks @ulysses-you ! Do you know when we start to have this bug? And do we ever support `decimal(0, 0)`? like in `CREATE TABLE` and `CAST`?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1031049024


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala:
##########
@@ -420,7 +420,11 @@ final class Decimal extends Ordered[Decimal] with Serializable {
       // have overflowed our Long; in either case we must rescale dv to the new scale.
       dv = dv.setScale(scale, roundMode)
       if (dv.precision > precision) {

Review Comment:
   I think this makes sense. If we write `SELECT 0bd` in Spark, the returned decimal is also `decimal(1, 0)`. Maybe forbidding `decimal(0, 0)` is a better choice. What do you think @srielau ? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1031941613


##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala:
##########
@@ -3537,6 +3537,12 @@ class DataFrameSuite extends QueryTest
       }.isEmpty)
     }
   }
+
+  test("SPARK-41219: Decimal changePrecision should work with decimal(0, 0)") {
+    val df = Seq("0.5944910").toDF("a")
+    checkAnswer(df.selectExpr("cast(a as decimal(7,7)) div 100"), Row(0))
+    checkAnswer(df.select(lit(BigDecimal(0)) as "c").selectExpr("cast(c as decimal(0,0))"), Row(0))

Review Comment:
   @gengliangwang we can, it actually is the path of least resistance. By making sure the result decimal precision bigger than 0, see the comment https://github.com/apache/spark/pull/38760#discussion_r1030015079.
   
   Besides, some other quries would fail with decimal(0, 0), it can less happen in production though. So this pr wants to make sure how does Spark handle decimal(0, 0) or leave it as is.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1031044398


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala:
##########
@@ -420,7 +420,11 @@ final class Decimal extends Ordered[Decimal] with Serializable {
       // have overflowed our Long; in either case we must rescale dv to the new scale.
       dv = dv.setScale(scale, roundMode)
       if (dv.precision > precision) {

Review Comment:
   it's 1, can see the docs in `java.math.BigDecimal`
   <img width="650" alt="image" src="https://user-images.githubusercontent.com/12025282/203693808-37715386-1fda-4134-aafc-b558ee55b7fe.png">
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1030015079


##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala:
##########
@@ -3537,6 +3537,12 @@ class DataFrameSuite extends QueryTest
       }.isEmpty)
     }
   }
+
+  test("SPARK-41219: Decimal changePrecision should work with decimal(0, 0)") {
+    val df = Seq("0.5944910").toDF("a")
+    checkAnswer(df.selectExpr("cast(a as decimal(7,7)) div 100"), Row(0))

Review Comment:
   @cloud-fan see this test, the decimal type of IntegralDivide can be `decimal(0, 0)` (other BinaryArithmetic does not have the issue).
   
   https://github.com/apache/spark/blob/d275a83c582a23d7730b5a35a335f9cd10c2741c/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala#L864-L868
   
   Or, we may change it to `max(p1 - s1 + s2, 1)`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] gengliangwang commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
gengliangwang commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1031804704


##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala:
##########
@@ -3537,6 +3537,12 @@ class DataFrameSuite extends QueryTest
       }.isEmpty)
     }
   }
+
+  test("SPARK-41219: Decimal changePrecision should work with decimal(0, 0)") {
+    val df = Seq("0.5944910").toDF("a")
+    checkAnswer(df.selectExpr("cast(a as decimal(7,7)) div 100"), Row(0))
+    checkAnswer(df.select(lit(BigDecimal(0)) as "c").selectExpr("cast(c as decimal(0,0))"), Row(0))

Review Comment:
   Shall we change the evaluation of `decimal div integer` instead? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1408813140

   Thanks for the explanation! @ulysses-you can you put it in the PR description? e.g. how this bug was introduced and why it worked before.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan closed pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0
URL: https://github.com/apache/spark/pull/38760


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1409665363

   > Do we need to add some assert in DecimalType to prevent zero precision?
   
   I think we should, but let's do it in the master branch only to officially ban 0 decimal precision.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1409650160

   @cloud-fan updated


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1029962313


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/types/DecimalSuite.scala:
##########
@@ -384,4 +384,11 @@ class DecimalSuite extends SparkFunSuite with PrivateMethodTester with SQLHelper
       }
     }
   }
+
+  test("SPARK-41219: Decimal changePrecision should work with decimal(0, 0)") {
+    assert(Decimal(0).changePrecision(0, 0))
+    assert(Decimal(0L).changePrecision(0, 0))
+    assert(Decimal(java.math.BigInteger.valueOf(0)).changePrecision(0, 0))
+    assert(Decimal(BigDecimal(0)).changePrecision(0, 0))

Review Comment:
   this is the key test, before it returned false



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1324450892

   cc @cloud-fan @revans2  @gengliangwang 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] srielau commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
srielau commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1030596213


##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala:
##########
@@ -3537,6 +3537,12 @@ class DataFrameSuite extends QueryTest
       }.isEmpty)
     }
   }
+
+  test("SPARK-41219: Decimal changePrecision should work with decimal(0, 0)") {
+    val df = Seq("0.5944910").toDF("a")
+    checkAnswer(df.selectExpr("cast(a as decimal(7,7)) div 100"), Row(0))
+    checkAnswer(df.select(lit(BigDecimal(0)) as "c").selectExpr("cast(c as decimal(0,0))"), Row(0))

Review Comment:
   The numeric equivalent to CHAR(0). The only values are NULL and 0. I would choose the path of least resistance. I agree that there is risk in support. What's the origin of this PR?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1324618007

   It seems reasonable to say that 0 is the only valid value for `decimal(0, 0)`. Forbidding `decimal(0, 0)` seems also reasonable but is more risky.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a diff in pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #38760:
URL: https://github.com/apache/spark/pull/38760#discussion_r1030003237


##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala:
##########
@@ -3537,6 +3537,12 @@ class DataFrameSuite extends QueryTest
       }.isEmpty)
     }
   }
+
+  test("SPARK-41219: Decimal changePrecision should work with decimal(0, 0)") {
+    val df = Seq("0.5944910").toDF("a")
+    checkAnswer(df.selectExpr("cast(a as decimal(7,7)) div 100"), Row(0))
+    checkAnswer(df.select(lit(BigDecimal(0)) as "c").selectExpr("cast(c as decimal(0,0))"), Row(0))

Review Comment:
   hmmm, `decimal(0, 0)` is a valid decimal type? how do you use it in production?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on pull request #38760: [SPARK-41219][SQL] Decimal changePrecision should work with decimal(0, 0)

Posted by GitBox <gi...@apache.org>.
viirya commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1324699111

   Hmm, seems not precision 0 is not allowed for all? For example, a quick search found that Mysql disallows it. Although I don't see others like postgresql, trino explicitly define it in their documention.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1408442961

   > Do you know when we start to have this bug?
   
   It happened in branch-3.4 after we refactor decimal binary operater.
   
   > And do we ever support decimal(0, 0)? like in CREATE TABLE and CAST?
   
   It's more complex and is a long time issue. In short, Spark does not validate and fail if the presicion is 0 when create table or cast expression. But the dependency(hive/parquet) did it.
   ```sql
   -- work with in-memory catalog
   create table t (c decimal(0, 0)) using parquet;
   -- fail with parquet
   -- java.lang.IllegalArgumentException: Invalid DECIMAL precision: 0
   --	at org.apache.parquet.Preconditions.checkArgument(Preconditions.java:57)
   insert into table t values(0);
   
   -- fail with hive catalog
   -- Caused by: java.lang.IllegalArgumentException: Decimal precision out of allowed range [1,38]
   --	at org.apache.hadoop.hive.serde2.typeinfo.HiveDecimalUtils.validateParameter(HiveDecimalUtils.java:44)
   create table t (c decimal(0, 0)) using parquet;
   ```
   So I think we should fail if precision is 0.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1408456878

   The decimal type is a intermediate data type of `IntegralDivide`, the final data type is long.. Before we promoted the precision for the intermediate data type so it's not decimal(1, 0).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1409692951

   > I think we need but it's a breaking change so how about creating a new pr for master
   
   Yea, let's do it in master branch. Thanks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #38760: [SPARK-41219][SQL] IntegralDivide use decimal(1, 0) to represent 0

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #38760:
URL: https://github.com/apache/spark/pull/38760#issuecomment-1409636538

   Please link to the PR of decimal refactor. Then I think this is good to go.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org