DonnyZone commented on a change in pull request #1381: [CALCITE-3245]
CompileException in Janino when a query contains a division between a Double
and a BigDecimal
URL: https://github.com/apache/calcite/pull/1381#discussion_r322142066
##########
File path: core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
##########
@@ -589,6 +592,14 @@ private void check(ResultSetMetaData metaData, String
columnName,
.returns("C=null\n");
}
+ @Test public void testDivideDoubleBigDecimal() {
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that().withSchema("s", CATCHALL);
+ with.query("select \"wrapperDouble\" / \"bigDecimal\" as c\n"
+ + " from \"s\".\"everyTypes\"")
+ .runs();
Review comment:
I find that `ReflectiveSchemaTest#testOp()` enumerates all type combinations
for numeric operators ('+', '-', '*', '/'), including `null` content (e.g.,
`wrapperInteger`, `wrapperDouble`). I think it can cover these cases. So, maybe
we can even remove this test case.
However, when I tested a `null` literal with the following test case.
```
@Test public void testDivideDoubleBigDecimal() {
final CalciteAssert.AssertThat with =
CalciteAssert.that().withSchema("s", CATCHALL);
with.query("select \"bigDecimal\" / null as c\n"
+ " from \"s\".\"everyTypes\"")
.runs();
}
```
It fails due to the **Assertion** below. When SqlBinaryOperator figuring out
its `Monotonicity`, if the second operand is a Literal, it will cast the
literal into BigDecimal. But the `Null` Literal can not be properly handled.
It seems to be the problem related with NULL literal, which demands a
systematic solution.
Should we file a seperate Jira for this issue (it can also be trigger by
'wrapperLong'/null)?
```
java.lang.AssertionError: cannot cast null as class java.math.BigDecimal
at org.apache.calcite.sql.SqlLiteral.getValueAs(SqlLiteral.java:351)
at
org.apache.calcite.sql.SqlCallBinding.getOperandLiteralValue(SqlCallBinding.java:217)
at
org.apache.calcite.sql.SqlBinaryOperator.getMonotonicity(SqlBinaryOperator.java:190)
at org.apache.calcite.sql.SqlCall.getMonotonicity(SqlCall.java:182)
at
org.apache.calcite.sql.SqlCallBinding.getOperandMonotonicity(SqlCallBinding.java:188)
at
org.apache.calcite.sql.SqlAsOperator.getMonotonicity(SqlAsOperator.java:139)
at org.apache.calcite.sql.SqlCall.getMonotonicity(SqlCall.java:182)
at
org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(SqlToRelConverter.java:3961)
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services