tanclary commented on code in PR #3234:
URL: https://github.com/apache/calcite/pull/3234#discussion_r1212297267
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6111,6 +6111,31 @@ private static void checkIf(SqlOperatorFixture f) {
f.checkNull("truncate(cast(null as double))");
}
+ @Test void testSafeMultiplyFunc() {
+ final SqlOperatorFixture f0 =
fixture().setFor(SqlLibraryOperators.SAFE_MULTIPLY);
+ // Bounds of int64
+ final String max = "9223372036854775807";
+ final String min = "-9223372036854775808";
+ f0.checkFails("^safe_multiply(2, 3)^",
+ "No match found for function signature SAFE_MULTIPLY\\(<NUMERIC>,
<NUMERIC>\\)",
+ false);
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.BIG_QUERY);
+ // Most tests are to verify correct return type and handling of overflow
result
+ f.checkScalar("safe_multiply(2, 3)", "6", "INTEGER");
+ f.checkScalar("safe_multiply(2, -1)", "-2", "INTEGER");
+ f.checkScalar("safe_multiply(2.5, 3.5)", "8.75", "DECIMAL(4, 2)");
+ f.checkScalar("safe_multiply(cast(2 as float), 3)", "6.0", "FLOAT");
+
+ // Test that a result larger than INTEGER but less than overflow will
return BIGINT type
+ f.checkScalar("safe_multiply(1, " + max + ")", max, "BIGINT");
+ f.checkScalar("safe_multiply(1, " + min + ")", min, "BIGINT");
+
+ // Test that overflow/underflow/null operand correctly returns null
+ f.checkNull("safe_multiply(2, " + max + ")");
Review Comment:
That is a great idea, I think I was misunderstanding the overflow limit. I
will update the tests.
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6111,6 +6111,31 @@ private static void checkIf(SqlOperatorFixture f) {
f.checkNull("truncate(cast(null as double))");
}
+ @Test void testSafeMultiplyFunc() {
+ final SqlOperatorFixture f0 =
fixture().setFor(SqlLibraryOperators.SAFE_MULTIPLY);
+ // Bounds of int64
+ final String max = "9223372036854775807";
Review Comment:
Great idea.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]