Math Calculation Issues


#1

After upgrading to the new release of MapD, I noticed some result discrepancies in one of our dashboards. After some digging, I’ve narrowed it down to simple mathematical queries. I’ve included 3 screenshots from the Immerse dashboard, as well as the query editor. In addition, I’m including a couple of sample queries below which speak to the odd behavior. So far, I’ve been able to reproduced this in table and number charts, as well as the editor.

Sample Queries (as Custom Measure using a number chart with .2f formating)
1 + 2 -> 3.00 (correct)
1 + 2.0 -> 30.00 (incorrect)
1 + 2.001 -> 3001.00 (incorrect)
COUNT(DISTINCT(name)) -> 7.00 (correct, 7 unique names in my dataset)
COUNT(DISTINCT(name)) + 2 -> 9.00 (correct)
COUNT(DISTINCT(name)) + 2.1 -> 9.1 (correct)
7 + 2.1 -> 91.00 (incorrect)
COUNT(DISTINCT(name)) / 2 -> 3.00 (incorrect)
7 / 2 -> 3.00 (incorrect)
(COUNT(DISTINCT(name)) + 1 ) / 2 -> 4.00 (correct)
(7 + 1) / 2 -> 4 (correct)
(1/2) + (1/2) -> 0 (incorrect)
0.5 + 0.5 -> 10.00 (incorrect)
COUNT(DISTINCT(name))/COUNT(DISTINCT(name))+1.23 -> 2.23 (correct)
COUNT(DISTINCT(name))/COUNT(DISTINCT(name))+(1+0.23) -> correct
1+1+0.23 -> 2.23 (correct)
1+1.23 -> 223.00 (incorrect)

/opt/mapd/bin/mapd_server -v

MapD Version: 4.1.0-20180731-3a391059da


#2

Hi,

Thanks for using MapD and reporting this issue. It appears you have found a bug in out arithmetic decimal literal processing.

We have started on a fix for it. Will be fixed in 4.2.

as a work around if you explicitly CAST the calculation to float you should get the results you want eg

select cast(1+2.2200 as float) from table1 limit 1;

Some of your incorrect result above are actually integer casting results and are correct as far as integer math goes. Things like

7 / 2 -> 3.00

you would need to specify the cast to get the result you want

mapdql> select cast(7 as float) /2  from table1 limit 1;
EXPR$0
3.5

Regards


#3

Thanks for the response!

I went and tried that on the simple queries, and then on our more complex production ones. Looks like it’s patched the issue nicely. Would you happen to know a ballpark timeline of v4.2, just since I wanted to see if it was worth updating all our queries to use CAST (as we have a bit baked into a charting API implementation) or if we should wait it out.

Much appreciated,


#4

Hi,

4.2 should be out around end of next month.

regards