-
Notifications
You must be signed in to change notification settings - Fork 326
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
feat: support first_value/last_value
in range query
#3448
feat: support first_value/last_value
in range query
#3448
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3448 +/- ##
==========================================
+ Coverage 85.00% 85.01% +0.01%
==========================================
Files 889 896 +7
Lines 146596 147711 +1115
==========================================
+ Hits 124613 125579 +966
- Misses 21983 22132 +149 |
Datafusion already has these two functions, see https://arrow.apache.org/datafusion/user-guide/sql/aggregate_functions.html#last-value, why implement our own? |
Because the DataFusion's |
@Taylor-lagrange Users are already able to execute "last_value" in range query like this: select last_value(`c` order by `ts`) range '1s' as `c`, ts from test
where a = 'x' and ts > 1706716800000000 and ts < 1706803200000000
align '1s' to '2023-12-01T00:00:00' by (a) order by ts asc What's the difference with the new "last/first" functions? |
The point is to provide a gramma candy inside range query, where the time index column is considered special. So in range query the |
The execution logic of DataFusion If DataFusion's
If user use |
The implementation of range plan only reuses the |
These guarantees are mainly about the orderliness of the input, but there are only a few of these functions, only |
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.
Can you show an example of wrong result of Datafusion's last_value in range query?
Because most of the time when use |
@Taylor-lagrange Please add that case in your sqlness test. |
Considering the |
I hereby agree to the terms of the GreptimeDB CLA.
Refer to a related PR or issue link (optional)
What's changed and what's your intention?
first/last
aggregate function (In DataFusion, the function callfirst_value/last_value
) in range query. When user specifyorder by
param infirst_value/last_value
, the data will be sort byorder by
param, elsetime index
will be defaultorder by
param to sort the data.count(*)
in range query.Checklist
Closes #3460