[ 
https://issues.apache.org/jira/browse/CALCITE-3872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17067933#comment-17067933
 ] 

Julian Hyde edited comment on CALCITE-3872 at 3/26/20, 6:26 PM:
----------------------------------------------------------------

Calcite uses BigDecimal to represent literals (i.e. at compile time) but it 
doesn't use it to represent values (i.e. at run time). Compile time is already 
covered, because if you write "- - 10" we can do constant reduction. So the 
question is run time.

I am somewhat concerned about exceptions and overflow too. We don't specify 
what should happen if there is an overflow in an intermediate result. I suspect 
that for {{- - CAST(\-32768 AS SMALLINT)}} we will generate Java something like 
{{- (- ((short) -32768))} and that Java will evaluate to {{-32768}} even though 
the intermediate value {{32768}} is too large for a SQL {{SMALLINT}}.

So this simplification may be valid given our current semantics.


was (Author: julianhyde):
Calcite uses BigDecimal to represent literals (i.e. at compile time) but it 
doesn't use it to represent values (i.e. at run time). Compile time is already 
covered, because if you write "- - 10" we can do constant reduction. So the 
question is run time.

I am somewhat concerned about exceptions and overflow too. We don't specify 
what should happen if there is an overflow in an intermediate result. I suspect 
that for {{- - CAST(-32768 AS SMALLINT)}} we will generate Java something like 
{{- (- ((short) -32768))} and that Java will evaluate to {{-32768}} even though 
the intermediate value {{32768}} is too large for a SQL {{SMALLINT}}.

So this simplification may be valid given our current semantics.

> Simplify expressions with unary minus
> -------------------------------------
>
>                 Key: CALCITE-3872
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3872
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Liya Fan
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Support simplifying expression - ( - ( x ) ) as x.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to