BlazingDB / blazingsql

BlazingSQL is a lightweight, GPU accelerated, SQL engine for Python. Built on RAPIDS cuDF.
https://blazingsql.com
Apache License 2.0
1.92k stars 181 forks source link

[BUG] TIMESTAMPADD and TIMESTAMPDIFF produce wrong results #1448

Closed drabastomek closed 3 years ago

drabastomek commented 3 years ago

Describe the bug These SQL functions produce a valid RAL but return wrong results i.e. the BSQL engine technically supports these functions but in reality, the results are not correct.

Steps/Code to reproduce bug

import blazingsql as bsql
import cudf

df = cudf.DataFrame({'datetime': [
    np.datetime64('2020-10-15T10:58:02') 
    , np.datetime64('2020-10-01T10:02:23') 
    , np.datetime64('2020-09-30T14:36:26') 
    , np.datetime64('2020-10-10T08:34:36') 
    , np.datetime64('2020-10-09T08:34:40') 
    , np.datetime64('2020-10-03T03:31:21') 
    , np.datetime64('2020-10-05T03:21:28')
]})
bc = bsql.BlazingContext()
bc.create_table('dates_table', df)

bc.sql('''
    SELECT datetime,
        TIMESTAMP'2020-11-10 12:00:01' AS datetime2,
        TIMESTAMPDIFF(DAY, datetime, TIMESTAMP'2020-11-10 12:00:01') AS diff,
        TIMESTAMPADD(HOUR, 2, datetime) AS add
    FROM dates_table
''')

The above produces the following table

datetime datetime2 diff add
2020-10-15 10:58:02 2020-11-10 12:00:01 1396630809 2021-01-06 18:58:02
2020-10-01 10:02:23 2020-11-10 12:00:01 1396630809 2020-12-23 18:02:23
2020-09-30 14:36:26 2020-11-10 12:00:01 1396630809 2020-12-22 22:36:26
2020-10-10 08:34:36 2020-11-10 12:00:01 1396630809 2021-01-01 16:34:36
2020-10-09 08:34:40 2020-11-10 12:00:01 1396630809 2020-12-31 16:34:40
2020-10-03 03:31:21 2020-11-10 12:00:01 1396630809 2020-12-25 11:31:21
2020-10-05 03:21:28 2020-11-10 12:00:01 1396630809 2020-12-27 11:21:28

Expected behavior Proper values are returned

datetime datetime2 diff add
2020-10-15 10:58:02 2020-11-10 12:00:01 26 2020-10-15 12:58:02
2020-10-01 10:02:23 2020-11-10 12:00:01 40 2020-10-01 12:02:23
2020-09-30 14:36:26 2020-11-10 12:00:01 40 2020-09-30 16:36:26
2020-10-10 08:34:36 2020-11-10 12:00:01 31 2020-10-10 10:34:36
2020-10-09 08:34:40 2020-11-10 12:00:01 32 2020-10-09 10:34:40
2020-10-03 03:31:21 2020-11-10 12:00:01 38 2020-10-03 05:31:21
2020-10-05 03:21:28 2020-11-10 12:00:01 36 2020-10-05 05:21:28

Environment overview (please complete the following information)