superset icon indicating copy to clipboard operation
superset copied to clipboard

[sqllab] query result is not accurate

Open luciuschina opened this issue 9 years ago • 18 comments

Make sure these boxes are checked before submitting your issue - thank you!

  • [X] I have checked the superset logs for python stacktraces and included it here as text if any
  • [X] I have reproduced the issue with at least the latest released version of superset
  • [X] I have checked the issue tracker for the same issue and I haven't found one similar

Superset version

0.18.5 0.17.6

Python version

2.7

Expected results

return the accurate bigint field

Actual results

the last two bits in the bigint is wrong

Steps to reproduce

I use sqllab to query mysql tables. My sql statement is : select * from ec_order_main where main_order_no = 401501121320267725. "main_order_no" is the primary key of ec_order_main table,its data type is BIGINT.

Sqllab can find the record,but the 'main_order_no' is 401501121320267700. I expected the "main_order_no" should be "401501121320267725" instead of "401501121320267700". Am I missing something and how can I address this issue? 1

luciuschina avatar Jul 27 '17 03:07 luciuschina

Which database is this? Have you tried doing the same query with the database cli?

xrmx avatar Jul 27 '17 07:07 xrmx

@xrmx This is mysql, and I use other clients, it is OK! 1

luciuschina avatar Jul 27 '17 07:07 luciuschina

Next step is to try the query in pandas, if it's still wrong here then the issue is in pandas.

xrmx avatar Jul 27 '17 07:07 xrmx

OK , I am not very familiar with python and pandas, but I will have a try.

luciuschina avatar Jul 27 '17 07:07 luciuschina

This looks like a good start https://stackoverflow.com/a/25030617/4470501

xrmx avatar Jul 27 '17 07:07 xrmx

A colleague of mine is familiar with python and pandas,he tested this query in pandas: 111 So it seemed that the pandas has no problems。

luciuschina avatar Jul 27 '17 09:07 luciuschina

Thanks for checking! Maybe is this just javascript? On my browser console Number.MAX_SAFE_INTEGER < 401501121320267725 returns true and Number.isSafeInteger(401501121320267725) false.

Reference https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

xrmx avatar Jul 27 '17 09:07 xrmx

So is this a bug ?

luciuschina avatar Jul 27 '17 09:07 luciuschina

That is a weird bug. :/

mistercrunch avatar Jul 29 '17 01:07 mistercrunch

If it's only a visualization bug the sql lab api can cast everything to string?

xrmx avatar Jul 29 '17 09:07 xrmx

Is the value ok in the json ?

mistercrunch avatar Jul 29 '17 15:07 mistercrunch

@mistercrunch I use fiddler to get the result json。It seems the value in json is OK。

1

123232

Although,I set the type of main_order_no filed as VARCHAR in superset, it still doesn't work ! But when I change the field type from BIGINT to VARCHAR in mysql, It can be displayed correctly.

1

luciuschina avatar Jul 31 '17 01:07 luciuschina

Seems like a JS/JSON.parse limitation: https://stackoverflow.com/questions/18755125/node-js-is-there-any-proper-way-to-parse-json-with-large-numbers-long-bigint

mistercrunch avatar Jul 31 '17 03:07 mistercrunch

Most simple way to reproduce:

SELECT 401501121320267725 as test

in SQLLab

rumbin avatar Jul 31 '17 06:07 rumbin

here it states that any number longer than 15 digits is going to be imprecise in javascript. You can try in console:

let b = 123456789012345
b // 123456789012345
b = 12345678901234567
b // 12345678901234568

12345678901234567 is "corrected" to 12345678901234568

dmigo avatar Jul 31 '17 08:07 dmigo

@mistercrunch true, also probably much more fundamental

JS stores numbers as double precision 64 bit format IEEE 754 values. (http://www.ecma-international.org/ecma-262/5.1/#sec-8.5)

I'm guessing this needs to be wrapped in some kind of string format.

jargnar avatar Jul 31 '17 08:07 jargnar

Seems like this is what this does: https://www.npmjs.com/package/json-bigint-string

mistercrunch avatar Aug 02 '17 05:08 mistercrunch

Notice: this issue has been closed because it has been inactive for 264 days. Feel free to comment and request for this issue to be reopened.

mistercrunch avatar Apr 23 '18 05:04 mistercrunch