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

Mihai Budiu commented on CALCITE-1466:
--------------------------------------

The last PR for this issue adds support for 4 unsigned types corresponding to 
the existing 4 signed types: https://github.com/apache/calcite/pull/4411.

An unsigned type is written as e.g., INTEGER UNSIGNED; just UNSIGNED is an 
alias for INTEGER UNSIGNED

The compiler part is relatively easy, the complexity is all in the runtime.

The number of casts is the square of the number of types, so there is a lot of 
relatively repetitive code unfortunately. The implementation could have used a 
few thousand unit tests too, but I think it's big enough as it is, and we can 
add more tests in the future, especially if bugs are found. Ideally we would 
tag this implementation as "experimental", but there is no easy way to do this.

Unlike MySQL, which also supports similar types, we support all possible casts 
between all possible types. 

The current implementation only supports the basic arithmetic operations for 
unsigned types; none of the existing mathematical functions are implemented. 
But perhaps this is right, and people should cast unsigned to signed if they 
want to call the mathematical functions.

When combining signed and unsigned types in an arithmetic operation the result 
is cast to the wider type; for the same width, the result is the unsigned type. 
This can lead to surprising behaviors, but the converse would too, and I think 
this is what MySQL does too.

The question of overflow of arithmetic operations is also unspecified. There 
exist checked and unchecked arithmetic operations (similar to signed integers), 
but I think at this point the overflow is always fatal. A few hundreds of unit 
tests may be needed for that as well...

> Support for UNSIGNED types of TINYINT, SMALLINT, INT, BIGINT in type system
> ---------------------------------------------------------------------------
>
>                 Key: CALCITE-1466
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1466
>             Project: Calcite
>          Issue Type: Improvement
>          Components: avatica
>            Reporter: Rajeshbabu Chintaguntla
>            Assignee: Mihai Budiu
>            Priority: Major
>              Labels: pull-request-available
>
> There are some data bases like MySQL supporting unsigned data types.  Apache 
> Phoenix also supports them. Would be great to add them to calcite as well.
> http://dev.mysql.com/doc/refman/5.7/en/integer-types.html



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to