Skip to content

Commit 2e4ddb4

Browse files
viiryaIsaac
andcommitted
Fix scalafmt in sql/api and test zero at the old fast-fail boundary
Use the 2-space continuation indent and wrap the Javadoc within maxColumn = 98, as scalafmt requires for sql/api. Scope the Javadoc's note on the conf to this helper, since Decimal.set still reads it for an in-range value with a negative scale. Also test '0e38', the smallest exponent master rejected, and '0e37', which used to get precision 38. Co-authored-by: Isaac <[email protected]>
1 parent e7dd3a4 commit 2e4ddb4

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

‎sql/api/src/main/scala/org/apache/spark/sql/types/Decimal.scala‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,13 @@ object Decimal {
646646
}
647647

648648
/**
649-
* Converts a `JavaBigDecimal` parsed from a string to `Decimal`, or returns null if its integral
650-
* part has more than `DecimalType.MAX_PRECISION` digits and negative scales are not allowed. We
651-
* fast fail because constructing a very large JavaBigDecimal to Decimal is very slow. For
652-
* example: Decimal("6.0790316E+25569151")
649+
* Converts a `JavaBigDecimal` parsed from a string to `Decimal`, or returns null if its
650+
* integral part has more than `DecimalType.MAX_PRECISION` digits and negative scales are not
651+
* allowed. We fast fail because constructing a very large JavaBigDecimal to Decimal is very
652+
* slow. For example: Decimal("6.0790316E+25569151")
653653
*
654-
* This runs for every row of a cast, so the conf is read only for a zero with a negative scale
655-
* and for a value with too many integral digits.
654+
* This runs for every row of a cast, so this helper reads the conf only for a zero with a
655+
* negative scale and for a value with too many integral digits.
656656
*/
657657
private def stringBigDecimalToDecimal(bigDecimal: JavaBigDecimal): Decimal = {
658658
if (bigDecimal.signum == 0) {
@@ -664,7 +664,7 @@ object Decimal {
664664
Decimal(bigDecimal)
665665
}
666666
} else if (numDigitsInIntegralPart(bigDecimal) > DecimalType.MAX_PRECISION &&
667-
!SqlApiConf.get.allowNegativeScaleOfDecimalEnabled) {
667+
!SqlApiConf.get.allowNegativeScaleOfDecimalEnabled) {
668668
null
669669
} else {
670670
Decimal(bigDecimal)

‎sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuiteBase.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ abstract class CastSuiteBase extends SparkFunSuite with ExpressionEvalHelper {
331331
}
332332

333333
test("SPARK-60118: cast string of zero with a large exponent to decimal") {
334-
Seq("0e39", "-0E+100", "0e2147483647").foreach { s =>
334+
Seq("0e38", "0e39", "-0E+100", "0e2147483647").foreach { s =>
335335
checkEvaluation(cast(s, DecimalType(10, 2)), Decimal("0.00"))
336336
}
337337
}

‎sql/catalyst/src/test/scala/org/apache/spark/sql/types/DecimalSuite.scala‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,9 @@ class DecimalSuite extends SparkFunSuite with PrivateMethodTester with SQLHelper
457457
condition = "NUMERIC_OUT_OF_SUPPORTED_RANGE",
458458
parameters = Map("value" -> string))
459459
}
460-
// Zero fits any decimal type whatever its exponent.
461-
Seq("0e39", "-0E+100", "0e2147483647").foreach { string =>
460+
// Zero fits any decimal type whatever its exponent. "0e38" is the smallest exponent that
461+
// used to be rejected, and "0e37" used to get precision 38.
462+
Seq("0e37", "0e38", "0e39", "-0E+100", "0e2147483647").foreach { string =>
462463
Seq(Decimal.fromString(UTF8String.fromString(string)),
463464
Decimal.fromStringANSI(UTF8String.fromString(string))).foreach { d =>
464465
assert(d === Decimal(0))

0 commit comments

Comments
 (0)