[
https://issues.apache.org/jira/browse/CALCITE-7360?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18052194#comment-18052194
]
Mihai Budiu commented on CALCITE-7360:
--------------------------------------
As you see, MySQL and DuckDB do not agree.
Rust, for example, prohibits unary negation on unsigned values.
Calcite never promised to be a superset of the behaviors in other dialects, and
even if you choose one dialect to emulate, the others will by definition not be
emulated correctly. In general, the argument "we cannot reject such expressions
because some dialects allow them" does not hold in Calcite. There are thousands
of things that work in some dialects which Calcite rejects. It is simply
impossible to be a superset of all dialects, because dialects make different
choices which can be contradictory.
Note that this is not really a problem of syntax, but of type checking. In
principle you can use another SqlOperator for unary negation which has
different rules (except the fact that Calcite does not make it easy to replace
the standard operator table).
I think the Rust solution is logically sound, but I am open to other proposals.
The other logical choice is for negation's type to be the next larger signed
integer type (UNSIGNED INT -> BIGINT), but, frankly, I think this behavior can
be surprising for users. Why next highest? Because otherwise negation will
produce runtime errors for half the values in the type's range (anything bigger
than MAX_INT).
> The meaning of negation for unsigned numbers is not defined
> -----------------------------------------------------------
>
> Key: CALCITE-7360
> URL: https://issues.apache.org/jira/browse/CALCITE-7360
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.41.0
> Reporter: Mihai Budiu
> Priority: Minor
> Labels: pull-request-available
>
> Some time ago unsigned integer types were introduced in Calcite.
> They allow all arithmetic operations as signed types.
> However, the meaning of negation is not defined. Using negation in a quidem
> test causes an exception, since the implementation is incorrect.
> Questions:
> * Should negation be allowed at all?
> * Should it coerce the value to a larger integer type?
> * Or should it work as in C?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)