[
https://issues.apache.org/jira/browse/CALCITE-5860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17744643#comment-17744643
]
pengfei.zhan edited comment on CALCITE-5860 at 7/19/23 2:30 PM:
----------------------------------------------------------------
{{When invoking the method RexToLixTranslator#checkExpressionPadTruncate, set
the scale for decimal. The the generated code as follows:}}
{code:java}
/* 1 */ public Object[] apply(Object root0) {
/* 2 */ final java.math.BigDecimal literal_value0 = new
java.math.BigDecimal(
/* 3 */ "3.0");
/* 4 */ final java.math.BigDecimal literal_value1 = new
java.math.BigDecimal(
/* 5 */ "0.5");
/* 6 */ final double method_name_call_value =
org.apache.calcite.runtime.SqlFunctions.power(literal_value0, literal_value1);
/* 7 */ final java.math.BigDecimal cast_value = new java.math.BigDecimal(
/* 8 */ 2.0D / method_name_call_value).setScale(0,
java.math.RoundingMode.HALF_UP);
/* 9 */ return new Object[] {
/* 10 */ cast_value == null ? 0.0D : cast_value.doubleValue() *
method_name_call_value};
/* 11 */ }
/* 12 */
/* {code}
[https://github.com/apache/calcite/pull/3326]
was (Author: JIRAUSER294653):
{{When invoking the method RexToLixTranslator#checkExpressionPadTruncate, set
the scale for decimal.}}
{code:java}
/* 1 */ public Object[] apply(Object root0) {
/* 2 */ final java.math.BigDecimal literal_value0 = new
java.math.BigDecimal(
/* 3 */ "3.0");
/* 4 */ final java.math.BigDecimal literal_value1 = new
java.math.BigDecimal(
/* 5 */ "0.5");
/* 6 */ final double method_name_call_value =
org.apache.calcite.runtime.SqlFunctions.power(literal_value0, literal_value1);
/* 7 */ final java.math.BigDecimal cast_value = new java.math.BigDecimal(
/* 8 */ 2.0D / method_name_call_value).setScale(0,
java.math.RoundingMode.HALF_UP);
/* 9 */ return new Object[] {
/* 10 */ cast_value == null ? 0.0D : cast_value.doubleValue() *
method_name_call_value};
/* 11 */ }
/* 12 */
/* {code}
[https://github.com/apache/calcite/pull/3326]
> 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
> Priority: Major
> Labels: pull-request-available
> Attachments: image-2023-07-19-22-23-19-816.png,
> image-2023-07-19-22-24-31-490.png
>
>
> 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)