[
https://issues.apache.org/jira/browse/CALCITE-7360?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18052121#comment-18052121
]
Zhen Chen commented on CALCITE-7360:
------------------------------------
I test some cases using duckdb and mysql. Perhaps this can provide you with
some reference.
{code:java}
duckdb> select -CAST(2.2 AS UINTEGER);
┌──────────────────────────┐
│ -(CAST(2.2 AS UINTEGER)) │
╞══════════════════════════╡
│ 4294967294 │
└──────────────────────────┘
duckdb> select -CAST(2 AS UINTEGER);
┌────────────────────────┐
│ -(CAST(2 AS UINTEGER)) │
╞════════════════════════╡
│ 4294967294 │
└────────────────────────┘
duckdb> select 1 - CAST(2 AS UINTEGER);
Out of Range Error: Overflow in subtraction of UINT32 (1 - 2)!
duckdb> select 3 - CAST(2 AS UINTEGER);
┌───────────────────────────┐
│ (3 - CAST(2 AS UINTEGER)) │
╞═══════════════════════════╡
│ 1 │
└───────────────────────────┘
duckdb> select 3.2 - CAST(2 AS UINTEGER);
┌─────────────────────────────┐
│ (3.2 - CAST(2 AS UINTEGER)) │
╞═════════════════════════════╡
│ 1.2 │
└─────────────────────────────┘ {code}
{code:java}
SELECT -CAST(1 AS UNSIGNED INTEGER);
+------------------------------+
| -CAST(1 AS UNSIGNED INTEGER) |
+------------------------------+
| -1 |
+------------------------------+
SELECT 2 - CAST(1 AS UNSIGNED INTEGER);
+---------------------------------+
| 2 - CAST(1 AS UNSIGNED INTEGER) |
+---------------------------------+
| 1 |
+---------------------------------+
SELECT 2.3 - CAST(1 AS UNSIGNED INTEGER);
+-----------------------------------+
| 2.3 - CAST(1 AS UNSIGNED INTEGER) |
+-----------------------------------+
| 1.3 |
+-----------------------------------+
SELECT -CAST(1.2 AS UNSIGNED INTEGER);
+--------------------------------+
| -CAST(1.2 AS UNSIGNED INTEGER) |
+--------------------------------+
| -1 |
+--------------------------------+
SELECT 1 - CAST(2 AS UNSIGNED INTEGER);
ERROR 1690 (22003) at line 9: BIGINT UNSIGNED value is out of range in '(1 -
cast(2 as unsigned))'{code}
As [~dmsysolyatin] mentioned, should we borrow from existing SQL dialects?
> 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)