-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
DataFusion supports a few literal expression types for a VALUES list clause:
SELECT
*
FROM (
VALUES (5, 'foo')
) as t (col1, col2)However, typed string literals, like a TIMESTAMP are not supported:
select * from (VALUES (TIMESTAMP '2021-06-10 17:01:00Z')) as t (time);NotImplemented("Unsupported value TypedString { data_type: Timestamp, value: \"2021-06-10 17:01:00Z\" } in a values list expression")
Every time we wish to refer to the time column as a TIMESTAMP, we have to CAST it first, such as in this contrived example:
SELECT DATE_TRUNC('minute', CAST(time AS TIMESTAMP)) AS time
FROM (
VALUES ('2021-06-10 17:01:30Z')
) as t (time)
WHERE CAST(time AS TIMESTAMP) > TIMESTAMP '2021-01-01 00:00:00';+---------------------+
| time |
+---------------------+
| 2021-06-10 17:01:00 |
+---------------------+
1 row in set. Query took 0.004 seconds.
See the next section for the improved user experience.
Describe the solution you'd like
Add support for typed string literals to a VALUES list. As demonstrated below, the SQL statement becomes less verbose and clarifies the intent by using strict column types:
SELECT DATE_TRUNC('minute', time) AS time
FROM (
VALUES (TIMESTAMP '2021-06-10 17:01:30Z')) as t (time)
WHERE time > TIMESTAMP '2021-01-01 00:00:00';+---------------------+
| time |
+---------------------+
| 2021-06-10 17:01:00 |
+---------------------+
1 row in set. Query took 0.007 seconds.
Describe alternatives you've considered
A workaround is possible, however, PostgreSQL supports this syntax, so it would be consistent for DataFusion to provide a similar experience.