-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
date_part
support fractions of second
#4385
Conversation
@waitingkuo finally we can get back to #3997 resolution. Now date_part supports second fraction, but its still not the same as in PSQL like
To do the same you need to run
Let me know if this is ok |
hi @comphead thank you i tested the pr ❯ select date_part('second', timestamp '2000-01-01T00:00:09.123456');
+-------------------------------------------------------------+
| datepart(Utf8("second"),Utf8("2000-01-01T00:00:09.123456")) |
+-------------------------------------------------------------+
| 9 |
+-------------------------------------------------------------+
1 row in set. Query took 0.002 seconds.
❯ select date_part('millisecond', timestamp '2000-01-01T00:00:09.123456');
+------------------------------------------------------------------+
| datepart(Utf8("millisecond"),Utf8("2000-01-01T00:00:09.123456")) |
+------------------------------------------------------------------+
| 123 |
+------------------------------------------------------------------+
1 row in set. Query took 0.002 seconds.
❯ select date_part('microsecond', timestamp '2000-01-01T00:00:09.123456');
+------------------------------------------------------------------+
| datepart(Utf8("microsecond"),Utf8("2000-01-01T00:00:09.123456")) |
+------------------------------------------------------------------+
| 123456 |
+------------------------------------------------------------------+
1 row in set. Query took 0.002 seconds. the behavior is different than what postgresql has willy=# select date_part('second', timestamp '2000-01-01T00:00:09.123456');
date_part
-----------
9.123456
(1 row)
willy=# select date_part('millisecond', timestamp '2000-01-01T00:00:09.123456');
date_part
-----------
9123.456
(1 row)
willy=# select date_part('microsecond', timestamp '2000-01-01T00:00:09.123456');
date_part
-----------
9123456
(1 row) i checked some other system, # this is spark
SELECT date_part('SECONDS', timestamp'2019-10-01 00:00:01.000001');
+----------------------------------------------------------+
|date_part(SECONDS, TIMESTAMP '2019-10-01 00:00:01.000001')|
+----------------------------------------------------------+
| 1.000001|
+----------------------------------------------------------+ while mysql's is similar as this pr # this is MYSQL
EXTRACT(SECOND FROM "2017-06-20 00:00:01.123456");
1 I originally purposed to output f64 instead of i32 since i'd like to follow postgresql's @alamb @tustvold do you have any suggestion? |
Thanks @waitingkuo for testing the PR. I think since we now having seconds fraction support so we can concat the value and be in sync with postgres date_part if this is a preferred way |
I think we should follow postgres (output floating point) if possible |
# Conflicts: # datafusion/physical-expr/src/datetime_expressions.rs
…afusion into date_part_f64 # Conflicts: # datafusion/physical-expr/src/datetime_expressions.rs
@waitingkuo made in sync with postgres.
whereas nanosecond date_part works. I will create a ticket for this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @comphead thank you, this looks good to me.
// test_expression!( | ||
// "EXTRACT(nanosecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))", | ||
// "1212345678" | ||
// ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i suggest that uncomment this test case and expect the error
e.g. like this https://github.com/apache/arrow-datafusion/blob/740a4fa2c6ba4b85875a433bb86e5b00435a5969/datafusion/core/tests/sql/timestamp.rs#L1071-L1074
@comphead sqlparser doesn't support nanosecond for now. |
@comphead i created a ticket and submitted a pr in sqlparser apache/datafusion-sqlparser-rs#748 it would be great if you could creat another ticket in datafusion so that we could fix it once the issue in sqlparser merged and new version released |
#4528 |
Thanks @comphead and @waitingkuo ! |
Benchmark runs are scheduled for baseline = 19cddf5 and contender = cedb05a. cedb05a is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Which issue does this PR close?
Closes #3997
Rationale for this change
See #3997
What changes are included in this PR?
Extending
date_part
to support millis, micros, nanosAre these changes tested?
Yes
Are there any user-facing changes?
No
No