[MCOL-389] cast of int mod function to char results in trailing decimal points Created: 2016-11-06  Updated: 2017-01-16  Resolved: 2017-01-16

Status: Closed
Project: MariaDB ColumnStore
Component/s: DMLProc
Affects Version/s: 1.0.4
Fix Version/s: 1.0.7

Type: Bug Priority: Minor
Reporter: David Thompson (Inactive) Assignee: Daniel Lee (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Sprint: 2016-24, 2016-25, 2017-01

 Description   

The combination of mod and cast seems to result in addition of decimal points in the resulting string for columnstore table data. Note the 3rd query result, this should also be 1.

create table t1(id int) engine=columnstore;
insert into t1 values (1);

MariaDB [loans]> select id from t1;
------

id

------

1

------
1 row in set (0.03 sec)

MariaDB [loans]> select cast(id as char) from t1;
------------------

cast(id as char)

------------------

1

------------------
1 row in set (0.01 sec)

MariaDB [loans]> select cast(mod(id,1024) as char) from t1;
----------------------------

cast(mod(id,1024) as char)

----------------------------

1.000000

----------------------------
1 row in set (0.01 sec)

MariaDB [loans]> select mod(id,1024) from t1;
--------------

mod(id,1024)

--------------

1

--------------
1 row in set (0.01 sec)



 Comments   
Comment by Andrew Hutchings (Inactive) [ 2016-12-19 ]

this is because cast calls getStrVal on the mod() which is part of the 'real' set of functions. With no override the parent class for func_mod calls getDouble() and then converts that. The fix is to implement getStrVal() for func_mod.

Comment by Andrew Hutchings (Inactive) [ 2016-12-19 ]

Added support for int types for mod() instead of casting to double.

For testing, from the original issue:

select cast(mod(id,1024) as char) from t1;

Should return 1.000000 before fix and 1 after fix.

Comment by Daniel Lee (Inactive) [ 2017-01-16 ]

Build tested:

[root@localhost mariadb-columnstore-server]# git show
commit 83b0e5c54a644bc31461752cf73f0e1140586d39
Merge: b975814 93c1c7e
Author: david hill <david.hill@mariadb.com>
Date: Thu Jan 12 09:27:28 2017 -0600

Merge pull request #26 from mariadb-corporation/MCOL-500

Update README.md

MariaDB [mytest]> insert into t1 values (1);
Query OK, 1 row affected (0.04 sec)

MariaDB [mytest]> select * from t1;
------

id

------

1

------
1 row in set (0.11 sec)

MariaDB [mytest]> select cast(id as char) from t1;
------------------

cast(id as char)

------------------

1

------------------
1 row in set (0.01 sec)

MariaDB [mytest]> select cast(mod(id,1024) as char) from t1
-> ;
----------------------------

cast(mod(id,1024) as char)

----------------------------

1

----------------------------
1 row in set (0.01 sec)

MariaDB [mytest]> select mod(id,1024) from t1;
--------------

mod(id,1024)

--------------

1

--------------
1 row in set (0.00 sec)

MariaDB [mytest]> quit
Bye

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