cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benjamin Lerer (JIRA)" <>
Subject [jira] [Commented] (CASSANDRA-14170) Loss of digits when doing CAST from varint/bigint to decimal
Date Thu, 15 Feb 2018 09:30:00 GMT


Benjamin Lerer commented on CASSANDRA-14170:

[~danfiala] Thanks for reporting the problem.

I pushed a branch [here|]
to fix the problem and add some extra tests.

The patch can be merge without trouble into trunk and the Unit tests runs fine on both branches.
We do not have DTests for the {{CAST}} operations.

[~adelapena] Could you review?

> Loss of digits when doing CAST from varint/bigint to decimal
> ------------------------------------------------------------
>                 Key: CASSANDRA-14170
>                 URL:
>             Project: Cassandra
>          Issue Type: Bug
>         Environment: Tested with Cassandra 3.11.1 but this issue is present since the
implementation of cast functions.
>            Reporter: Daniel Fiala
>            Assignee: Benjamin Lerer
>            Priority: Minor
> Cast functions from numeric types to decimal type are implemented as conversion to double
first and then from double to decimal: [].
> This can cause loss of digits for big values stored in varint or bigint. It is probably
unexpected because decimal can store such values precisely.
> Examples:
> {{cqlsh> CREATE TABLE cast_bigint_test(k int PRIMARY KEY, bigint_clmn bigint);}}
>  {{cqlsh> INSERT INTO cast_bigint_test(k, decimal_clmn) VALUES(2, 9223372036854775807);}}
>  {{cqlsh> SELECT CAST(bigint_clmn AS decimal) FROM cast_bigint_test;}}
>  {{cast(bigint_clmn as decimal)}}
>  {{------------------------------}}
>  {{9.223372036854776E+18}}
>  {{(1 rows)}}
> {{cqlsh> CREATE TABLE cast_varint_test (k int PRIMARY KEY, varint_clmn varint);}}
>  {{cqlsh> INSERT INTO cast_varint_test(k, varint_clmn) values(2, 1234567890123456789);}}
>  {{cqlsh> SELECT CAST(varint_clmn AS decimal) FROM cast_varint_test;}}
>  {{cast(varint_clmn as decimal)}}
>  {{------------------------------}}
> 1.23456789012345677E+18
>  {{(1 rows)}}

This message was sent by Atlassian JIRA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message