[ https://issues.apache.org/jira/browse/CALCITE-3411?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Haisheng Yuan resolved CALCITE-3411. ------------------------------------ Fix Version/s: 1.22.0 Resolution: Fixed Fixed in https://github.com/apache/calcite/commit/2cde99f7c5627a488e0dbd33ff1acecb56f3aaa2, thanks for the PR, [~donnyzone]! > Incorrect code generated for BigDecimal ConstantExpression > ---------------------------------------------------------- > > Key: CALCITE-3411 > URL: https://issues.apache.org/jira/browse/CALCITE-3411 > Project: Calcite > Issue Type: Bug > Affects Versions: 1.21.0 > Reporter: Feng Zhu > Assignee: Feng Zhu > Priority: Major > Labels: pull-request-available > Fix For: 1.22.0 > > Time Spent: 50m > Remaining Estimate: 0h > > In current implementation > {code:java} > Expressions.constant("104", BigDecimal.class) -> new > java.math.BigDecimal(104L) > Expressions.constant("1000", BigDecimal.class) -> new > java.math.BigDecimal(1L, -3){code} > However, in *java.math.BigDecimal*, there is no constructor: > {code:java} > java.math.BigDecimal(long exact, int scale) {code} > Instead we should call method > {code:java} > java.math.BigDecimal.valueOf(long exact, int scale){code} > h4. *Why this issue did not exposed before?* > *BlockBuilder* conducts optimizations that can bury this issue. > For example, when we disable the optimization. > _MaterializationTest#testAggregateMaterializationAggregateFuncs11_ will > produce the code below. However, it can't pass the compilation. > {code:java} > final long v = org.apache.calcite.runtime.SqlFunctions.floor(853763696000L, > ((Long) new java.math.BigDecimal(1L, -3)).longValue());{code} -- This message was sent by Atlassian Jira (v8.3.4#803005)