[ 
https://issues.apache.org/jira/browse/CALCITE-4632?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jess Balint closed CALCITE-4632.
--------------------------------

Resolved in release 1.33.0 (2023-02-06)

> Exception in RelToSqlConverter: "Cannot convert x to DECIMAL(n, m) due to 
> overflow"
> -----------------------------------------------------------------------------------
>
>                 Key: CALCITE-4632
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4632
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Steven Talbot
>            Assignee: Abhishek Dasgupta
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.33.0
>
>          Time Spent: 2.5h
>  Remaining Estimate: 0h
>
> Test in RelToSqlConverter.java
> {code: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);
> }{code}
> Stack trace:
>  
> {noformat}
> 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){noformat}
>  
> 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? 
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to