Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Contributor 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