-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Correct dremio date interval functions #9150
base: master
Are you sure you want to change the base?
Conversation
@@ -59,11 +59,27 @@ class DremioQuery extends BaseQuery { | |||
} | |||
|
|||
subtractInterval(date, interval) { | |||
return `DATE_SUB(${date}, INTERVAL ${interval})`; | |||
const intervalParts = interval.trim().split(' '); |
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.
Unfortunately, intervals are a bit more complicated. You can get here interval values like:
- 1 hour 2 minutes
- 3 month
- 3 months 24 days 15 minutes
- 2 years 6 months
- Etc....
Please, have a look at some examples of interval processing in different dialects that might give you an idea how to process it here:
public subtractInterval(date: string, interval: string) { - https://github.com/cube-js/cube/blob/master/packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts#L180
- https://github.com/cube-js/cube/blob/master/packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.ts#L84
Have a look at formatInterval()
implementations in these query dialects.
Hope this helps!
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.
Many thanks for the info. I have sent a further change. It only supports year,qtr,month and day for now. I've taken examples from the other drivers as per suggestions above.
…cube into dremio-date-interval-fix Sync branch before push to origin. Need to correct lint failures
/** | ||
* The input interval with (possible) plural units, like "1 hour 2 minutes", "2 year", "3 months", "4 weeks", "5 days", "3 months 24 days 15 minutes", ... | ||
* will be converted to Dremio dialect. | ||
* @see https://docs.dremio.com/24.3.x/reference/sql/sql-functions/functions/DATE_ADD/ |
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.
Looking at the docs, I see that Dremio supports more intervals for timestamps.
DATE_ADD(timestamp_expression string, time_interval interval) → timestamp
timestamp_expression: A string-formatted timestamp in the format 'YYYY-MM-DD HH24:MI:SS'.
time_interval: A CAST of a number to one of these intervals: SECOND, MINUTE, HOUR, DAY, MONTH, YEAR.
So i think they should be supported here too :)
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.
Agreed, we also need to support a week method as well in the same way the quarter is calculated.
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.
Please add support for SECOND, MINUTE, HOUR
There are these functions defined in base class that you can override: /**
* @param {string} timestamp
* @param {string} interval
* @returns {string}
*/
addTimestampInterval(timestamp, interval) {
return this.addInterval(timestamp, interval);
}
/**
* @param {string} timestamp
* @param {string} interval
* @returns {string}
*/
subtractTimestampInterval(timestamp, interval) {
return this.subtractInterval(timestamp, interval);
} |
Another thing I missed: you should also provide the template for INTERVAL that might be used by SQL API.
|
Check List
Issue Reference this PR resolves
In the dremio driver (query) the syntax for DATE_ADD and DATE_SUB are incorrect. The interval function requires a cast and the positional arguments need correcting.