Skip to content
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

Fix Date32 and Date64 literals unparsing for SQLite #20

Conversation

sgrebnov
Copy link
Collaborator

@sgrebnov sgrebnov commented Jul 25, 2024

SQLite date instead of datetime should be used for Date32 and Date64 literals unparsing, example for TPCH orders table:

SELECT 
    o_orderdate, 
    datetime(757382400, 'unixepoch') AS v1,
    date(757382400, 'unixepoch') AS v2,
    o_orderdate = datetime(757382400, 'unixepoch') AS is_v1_equal,
    o_orderdate = date(757382400, 'unixepoch') AS is_v2_equal
FROM 
    orders o 
WHERE 
    o.o_orderkey = 32418;

image

select
    n_name,
    o_orderdate
from
    customer,
    orders,
    lineitem,
    supplier,
    nation,
    region
where
        c_custkey = o_custkey
  and l_orderkey = o_orderkey
  and l_suppkey = s_suppkey
  and c_nationkey = s_nationkey
  and s_nationkey = n_nationkey
  and n_regionkey = r_regionkey
  and r_name = 'ASIA'
  and o_orderdate >= date '1994-01-01'
  and o_orderdate < date '1995-01-01'
  and n_name = 'INDIA'
ORDER BY o_orderdate

Before this change (1994-01-01 is missing)

+--------+-------------+
| n_name | o_orderdate |
+--------+-------------+
| INDIA  | 1994-01-09  |
| INDIA  | 1994-03-23  |
| INDIA  | 1994-04-27  |
| INDIA  | 1994-05-20  |
| INDIA  | 1994-05-26  |
| INDIA  | 1994-06-27  |
| INDIA  | 1994-08-06  |
| INDIA  | 1994-08-12  |
| INDIA  | 1994-09-01  |
| INDIA  | 1994-09-17  |
| INDIA  | 1994-09-28  |
| INDIA  | 1994-10-21  |
| INDIA  | 1994-10-24  |
| INDIA  | 1994-12-08  |
| INDIA  | 1994-12-23  |
+--------+-------------+

After

+--------+-------------+
| n_name | o_orderdate |
+--------+-------------+
| INDIA  | 1994-01-01  |
| INDIA  | 1994-01-09  |
| INDIA  | 1994-03-23  |
| INDIA  | 1994-04-27  |
| INDIA  | 1994-05-20  |
| INDIA  | 1994-05-26  |
| INDIA  | 1994-06-27  |
| INDIA  | 1994-08-06  |
| INDIA  | 1994-08-12  |
| INDIA  | 1994-09-01  |
| INDIA  | 1994-09-17  |
| INDIA  | 1994-09-28  |
| INDIA  | 1994-10-21  |
| INDIA  | 1994-10-24  |
| INDIA  | 1994-12-08  |
| INDIA  | 1994-12-23  |
+--------+-------------+

@phillipleblanc phillipleblanc merged commit 16d871e into datafusion-contrib:main Jul 26, 2024
2 checks passed
@sgrebnov sgrebnov deleted the sgrebnov/sqlite-fix-date-casting branch August 1, 2024 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants