[
https://issues.apache.org/jira/browse/CALCITE-5860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17746085#comment-17746085
]
Benchao Li commented on CALCITE-5860:
-------------------------------------
[~pfzhan] I agree that this is a valid bug, and I have reproduced it in sqlline
on current main branch. But I'm not sure I will be available in the next few
days to give it a review, you can also find another reviewer in the dev mailing
list.
Besides, we usually do not suggest to explicitly tag someone, you can find the
suggestions in the [doc|https://calcite.apache.org/develop/#contributing]
bq. The best place to ask for feedback related to an issue is the developers
list. Please avoid tagging specific people in the JIRA case asking for
feedback. This discourages other contributors to participate in the discussion
and provide valuable feedback.
> 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
>
> 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)