@cubejs-backend/dremio-driver 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,13 +3,19 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [1.2.1](https://github.com/cube-js/cube/compare/v1.2.0...v1.2.1) (2025-02-06)
6
+ ## [1.2.3](https://github.com/cube-js/cube/compare/v1.2.2...v1.2.3) (2025-02-06)
7
7
 
8
8
  **Note:** Version bump only for package @cubejs-backend/dremio-driver
9
9
 
10
+ ## [1.2.2](https://github.com/cube-js/cube/compare/v1.2.1...v1.2.2) (2025-02-06)
10
11
 
12
+ ### Bug Fixes
11
13
 
14
+ - **dremio-driver:** Correct dremio date interval functions ([#9193](https://github.com/cube-js/cube/issues/9193)) ([7cf2287](https://github.com/cube-js/cube/commit/7cf2287e165beff948ddd88eb47bd0048812aa9b))
12
15
 
16
+ ## [1.2.1](https://github.com/cube-js/cube/compare/v1.2.0...v1.2.1) (2025-02-06)
17
+
18
+ **Note:** Version bump only for package @cubejs-backend/dremio-driver
13
19
 
14
20
  # [1.2.0](https://github.com/cube-js/cube/compare/v1.1.18...v1.2.0) (2025-02-05)
15
21
 
@@ -1,4 +1,5 @@
1
1
  const { BaseFilter, BaseQuery } = require('@cubejs-backend/schema-compiler');
2
+ const { parseSqlInterval } = require('@cubejs-backend/shared');
2
3
 
3
4
  const GRANULARITY_TO_INTERVAL = {
4
5
  week: (date) => `DATE_TRUNC('week', ${date})`,
@@ -55,15 +56,39 @@ class DremioQuery extends BaseQuery {
55
56
  }
56
57
 
57
58
  dateTimeCast(value) {
58
- return `TO_TIMESTAMP(${value})`;
59
+ return `TO_TIMESTAMP(${value}, 'YYYY-MM-DD"T"HH24:MI:SS.FFF')`;
59
60
  }
60
61
 
61
62
  subtractInterval(date, interval) {
62
- return `DATE_SUB(${date}, INTERVAL ${interval})`;
63
+ const formattedTimeIntervals = this.formatInterval(interval);
64
+ const intervalFormatted = formattedTimeIntervals[0];
65
+ const timeUnit = formattedTimeIntervals[1];
66
+ return `DATE_SUB(${date}, CAST(${intervalFormatted} as INTERVAL ${timeUnit}))`;
63
67
  }
64
68
 
65
69
  addInterval(date, interval) {
66
- return `DATE_ADD(${date}, INTERVAL ${interval})`;
70
+ const formattedTimeIntervals = this.formatInterval(interval);
71
+ const intervalFormatted = formattedTimeIntervals[0];
72
+ const timeUnit = formattedTimeIntervals[1];
73
+ return `DATE_ADD(${date}, CAST(${intervalFormatted} as INTERVAL ${timeUnit}))`;
74
+ }
75
+
76
+ /**
77
+ * @param {string} timestamp
78
+ * @param {string} interval
79
+ * @returns {string}
80
+ */
81
+ addTimestampInterval(timestamp, interval) {
82
+ return this.addInterval(timestamp, interval);
83
+ }
84
+
85
+ /**
86
+ * @param {string} timestamp
87
+ * @param {string} interval
88
+ * @returns {string}
89
+ */
90
+ subtractTimestampInterval(timestamp, interval) {
91
+ return this.subtractInterval(timestamp, interval);
67
92
  }
68
93
 
69
94
  timeGroupedColumn(granularity, dimension) {
@@ -78,7 +103,8 @@ class DremioQuery extends BaseQuery {
78
103
  const values = timeDimension.timeSeries().map(
79
104
  ([from, to]) => `select '${from}' f, '${to}' t`
80
105
  ).join(' UNION ALL ');
81
- return `SELECT TO_TIMESTAMP(dates.f, 'YYYY-MM-DDTHH:MI:SS.FFF') date_from, TO_TIMESTAMP(dates.t, 'YYYY-MM-DDTHH:MI:SS.FFF') date_to FROM (${values}) AS dates`;
106
+
107
+ return `SELECT TO_TIMESTAMP(dates.f, 'YYYY-MM-DD"T"HH24:MI:SS.FFF') date_from, TO_TIMESTAMP(dates.t, 'YYYY-MM-DD"T"HH24:MI:SS.FFF') date_to FROM (${values}) AS dates`;
82
108
  }
83
109
 
84
110
  concatStringsSql(strings) {
@@ -92,6 +118,55 @@ class DremioQuery extends BaseQuery {
92
118
  wrapSegmentForDimensionSelect(sql) {
93
119
  return `IF(${sql}, 1, 0)`;
94
120
  }
121
+
122
+ /**
123
+ * 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", ...
124
+ * will be converted to Dremio dialect.
125
+ * @see https://docs.dremio.com/24.3.x/reference/sql/sql-functions/functions/DATE_ADD/
126
+ * @see https://docs.dremio.com/24.3.x/reference/sql/sql-functions/functions/DATE_SUB/
127
+ * It returns a tuple of (formatted interval, timeUnit to use in date functions)
128
+ * This function only supports the following scenarios for now:
129
+ * ie. n year[s] or n quarter[s] or n month[s] or n week[s] or n day[s]
130
+ */
131
+ formatInterval(interval) {
132
+ const intervalParsed = parseSqlInterval(interval);
133
+ const intKeys = Object.keys(intervalParsed).length;
134
+
135
+ if (intervalParsed.year && intKeys === 1) {
136
+ return [`${intervalParsed.year}`, 'YEAR'];
137
+ } else if (intervalParsed.quarter && intKeys === 1) {
138
+ // dremio interval does not support quarter. Convert to month
139
+ return [`${intervalParsed.quarter * 3}`, 'MONTH'];
140
+ } else if (intervalParsed.week && intKeys === 1) {
141
+ // dremio interval does not support week. Convert to days
142
+ return [`${intervalParsed.week * 7}`, 'DAY'];
143
+ } else if (intervalParsed.month && intKeys === 1) {
144
+ return [`${intervalParsed.month}`, 'MONTH'];
145
+ } else if (intervalParsed.month && intKeys === 1) {
146
+ return [`${intervalParsed.day}`, 'DAY'];
147
+ } else if (intervalParsed.hour && intKeys === 1) {
148
+ return [`${intervalParsed.hour}`, 'HOUR'];
149
+ } else if (intervalParsed.minute && intKeys === 1) {
150
+ return [`${intervalParsed.minute}`, 'MINUTE'];
151
+ } else if (intervalParsed.second && intKeys === 1) {
152
+ return [`${intervalParsed.second}`, 'SECOND'];
153
+ }
154
+
155
+ throw new Error(`Cannot transform interval expression "${interval}" to Dremio dialect`);
156
+ }
157
+
158
+ sqlTemplates() {
159
+ const templates = super.sqlTemplates();
160
+ templates.functions.CURRENTDATE = 'CURRENT_DATE';
161
+ templates.functions.DATETRUNC = 'DATE_TRUNC(\'{{ date_part }}\', {{ args_concat }})';
162
+ templates.functions.DATEPART = 'DATE_PART(\'{{ date_part }}\', {{ args_concat }})';
163
+ // really need the date locale formatting here...
164
+ templates.functions.DATE = 'TO_DATE({{ args_concat }},\'YYYY-MM-DD\', 1)';
165
+ templates.functions.DATEDIFF = 'DATE_DIFF(DATE, DATE_TRUNC(\'{{ date_part }}\', {{ args[1] }}), DATE_TRUNC(\'{{ date_part }}\', {{ args[2] }}))';
166
+ templates.expressions.interval_single_date_part = 'CAST({{ num }} as INTERVAL {{ date_part }})';
167
+ templates.quotes.identifiers = '"';
168
+ return templates;
169
+ }
95
170
  }
96
171
 
97
172
  module.exports = DremioQuery;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@cubejs-backend/dremio-driver",
3
3
  "description": "Cube.js Dremio driver",
4
4
  "author": "Cube Dev, Inc.",
5
- "version": "1.2.1",
5
+ "version": "1.2.3",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/cube-js/cube.git",
@@ -22,15 +22,15 @@
22
22
  "lint:fix": "eslint driver/*.js"
23
23
  },
24
24
  "dependencies": {
25
- "@cubejs-backend/base-driver": "1.2.1",
26
- "@cubejs-backend/schema-compiler": "1.2.1",
27
- "@cubejs-backend/shared": "1.2.1",
25
+ "@cubejs-backend/base-driver": "1.2.3",
26
+ "@cubejs-backend/schema-compiler": "1.2.3",
27
+ "@cubejs-backend/shared": "1.2.3",
28
28
  "axios": "^0.21.1",
29
29
  "sqlstring": "^2.3.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@cubejs-backend/linter": "1.2.1",
33
- "@cubejs-backend/testing-shared": "1.2.1",
32
+ "@cubejs-backend/linter": "1.2.3",
33
+ "@cubejs-backend/testing-shared": "1.2.3",
34
34
  "jest": "^27"
35
35
  },
36
36
  "license": "Apache-2.0",
@@ -46,5 +46,5 @@
46
46
  "eslintConfig": {
47
47
  "extends": "../cubejs-linter"
48
48
  },
49
- "gitHead": "882a4436d0b1966ec7a6a5dd7faad9c7d99a7f2a"
49
+ "gitHead": "18909fe0dbe2b89a34c2d73a12c8e3a05c2e0ee2"
50
50
  }