Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Test in RelToSqlConverter.java
@Test void testSelectWhereInDecimal() { final Function<RelBuilder, RelNode> relFn = b -> b .scan("EMP") .filter( b.or(b.isNull(b.field("COMM")), (b.in(b.field("COMM"), b.literal(new BigDecimal("1.0")), b.literal(new BigDecimal("20000.0")))))) .build(); final String expected = "SELECT *\n" + "FROM \"scott\".\"EMP\"\n" + "WHERE \"COMM\" IS NULL OR \"COMM\" IN (1.0, 20000.0)"; relFn(relFn).ok(expected); }
Stack trace:
Cannot convert 20000.0 to DECIMAL(2, 1) due to overflow java.lang.IllegalArgumentException: Cannot convert 20000.0 to DECIMAL(2, 1) due to overflow at org.apache.calcite.rex.RexBuilder.makeLiteral(RexBuilder.java:990) at org.apache.calcite.rex.RexBuilder.makeExactLiteral(RexBuilder.java:1046) at org.apache.calcite.rex.RexBuilder.makeLiteral(RexBuilder.java:1592) at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.lambda$toIn$2(SqlImplementor.java:937) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at com.google.common.collect.CollectSpliterators$1WithCharacteristics.lambda$forEachRemaining$1(CollectSpliterators.java:67) at java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110) at com.google.common.collect.CollectSpliterators$1WithCharacteristics.forEachRemaining(CollectSpliterators.java:67) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toIn(SqlImplementor.java:939) at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:912) at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:804) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:338) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:531) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:134) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitInput(RelToSqlConverter.java:142) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:185) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:173) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitRoot(SqlImplementor.java:153) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.toSql(RelToSqlConverterTest.java:216) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.toSql(RelToSqlConverterTest.java:204) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.access$300(RelToSqlConverterTest.java:111) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:5999) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.ok(RelToSqlConverterTest.java:5967) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.testSelectWhereInDecimal(RelToSqlConverterTest.java:339)
Almost certainly because we just grab the type of the first arg at https://github.com/apache/calcite/blob/204b5ab42d9e365c55636cd0aca9f750f4d50e5d/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java#L801-L804, which in a decimal type is not guaranteed to be compatible with the remainder of the args. Probably need to call one of the type normalizing functions?
Attachments
Issue Links
- duplicates
-
CALCITE-4888 The type of generated search argument literal is wrong if the literal types of RelBuilder.in are different and compatible
- Closed
- fixes
-
CALCITE-4888 The type of generated search argument literal is wrong if the literal types of RelBuilder.in are different and compatible
- Closed
- links to