Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
20 changes: 18 additions & 2 deletions packages/cubejs-dremio-driver/driver/DremioQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,27 @@ class DremioQuery extends BaseQuery {
}

subtractInterval(date, interval) {
return `DATE_SUB(${date}, INTERVAL ${interval})`;
const intervalParts = interval.trim().split(' ');
Copy link
Member

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:

Have a look at formatInterval() implementations in these query dialects.
Hope this helps!

Copy link
Author

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.

const intervalNumber = parseInt(intervalParts[0]);
const intervalName = intervalParts[1].toLowerCase();
if (intervalName == 'quarter') {
intervalParts[0] = intervalNumber * 3;
intervalParts[1] = 'month';
}

return `DATE_SUB(${date}, CAST(${intervalParts[0]} as INTERVAL ${intervalParts[1]}))`;
}

addInterval(date, interval) {
return `DATE_ADD(${date}, INTERVAL ${interval})`;
const intervalParts = interval.trim().split(' ');
const intervalNumber = parseInt(intervalParts[0]);
const intervalName = intervalParts[1].toLowerCase();
if (intervalName == 'quarter') {
intervalParts[0] = intervalNumber * 3;
intervalParts[1] = 'month';
}

return `DATE_ADD(${date}, CAST(${intervalParts[0]} as INTERVAL ${intervalParts[1]}))`;
}

timeGroupedColumn(granularity, dimension) {
Expand Down