julianhyde commented on code in PR #3234:
URL: https://github.com/apache/calcite/pull/3234#discussion_r1253674610
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6114,35 +6114,62 @@ private static void checkIf(SqlOperatorFixture f) {
@Test void testSafeMultiplyFunc() {
final SqlOperatorFixture f0 =
fixture().setFor(SqlLibraryOperators.SAFE_MULTIPLY);
f0.checkFails("^safe_multiply(2, 3)^",
- "No match found for function signature SAFE_MULTIPLY\\(<NUMERIC>,
<NUMERIC>\\)",
- false);
+ "No match found for function signature "
+ + "SAFE_MULTIPLY\\(<NUMERIC>, <NUMERIC>\\)", false);
final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.BIG_QUERY);
- // check multiplication with no over/underflow has correct result and
result type
- f.checkScalar("safe_multiply(cast(2 as int), cast(3 as int))",
- "6", "INTEGER");
- f.checkScalar("safe_multiply(cast(2 as int), cast(3.5 as double))",
- "7.0", "DOUBLE");
- f.checkScalar("safe_multiply(cast(2 as int), cast(3.456 as float))",
- "6.912", "FLOAT");
- f.checkScalar("safe_multiply(cast(2 as int), cast(3.456 as decimal(4,
3)))",
- "6.912", "DECIMAL(14, 3)");
- f.checkScalar("safe_multiply(cast(2 as double), cast(3.5 as double))",
- "7.0", "DOUBLE");
- // DOUBLE and FLOAT in Calcite maps to BigQuery "FLOAT64", so returning
DOUBLE is okay here
- f.checkScalar("safe_multiply(cast(2 as double), cast(3.456 as float))",
- "6.912", "DOUBLE");
- f.checkScalar("safe_multiply(cast(2 as double), cast(3.456 as decimal(4,
3)))",
- "6.912", "DOUBLE");
- f.checkScalar("safe_multiply(cast(2 as float), cast(3.456 as float))",
- "6.912", "FLOAT");
- f.checkScalar("safe_multiply(cast(2 as float), cast(3.456 as decimal(4,
3)))",
- "6.912", "DOUBLE");
- f.checkScalar("safe_multiply(cast(3.4 as decimal(4,3)), cast(3.456 as
decimal(4,3)))",
- "11.7504", "DECIMAL(8, 6)");
- // check overflow returns null
- f.checkNull("safe_multiply(cast(" + Integer.MAX_VALUE + " as int), 3)");
- f.checkNull("safe_multiply(cast(" + Double.MAX_VALUE + " as double), 3)");
- f.checkNull("safe_multiply(9223372036854775807, 3)");
+ // Basic test for each of the 9 2-permutations of BIGINT, DECIMAL, and
FLOAT
+ f.checkScalar("safe_multiply(cast(20 as bigint), cast(20 as bigint))",
+ "400", "BIGINT");
+ f.checkScalar("safe_multiply(cast(20 as bigint), cast(1.2345 as
decimal(5,4)))",
+ "24.6900", "DECIMAL(19, 4)");
+ f.checkScalar("safe_multiply(cast(1.2345 as decimal(5,4)), cast(20 as
bigint))",
+ "24.6900", "DECIMAL(19, 4)");
+ f.checkScalar("safe_multiply(cast(1.2345 as decimal(5,4)), "
+ + "cast(2.0 as decimal(2, 1)))", "2.46900",
+ "DECIMAL(7, 5)");
+ f.checkScalar("safe_multiply(cast(3 as float), cast(3 as bigint))",
Review Comment:
Are you sure?
SQL's `FLOAT` datatype is more similar to Java `double` than Java `float`.
In SQL, 32-bit floating point is called `REAL`.
--
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]