[MCOL-1133] mcsapi string->decimal conversion corruption for long and negative data Created: 2018-01-04 Updated: 2023-10-26 Resolved: 2018-02-02 |
|
| Status: | Closed |
| Project: | MariaDB ColumnStore |
| Component/s: | None |
| Affects Version/s: | 1.1.2 |
| Fix Version/s: | 1.1.3 |
| Type: | Bug | Priority: | Major |
| Reporter: | Jens Röwekamp (Inactive) | Assignee: | Jens Röwekamp (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Debian 9 |
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Sprint: | 2018-01, 2018-02, 2018-03 | ||||||||
| Description |
|
Initializing a ColumnStoreDecimal with a too long String results in false values for Decimal columns. The same String inserted through SQL is inserted correctly. Example: "100000000.999999999000000000" for Decimal(18,9). Example Code attached. |
| Comments |
| Comment by Andrew Hutchings (Inactive) [ 2018-01-04 ] |
|
Confirmed result ends up being -8.223372037. |
| Comment by Andrew Hutchings (Inactive) [ 2018-01-04 ] |
|
Problem is the decimal number is stored as an int64_t. This overflows into a negative number (several times over) since the length of the value set is 27 digits. We need to do some bounds checking in the string variant of ColumnStoreDecimal::set. |
| Comment by Jens Röwekamp (Inactive) [ 2018-01-04 ] |
|
There also seems something off when assigning negative Strings. If I change the bulk_insert_decimal.cpp example from "23.42" to "-23.42" the value -22.52 gets added to tmp2. |
| Comment by Andrew Hutchings (Inactive) [ 2018-01-05 ] |
|
Fix decimal overflow and negative decimal storage. Added test cases. For QA: mcsapi built-in regression suite has a test for this now. |
| Comment by Jens Röwekamp (Inactive) [ 2018-01-05 ] |
|
Added 3 more test cases to bulk_insert_decimal.cpp (attached), compiled it on Debian 9 and run all tests through make check. Everything worked fine. Just wondered why "999999999.999999999" is rounded up to 1000000000 as integer and why "100000000.999999000000000" isn't rounded up to 100000001 but is converted to 100000000 instead. Don't know if this is relevant. Once we sorted this out I would approve the changes. |
| Comment by Andrew Hutchings (Inactive) [ 2018-01-05 ] |
|
decimal to int had a rounding error. This has now been fixed and pushed to the |
| Comment by Jens Röwekamp (Inactive) [ 2018-01-05 ] |
|
Tested in Debian 9 and Ubuntu 16.04 |
| Comment by Jens Röwekamp (Inactive) [ 2018-01-05 ] |
|
Just discovered that negative values bigger than -1 like "-0.0001" are transformed to their positive equivalent, i.e. "0.0001". Values lesser equal than -1 like "-23.42" are handled correctly. |
| Comment by Andrew Hutchings (Inactive) [ 2018-01-31 ] |
|
New patch switches to boost::multiprecision (header only) for decimal handling. Appears to get rid of the edge cases. |
| Comment by Jens Röwekamp (Inactive) [ 2018-02-01 ] |
|
Nice, looks good. Tested it on Debian9. All relevant tests passed. Due to my unpatched ColumnStoreEngine, I wasn't able to execute the MillionRowTest and the mcol-1160 test. Therefore, didn't merge yet. |
| Comment by Andrew Hutchings (Inactive) [ 2018-02-01 ] |
|
I executed the merge as those other two tests aren't relevant. For QA: The API built-in test suite has all the cases in this issue in the dataconvert-decimal test when you run "make test" |
| Comment by Daniel Lee (Inactive) [ 2018-02-01 ] |
|
Build tested: Github source [root@localhost ~]# cat mariadb-columnstore-1.1.3-1-centos7.x86_64.bin.tar.txt Merge pull request #92 from mariadb-corporation/ /root/columnstore/mariadb-columnstore-server/mariadb-columnstore-engine Merge pull request #391 from mariadb-corporation/ [root@localhost mariadb-columnstore-api]# git show Merge pull request #45 from mariadb-corporation/ [root@localhost mariadb-columnstore-api]# Tested on Centos 7 API built-in tests failed due to the following: – Configuring done |
| Comment by Andrew Hutchings (Inactive) [ 2018-02-01 ] |
|
Pull request switches to Boost from Git submodules. Now works in CentOS 7. |
| Comment by Jens Röwekamp (Inactive) [ 2018-02-02 ] |
|
Tested on Debian9 and CentOS7, all tests passed. |