Skip to content

Commit

Permalink
[SPARK-45786][SQL][FOLLOWUP][TEST] Fix Decimal random number tests wi…
Browse files Browse the repository at this point in the history
…th ANSI enabled

### What changes were proposed in this pull request?
This follow-up PR fixes the test for SPARK-45786 that is failing in GHA with SPARK_ANSI_SQL_MODE=true

### Why are the changes needed?
The issue discovered in apache#43678 (comment)

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Test updated

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#43853 from kazuyukitanimura/SPARK-45786-FollowUp.

Authored-by: Kazuyuki Tanimura <ktanimura@apple.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
  • Loading branch information
kazuyukitanimura authored and dongjoon-hyun committed Nov 17, 2023
1 parent 2814293 commit 949de34
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,27 +308,35 @@ class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
val mulResult = Decimal(mulExact.setScale(mulType.scale, RoundingMode.HALF_UP))
val mulExpected =
if (mulResult.precision > DecimalType.MAX_PRECISION) null else mulResult
checkEvaluation(mulActual, mulExpected)
checkEvaluationOrException(mulActual, mulExpected)

val divType = Divide(null, null).resultDecimalType(p1, s1, p2, s2)
val divResult = Decimal(divExact.setScale(divType.scale, RoundingMode.HALF_UP))
val divExpected =
if (divResult.precision > DecimalType.MAX_PRECISION) null else divResult
checkEvaluation(divActual, divExpected)
checkEvaluationOrException(divActual, divExpected)

val remType = Remainder(null, null).resultDecimalType(p1, s1, p2, s2)
val remResult = Decimal(remExact.setScale(remType.scale, RoundingMode.HALF_UP))
val remExpected =
if (remResult.precision > DecimalType.MAX_PRECISION) null else remResult
checkEvaluation(remActual, remExpected)
checkEvaluationOrException(remActual, remExpected)

val quotType = IntegralDivide(null, null).resultDecimalType(p1, s1, p2, s2)
val quotResult = Decimal(quotExact.setScale(quotType.scale, RoundingMode.HALF_UP))
val quotExpected =
if (quotResult.precision > DecimalType.MAX_PRECISION) null else quotResult
checkEvaluation(quotActual, quotExpected.toLong)
checkEvaluationOrException(quotActual, quotExpected.toLong)
}
}

def checkEvaluationOrException(actual: BinaryArithmetic, expected: Any): Unit =
if (SQLConf.get.ansiEnabled && expected == null) {
checkExceptionInExpression[SparkArithmeticException](actual,
"NUMERIC_VALUE_OUT_OF_RANGE")
} else {
checkEvaluation(actual, expected)
}
}
}

Expand Down

0 comments on commit 949de34

Please sign in to comment.