Guoliang Sun created CALCITE-5860:
-------------------------------------

             Summary: 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


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)

Reply via email to