-
Notifications
You must be signed in to change notification settings - Fork 1k
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: Add timestamp arithmetic functionality #6901
Conversation
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.
LGTM, with a few suggestions.
Hey @jzaralim - apologies if this was already debated, perhaps in the klip, and I simply missed it - I'm thinking that it might be easier for our users, and more in line with other common systems, to have a |
@blueedgenick Doesn't |
@blueedgenick If you're thinking of a function that generically adds/subtracts an interval of time from a timestamp, then currently there isn't anything stopping an interval from having a negative value, so |
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.
Cool, thanks @jzaralim. I left some comments. Btw, I'm not sure if using interval as another type. Is there another way to avoid that? Can we specify the right syntax in SqlBase.g4 instead?
Btw, I looked at other DBs, and they use the INTERVAL
keyword in their interval parameters. For instance, date_add(time, INTERVAL '5 hours 5 minutes')
. Snowflake, Postgres and Mysql support it that way. Do you think we should do it too?
ksqldb-functional-tests/src/test/resources/query-validation-tests/timestampadd.json
Show resolved
Hide resolved
); | ||
|
||
// Then: | ||
assertThat(e.getMessage(), containsString("no viable alternative at input 'TIMESTAMPADD(5 HOURS")); |
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.
Is there a way to change this error message? no viable alternative at ...
does not look helpful for users. If the problem is generic for other functions, then we can ignore it for now.
); | ||
|
||
// Then: | ||
assertThat(e.getMessage(), containsString("mismatched input '5' expecting {")); |
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.
Any way to change the error message? Users may get confused about which 5
parameter is.
|
||
@Override | ||
public String toString() { | ||
return "INTERVAL"; |
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.
Is this INTERVAL
string printed somewhere? I wonder if you were adding an INTERVAL keyword, but I didn't not see it.
ksqldb-functional-tests/src/test/resources/query-validation-tests/interval.json
Outdated
Show resolved
Hide resolved
...-execution/src/main/java/io/confluent/ksql/execution/expression/tree/IntervalExpression.java
Outdated
Show resolved
Hide resolved
The main reason interval is its own type is because we need the UDFs to be able to differentiate between regular integers and intervals. I'm not too sure what purpose the |
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.
LGTM. Thanks @jzaralim
Description
This PR adds the functions
timestampadd
andtimestampsub
. Example usages are:In order to do this, a new "type" was introduced,INTERVAL
, that represents an interval of time. Users define them using an IntervalExpression, which consists of numeric expression and a WindowUnit.INTERVAL
can only be used within a function and cannot be used as an actual data type (similar to intervals in MySQL).Testing done
Unit/QTT tests for each of the functions
Reviewer checklist