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

Proposal: Enable typed strings expressions for VALUES clause #3017

Closed
stuartcarnie opened this issue Aug 3, 2022 · 0 comments · Fixed by #3018
Closed

Proposal: Enable typed strings expressions for VALUES clause #3017

stuartcarnie opened this issue Aug 3, 2022 · 0 comments · Fixed by #3018
Labels
enhancement New feature or request

Comments

@stuartcarnie
Copy link
Contributor

stuartcarnie commented Aug 3, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant