[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: File bulk_insert_decimal.cpp     File bulk_insert_decimal.sql     File dataconvert-decimal.cpp    
Issue Links:
Relates
relates to MCOL-1198 Let the Spark Connector use the nativ... Closed
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 MCOL-1133 branch.

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
/root/columnstore/mariadb-columnstore-server
commit e5499e513d88a3dfefbe9a356e20a1bceb1bde38
Merge: 99cdb0a 4840a43
Author: david hill <david.hill@mariadb.com>
Date: Wed Jan 31 16:53:52 2018 -0600

Merge pull request #92 from mariadb-corporation/MCOL-1152

MCOL-1152: Change the debian package names.

/root/columnstore/mariadb-columnstore-server/mariadb-columnstore-engine
commit c792188a5ff06aac49415a51373963c1f3def7d4
Merge: aafda6b 253c23d
Author: david hill <david.hill@mariadb.com>
Date: Thu Feb 1 08:56:55 2018 -0600

Merge pull request #391 from mariadb-corporation/MCOL-1152

MCOL-1152: Change the debian package names.

[root@localhost mariadb-columnstore-api]# git show
commit 3ceb664e58d8064ddc709cbedc1bea3bbc720900
Merge: f053df6 85ea351
Author: Andrew Hutchings <andrew@linuxjedi.co.uk>
Date: Thu Feb 1 09:07:04 2018 +0200

Merge pull request #45 from mariadb-corporation/MCOL-1133-rev2

MCOL-1133 Use boost for decimal types

[root@localhost mariadb-columnstore-api]#

Tested on Centos 7

API built-in tests failed due to the following:

– Configuring done
– Generating done
– Build files have been written to: /root/mariadb-columnstore-api
[ 2%] Building CXX object src/CMakeFiles/mcsapi.dir/mcsapi_types.cpp.o
/root/mariadb-columnstore-api/src/mcsapi_types.cpp: In member function ‘uint64_t mcsapi::ColumnStoreDecimalImpl::getDecimalInt(uint32_t)’:
/root/mariadb-columnstore-api/src/mcsapi_types.cpp:314:28: error: ‘ilogb’ is not a member of ‘boost::multiprecision’
int64_t decimalScale = boost::multiprecision::ilogb(decNum);
^
/root/mariadb-columnstore-api/src/mcsapi_types.cpp:314:28: note: suggested alternatives:
In file included from /usr/include/features.h:375:0,
from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/os_defines.h:39,
from /usr/include/c+/4.8.2/x86_64-redhat-linux/bits/c+config.h:2097,
from /usr/include/c++/4.8.2/string:38,
from /root/mariadb-columnstore-api/src/common.h:23,
from /root/mariadb-columnstore-api/src/mcsapi_types.cpp:19:
/usr/include/bits/mathcalls.h:297:1: note: ‘ilogb’
_MATHDECL (int,ilogb,, (_Mdouble __x));
^
In file included from /root/mariadb-columnstore-api/src/common.h:31:0,
from /root/mariadb-columnstore-api/src/mcsapi_types.cpp:19:
/usr/include/c++/4.8.2/cmath:1402:5: note: ‘std::ilogb’
ilogb(_Tp __x)
^
At global scope:
cc1plus: warning: unrecognized command line option "-Wno-unknown-warning-option" [enabled by default]
cc1plus: warning: unrecognized command line option "-Wno-unused-command-line-argument" [enabled by default]
cc1plus: warning: unrecognized command line option "-Wno-format-truncation" [enabled by default]
make[2]: *** [src/CMakeFiles/mcsapi.dir/mcsapi_types.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/mcsapi.dir/all] Error 2
make: *** [all] Error 2

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.

Generated at Thu Feb 08 02:26:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.