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

support make_interval function #6951

Open
Tracked by #8282 ...
liukun4515 opened this issue Jul 13, 2023 · 5 comments
Open
Tracked by #8282 ...

support make_interval function #6951

liukun4515 opened this issue Jul 13, 2023 · 5 comments
Assignees

Comments

@liukun4515
Copy link
Contributor

          Do we have any method to convert or cast the integer type/integer expr with the timeunit to the interval?

@waitingkuo @alamb

I want to implement a app or function like this datetime + integer with timeunit, and the timeunit may be year,month,day.

I can't find the any method to convert the integer with timeunit to the interval, but in the PG which has a function make_interval() https://www.postgresql.org/docs/current/functions-datetime.html can do this.

I just can find a way to resolve the issue by using the concat method.

For example: I have a table like below, and want to convert the b with dayunit to interval

❯ \d test
+---------------+--------------+------------+-------------+-----------+-------------+
| table_catalog | table_schema | table_name | column_name | data_type | is_nullable |
+---------------+--------------+------------+-------------+-----------+-------------+
| datafusion    | public       | test       | a           | Date32    | NO          |
| datafusion    | public       | test       | b           | Int64     | NO          |
+---------------+--------------+------------+-------------+-----------+-------------+
2 rows in set. Query took 0.013 seconds.

Using the concat to get the utf8 expr which can be casted to interval.

❯   select cast(concat(b,' day') as interval), b from test;
+-------------------------------------------------------+---+
| concat(test.b,Utf8(" day"))                           | b |
+-------------------------------------------------------+---+
| 0 years 0 mons 2 days 0 hours 0 mins 0.000000000 secs | 2 |
+-------------------------------------------------------+---+

Originally posted by @liukun4515 in #3148 (comment)

@liukun4515
Copy link
Contributor Author

cc @alamb @waitingkuo please help to add this issue to #3148

@waitingkuo
Copy link
Contributor

@liukun4515
added, thank you

@waitingkuo
Copy link
Contributor

hi @liukun4515

Do you plan to support multiple time unit? for example column a as year, column b as month

@alamb
Copy link
Contributor

alamb commented Jul 13, 2023

I adding the make_interval function seems very reasonable to me.

arrow knows how to parse strings like 5 days 4 minutes so you could build up such a string using concat. However, if you already have the fields and you know what output interval type you want/need doing it with a specific function would likely be much more performant

@Tangruilin
Copy link
Contributor

@alamb Maybe you can assign it to me.

I can help with this issue

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

No branches or pull requests

4 participants