-
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
Implement current_time
scalar function
#4054
Conversation
LGTM, thank you @naosense |
I followed @comphead 's
but it reported an error
Is anything i missed? |
If there are multiple current_time() in a SQL statement, will it be invoked multiple times or just once ? |
casting |
@naosense ❯ select (now()::bigint % 86400000000000)::time;
+-------------------------------+
| now() % Int64(86400000000000) |
+-------------------------------+
| 07:41:27.421667 |
+-------------------------------+ i'll be great if you could fire a issue (or even a pr) to arrow-rs to support cast Timestamp to Time |
Arc::new(datetime_expressions::make_current_time( | ||
execution_props.query_execution_start_time, | ||
)) |
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.
👍
@mingmwang all the current_time within a query uses the same query_execution_start_time
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.
thank you @naosense
let nano = | ||
Some(now_ts.timestamp_nanos() % 86400000000000); | ||
move |_arg| Ok(ColumnarValue::Scalar(ScalarValue::Time64(nano))) |
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.
👍
let sql = "select case when current_time() = (now()::bigint % 86400000000000)::time then 'OK' else 'FAIL' end result"; | ||
let results = execute_to_batches(&ctx, sql).await; | ||
|
||
let expected = vec![ | ||
"+--------+", | ||
"| result |", | ||
"+--------+", | ||
"| OK |", | ||
"+--------+", | ||
]; |
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.
👍
it's a pleasure, I'll investigate how to do that |
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.
This looks great @naosense . Thanks @waitingkuo for the review!
Hi @naosense -- it seems this PR needs to have |
Thanks again @naosense and @waitingkuo ! |
Benchmark runs are scheduled for baseline = 8c26530 and contender = 97f2e4f. 97f2e4f is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
* implement `current_time` * edit test case * fix nanosecond after midnight * fix: fmt Co-authored-by: pingao <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
Which issue does this PR close?
Closes #3982 .
Rationale for this change
DataFusion users need to be able to use the current time to calculate things like "all data in the last 5 hours"
What changes are included in this PR?
Scalar
current_time
functionAre there any user-facing changes?