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

EXTRACT(EPOCH from column) #2785

Closed
Tracked by #3148
mkmik opened this issue Jun 24, 2022 · 5 comments · Fixed by #5555
Closed
Tracked by #3148

EXTRACT(EPOCH from column) #2785

mkmik opened this issue Jun 24, 2022 · 5 comments · Fixed by #5555
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@mkmik
Copy link
Contributor

mkmik commented Jun 24, 2022

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Datafusion supports a few date parts like "year" or "seconds" in the EXTRACT operator.

Postgres offers a few more. In particular it offers an EPOCH date part which extracts the number of seconds since 1970-01-01 00:00:00-00 (can be negative).

See https://www.postgresql.org/docs/8.1/functions-datetime.html

My particular use case is using pre-existing grafana postgres plugin, which crafts queries with such a construct. But I think it would be generally useful to support converting a timestamp to a unix epoch.

Describe the solution you'd like

select EXTRACT(EPOCH from column) from mytable;

Describe alternatives you've considered

select CAST(column AS bigint)/1000000000 from mytable;
@mkmik mkmik added the enhancement New feature or request label Jun 24, 2022
@alamb alamb added the good first issue Good for newcomers label Jun 24, 2022
@alamb
Copy link
Contributor

alamb commented Jun 24, 2022

Here is an example of how other parts were added: #1974

This may require adding epoch kernel to arrow, along the lines of apache/arrow-rs#1891 and then adding appropriate support

@mkmik
Copy link
Contributor Author

mkmik commented Jun 24, 2022

I have a draft in #2786 ; I tried it out with datafusion-cli

Next, I'll:

  1. add tests
  2. try to see if I can simplify it and make it use the same macros that we use for the other date field extractors

@alamb
Copy link
Contributor

alamb commented Jan 11, 2023

BTW here is a nice contained test case:

❯ select extract(epoch from '1825-08-29T07:29:01.256'::timestamp);
ArrowError(ExternalError(Execution("Date part 'EPOCH' not supported")))

I think this would be a good first issue

@toprakdeniz
Copy link

toprakdeniz commented Jan 15, 2023 via email

@alamb
Copy link
Contributor

alamb commented Jan 17, 2023

Welcome to the community @toprakdeniz ! We have many first time Rust enthusiasts work on DataFusion and look forward to helping get this feature done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
3 participants