[ https://issues.apache.org/jira/browse/CALCITE-5860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17764208#comment-17764208 ]
Stamatis Zampetakis commented on CALCITE-5860: ---------------------------------------------- [~pfzhan] Based on the discussion in CALCITE-5901 and [the respective thread|https://lists.apache.org/thread/2xqsl61w4r98jjqhjbnc0ybx4f4v1b0s] in the dev list it seems valid to have scale > precision so the respective changes should be reverted from the PR. Let's not bother with such cases as part of this change. > Decimal type conversion missing scale > ------------------------------------- > > Key: CALCITE-5860 > URL: https://issues.apache.org/jira/browse/CALCITE-5860 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.34.0 > Reporter: Guoliang Sun > Assignee: pengfei.zhan > Priority: Major > Labels: pull-request-available > Fix For: 1.36.0 > > > Take the following SQL as an example > {code:sql} > SELECT CAST(((2.0) / SQRT(3.0)) AS DECIMAL(18, 0)) * SQRT(3.0) {code} > The result of the SQL calculation should be {*}SQRT(3.0){*}.However, the > actual result is {*}2.0{*}, which is not meet expectations. > > The following is the code generated by Janino > {code:java} > public Object[] apply(Object root0) { > final java.math.BigDecimal literal_value = new java.math.BigDecimal( > "2.0"); > final java.math.BigDecimal literal_value0 = new java.math.BigDecimal( > "3.0"); > final java.math.BigDecimal literal_value1 = new java.math.BigDecimal( > "0.5"); > final double method_name_call_value = > org.apache.calcite.runtime.SqlFunctions.power(literal_value0, literal_value1); > final java.math.BigDecimal cast_value = new java.math.BigDecimal( > literal_value.doubleValue() / method_name_call_value); > return new Object[] { > cast_value == null ? 0.0D : cast_value.doubleValue() * > method_name_call_value}; > } {code} > We can see *((2.0) / SQRT(3.0)) AS DECIMAL(18, 0)* lost the scale. -- This message was sent by Atlassian Jira (v8.20.10#820010)