-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql result discrepency with sqlite, postgres and duckdb bug #2 #13782
Comments
Another example of what is probably the same cause: Datafusion > SELECT ALL + + 84 * + - COUNT ( * ) * - - COALESCE ( + 37, + 14 ) * - NULLIF ( CASE + + COUNT ( * ) WHEN 54 THEN NULL ELSE + 91 + + - 60 * - 23 END, ( + CAST ( + 96 AS REAL ) ) ) * + 14 col2;
+------------+
| col2 |
+------------+
| 64006150.0 |
+------------+
1 row(s) fetched. duckdb and postgres: D SELECT ALL + + 84 * + - COUNT ( * ) * - - COALESCE ( + 37, + 14 ) * - NULLIF ( CASE + + COUNT ( * ) WHEN 54 THEN NULL ELSE + 91 + + - 60 * - 23 END, ( + CAST ( + 96 AS REAL ) ) ) * + 14 col2;;
┌──────────┐
│ col2 │
│ int64 │
├──────────┤
│ 64006152 │
└──────────┘ |
Out of interest I looked into this a bit and wanted to share my findings. > SELECT - 4588 - 213220800 * NULLIF (1, CAST ( NULL AS REAL )) col1;
+--------------+
| col1 |
+--------------+
| -213225390.0 |
+--------------+ duckdb D SELECT - 4588 - 213220800 * NULLIF (1, CAST ( NULL AS REAL )) col1;
┌────────────┐
│ col1 │
│ int32 │
├────────────┤
│ -213225388 │
└────────────┘ Looking at just the nullif: SELECT NULLIF (1, CAST ( NULL AS REAL ));
+-----------------------+
| nullif(Int64(1),NULL) |
+-----------------------+
| 1.0 |
+-----------------------+ duckdb SELECT NULLIF (1, CAST ( NULL AS REAL ));
┌──────────────────────────────────┐
│ "nullif"(1, CAST(NULL AS FLOAT)) │
│ int32 │
├──────────────────────────────────┤
│ 1 │
└──────────────────────────────────┘ The documentation of nullif mentions that this is slightly different than postgres / duckdb: datafusion/datafusion/functions/src/core/nullif.rs Lines 44 to 56 in 63265fd
Maybe this helps someone with the investigation. |
It's not the nullif, it's the real datatype: > SELECT 1 - 213220800 * 1::REAL;
+----------------------------------------+
| Int64(1) - Int64(213220800) * Int64(1) |
+----------------------------------------+
| -213220800.0 |
+----------------------------------------+
1 row(s) fetched.
Elapsed 0.001 seconds.
> SELECT 1 - 213220800 * 1.0;
+------------------------------------------+
| Int64(1) - Int64(213220800) * Float64(1) |
+------------------------------------------+
| -213220799.0 |
+------------------------------------------+
1 row(s) fetched.
Elapsed 0.001 seconds.
> SELECT 1 - 213220800 * 1;
+----------------------------------------+
| Int64(1) - Int64(213220800) * Int64(1) |
+----------------------------------------+
| -213220799 |
+----------------------------------------+
1 row(s) fetched.
Elapsed 0.001 seconds.
There is something with the 'real' datatype that is breaking things. I am unsure why |
Thanks for your response @Omega359, I agree that the unexpected result is calculated due to calculations using the I also agree that SELECT 1::DOUBLE;
+----------+
| Int64(1) |
+----------+
| 1.0 |
+----------+ is also shown as Int64 in datafusion. Using > SELECT arrow_typeof(1::DOUBLE);
+------------------------+
| arrow_typeof(Int64(1)) |
+------------------------+
| Float64 |
+------------------------+
> SELECT arrow_typeof(1::REAL);
+------------------------+
| arrow_typeof(Int64(1)) |
+------------------------+
| Float32 |
+------------------------+ |
After fixing the test suite locally to use float8 instead of real (to mirror the actual data type that sqlite uses - 8 bytes for real vs 4 bytes for DF/postgres) the errors in this issue no longer occur. |
Resolved as fixed with change 'as REAL' to 'AS FLOAT8' in sqlite test files |
Describe the bug
Datafusion:
duckdb and postgres:
Duckdb and sqlite have the result as an int, DF and postgres as float.
To Reproduce
sql above.
Expected behavior
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: