@quillsql/react 2.12.30 → 2.12.32

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.
Files changed (201) hide show
  1. package/dist/cjs/Chart.d.ts +6 -37
  2. package/dist/cjs/Chart.d.ts.map +1 -1
  3. package/dist/cjs/Chart.js +86 -327
  4. package/dist/cjs/ChartBuilder.d.ts +12 -49
  5. package/dist/cjs/ChartBuilder.d.ts.map +1 -1
  6. package/dist/cjs/ChartBuilder.js +68 -36
  7. package/dist/cjs/ChartEditor.d.ts +1 -1
  8. package/dist/cjs/ChartEditor.d.ts.map +1 -1
  9. package/dist/cjs/ChartEditor.js +11 -7
  10. package/dist/cjs/Context.d.ts +4 -1
  11. package/dist/cjs/Context.d.ts.map +1 -1
  12. package/dist/cjs/Context.js +10 -4
  13. package/dist/cjs/Dashboard.d.ts +61 -114
  14. package/dist/cjs/Dashboard.d.ts.map +1 -1
  15. package/dist/cjs/Dashboard.js +261 -30
  16. package/dist/cjs/DateRangePicker/DateRangePicker.d.ts.map +1 -1
  17. package/dist/cjs/DateRangePicker/DateRangePicker.js +0 -26
  18. package/dist/cjs/ReportBuilder.d.ts +1 -1
  19. package/dist/cjs/ReportBuilder.d.ts.map +1 -1
  20. package/dist/cjs/ReportBuilder.js +62 -97
  21. package/dist/cjs/SQLEditor.d.ts +2 -2
  22. package/dist/cjs/SQLEditor.d.ts.map +1 -1
  23. package/dist/cjs/SQLEditor.js +10 -5
  24. package/dist/cjs/Table.d.ts.map +1 -1
  25. package/dist/cjs/Table.js +41 -43
  26. package/dist/cjs/components/Chart/BarChart.d.ts.map +1 -1
  27. package/dist/cjs/components/Chart/BarChart.js +12 -1
  28. package/dist/cjs/components/Chart/LineChart.d.ts +2 -1
  29. package/dist/cjs/components/Chart/LineChart.d.ts.map +1 -1
  30. package/dist/cjs/components/Chart/LineChart.js +25 -1
  31. package/dist/cjs/components/Dashboard/DataLoader.d.ts +7 -7
  32. package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
  33. package/dist/cjs/components/Dashboard/DataLoader.js +64 -28
  34. package/dist/cjs/components/Dashboard/MetricComponent.d.ts.map +1 -1
  35. package/dist/cjs/components/Dashboard/MetricComponent.js +11 -45
  36. package/dist/cjs/components/Dashboard/TableComponent.d.ts +1 -1
  37. package/dist/cjs/components/Dashboard/TableComponent.d.ts.map +1 -1
  38. package/dist/cjs/components/Dashboard/TableComponent.js +1 -30
  39. package/dist/cjs/components/QuillMultiSelectWithCombo.d.ts.map +1 -1
  40. package/dist/cjs/components/QuillMultiSelectWithCombo.js +16 -1
  41. package/dist/cjs/components/QuillSelectWithCombo.d.ts.map +1 -1
  42. package/dist/cjs/components/QuillSelectWithCombo.js +4 -1
  43. package/dist/cjs/components/ReportBuilder/FilterModal.d.ts +10 -2
  44. package/dist/cjs/components/ReportBuilder/FilterModal.d.ts.map +1 -1
  45. package/dist/cjs/components/ReportBuilder/FilterModal.js +94 -70
  46. package/dist/cjs/components/ReportBuilder/convert.d.ts +7 -2
  47. package/dist/cjs/components/ReportBuilder/convert.d.ts.map +1 -1
  48. package/dist/cjs/components/ReportBuilder/convert.js +53 -1
  49. package/dist/cjs/components/ReportBuilder/ui.d.ts +6 -6
  50. package/dist/cjs/components/ReportBuilder/ui.d.ts.map +1 -1
  51. package/dist/cjs/components/ReportBuilder/ui.js +6 -22
  52. package/dist/cjs/components/UiComponents.d.ts +26 -1
  53. package/dist/cjs/components/UiComponents.d.ts.map +1 -1
  54. package/dist/cjs/components/UiComponents.js +97 -4
  55. package/dist/cjs/hooks/useQuill.d.ts.map +1 -1
  56. package/dist/cjs/hooks/useQuill.js +19 -3
  57. package/dist/cjs/index.d.ts +2 -1
  58. package/dist/cjs/index.d.ts.map +1 -1
  59. package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts +1 -0
  60. package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
  61. package/dist/cjs/models/Columns.d.ts +2 -1
  62. package/dist/cjs/models/Columns.d.ts.map +1 -1
  63. package/dist/cjs/models/Filter.d.ts +15 -4
  64. package/dist/cjs/models/Filter.d.ts.map +1 -1
  65. package/dist/cjs/models/Filter.js +9 -1
  66. package/dist/cjs/models/Report.d.ts +10 -23
  67. package/dist/cjs/models/Report.d.ts.map +1 -1
  68. package/dist/cjs/utils/astFilterProcessing.d.ts.map +1 -1
  69. package/dist/cjs/utils/astFilterProcessing.js +37 -2
  70. package/dist/cjs/utils/columnProcessing.d.ts +2 -0
  71. package/dist/cjs/utils/columnProcessing.d.ts.map +1 -1
  72. package/dist/cjs/utils/columnProcessing.js +54 -1
  73. package/dist/cjs/utils/dashboard.d.ts +1 -1
  74. package/dist/cjs/utils/dashboard.d.ts.map +1 -1
  75. package/dist/cjs/utils/dashboard.js +3 -56
  76. package/dist/cjs/utils/dataProcessing.d.ts +4 -2
  77. package/dist/cjs/utils/dataProcessing.d.ts.map +1 -1
  78. package/dist/cjs/utils/dataProcessing.js +18 -1
  79. package/dist/cjs/utils/dates.d.ts +2 -1
  80. package/dist/cjs/utils/dates.d.ts.map +1 -1
  81. package/dist/cjs/utils/dates.js +23 -1
  82. package/dist/cjs/utils/filterProcessing.d.ts +7 -1
  83. package/dist/cjs/utils/filterProcessing.d.ts.map +1 -1
  84. package/dist/cjs/utils/filterProcessing.js +100 -13
  85. package/dist/cjs/utils/pivotConstructor.d.ts +2 -1
  86. package/dist/cjs/utils/pivotConstructor.d.ts.map +1 -1
  87. package/dist/cjs/utils/pivotConstructor.js +7 -1
  88. package/dist/cjs/utils/report.d.ts +4 -1
  89. package/dist/cjs/utils/report.d.ts.map +1 -1
  90. package/dist/cjs/utils/report.js +94 -7
  91. package/dist/cjs/utils/tableProcessing.d.ts +1 -1
  92. package/dist/esm/Chart.d.ts +6 -37
  93. package/dist/esm/Chart.d.ts.map +1 -1
  94. package/dist/esm/Chart.js +87 -329
  95. package/dist/esm/ChartBuilder.d.ts +12 -49
  96. package/dist/esm/ChartBuilder.d.ts.map +1 -1
  97. package/dist/esm/ChartBuilder.js +68 -33
  98. package/dist/esm/ChartEditor.d.ts +1 -1
  99. package/dist/esm/ChartEditor.d.ts.map +1 -1
  100. package/dist/esm/ChartEditor.js +11 -7
  101. package/dist/esm/Context.d.ts +4 -1
  102. package/dist/esm/Context.d.ts.map +1 -1
  103. package/dist/esm/Context.js +9 -3
  104. package/dist/esm/Dashboard.d.ts +61 -114
  105. package/dist/esm/Dashboard.d.ts.map +1 -1
  106. package/dist/esm/Dashboard.js +263 -32
  107. package/dist/esm/DateRangePicker/DateRangePicker.d.ts.map +1 -1
  108. package/dist/esm/DateRangePicker/DateRangePicker.js +0 -26
  109. package/dist/esm/ReportBuilder.d.ts +1 -1
  110. package/dist/esm/ReportBuilder.d.ts.map +1 -1
  111. package/dist/esm/ReportBuilder.js +64 -99
  112. package/dist/esm/SQLEditor.d.ts +2 -2
  113. package/dist/esm/SQLEditor.d.ts.map +1 -1
  114. package/dist/esm/SQLEditor.js +11 -6
  115. package/dist/esm/Table.d.ts.map +1 -1
  116. package/dist/esm/Table.js +42 -44
  117. package/dist/esm/components/Chart/BarChart.d.ts.map +1 -1
  118. package/dist/esm/components/Chart/BarChart.js +13 -2
  119. package/dist/esm/components/Chart/LineChart.d.ts +2 -1
  120. package/dist/esm/components/Chart/LineChart.d.ts.map +1 -1
  121. package/dist/esm/components/Chart/LineChart.js +26 -2
  122. package/dist/esm/components/Dashboard/DataLoader.d.ts +7 -7
  123. package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
  124. package/dist/esm/components/Dashboard/DataLoader.js +65 -29
  125. package/dist/esm/components/Dashboard/MetricComponent.d.ts.map +1 -1
  126. package/dist/esm/components/Dashboard/MetricComponent.js +11 -45
  127. package/dist/esm/components/Dashboard/TableComponent.d.ts +1 -1
  128. package/dist/esm/components/Dashboard/TableComponent.d.ts.map +1 -1
  129. package/dist/esm/components/Dashboard/TableComponent.js +1 -30
  130. package/dist/esm/components/QuillMultiSelectWithCombo.d.ts.map +1 -1
  131. package/dist/esm/components/QuillMultiSelectWithCombo.js +16 -1
  132. package/dist/esm/components/QuillSelectWithCombo.d.ts.map +1 -1
  133. package/dist/esm/components/QuillSelectWithCombo.js +5 -2
  134. package/dist/esm/components/ReportBuilder/FilterModal.d.ts +10 -2
  135. package/dist/esm/components/ReportBuilder/FilterModal.d.ts.map +1 -1
  136. package/dist/esm/components/ReportBuilder/FilterModal.js +94 -70
  137. package/dist/esm/components/ReportBuilder/convert.d.ts +7 -2
  138. package/dist/esm/components/ReportBuilder/convert.d.ts.map +1 -1
  139. package/dist/esm/components/ReportBuilder/convert.js +51 -0
  140. package/dist/esm/components/ReportBuilder/ui.d.ts +6 -6
  141. package/dist/esm/components/ReportBuilder/ui.d.ts.map +1 -1
  142. package/dist/esm/components/ReportBuilder/ui.js +6 -22
  143. package/dist/esm/components/UiComponents.d.ts +26 -1
  144. package/dist/esm/components/UiComponents.d.ts.map +1 -1
  145. package/dist/esm/components/UiComponents.js +95 -3
  146. package/dist/esm/hooks/useQuill.d.ts.map +1 -1
  147. package/dist/esm/hooks/useQuill.js +19 -3
  148. package/dist/esm/index.d.ts +2 -1
  149. package/dist/esm/index.d.ts.map +1 -1
  150. package/dist/esm/internals/ReportBuilder/PivotModal.d.ts +1 -0
  151. package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
  152. package/dist/esm/models/Columns.d.ts +2 -1
  153. package/dist/esm/models/Columns.d.ts.map +1 -1
  154. package/dist/esm/models/Filter.d.ts +15 -4
  155. package/dist/esm/models/Filter.d.ts.map +1 -1
  156. package/dist/esm/models/Filter.js +8 -0
  157. package/dist/esm/models/Report.d.ts +10 -23
  158. package/dist/esm/models/Report.d.ts.map +1 -1
  159. package/dist/esm/utils/astFilterProcessing.d.ts.map +1 -1
  160. package/dist/esm/utils/astFilterProcessing.js +38 -3
  161. package/dist/esm/utils/columnProcessing.d.ts +2 -0
  162. package/dist/esm/utils/columnProcessing.d.ts.map +1 -1
  163. package/dist/esm/utils/columnProcessing.js +52 -0
  164. package/dist/esm/utils/dashboard.d.ts +1 -1
  165. package/dist/esm/utils/dashboard.d.ts.map +1 -1
  166. package/dist/esm/utils/dashboard.js +3 -56
  167. package/dist/esm/utils/dataProcessing.d.ts +4 -2
  168. package/dist/esm/utils/dataProcessing.d.ts.map +1 -1
  169. package/dist/esm/utils/dataProcessing.js +16 -0
  170. package/dist/esm/utils/dates.d.ts +2 -1
  171. package/dist/esm/utils/dates.d.ts.map +1 -1
  172. package/dist/esm/utils/dates.js +21 -0
  173. package/dist/esm/utils/filterProcessing.d.ts +7 -1
  174. package/dist/esm/utils/filterProcessing.d.ts.map +1 -1
  175. package/dist/esm/utils/filterProcessing.js +97 -12
  176. package/dist/esm/utils/pivotConstructor.d.ts +2 -1
  177. package/dist/esm/utils/pivotConstructor.d.ts.map +1 -1
  178. package/dist/esm/utils/pivotConstructor.js +7 -1
  179. package/dist/esm/utils/report.d.ts +4 -1
  180. package/dist/esm/utils/report.d.ts.map +1 -1
  181. package/dist/esm/utils/report.js +92 -6
  182. package/dist/esm/utils/tableProcessing.d.ts +1 -1
  183. package/package.json +1 -1
  184. package/dist/esm/components/ReportBuilder/convert.uspec.d.ts +0 -2
  185. package/dist/esm/components/ReportBuilder/convert.uspec.d.ts.map +0 -1
  186. package/dist/esm/components/ReportBuilder/convert.uspec.js +0 -1152
  187. package/dist/esm/utils/astFilterProcessing.uspec.d.ts +0 -2
  188. package/dist/esm/utils/astFilterProcessing.uspec.d.ts.map +0 -1
  189. package/dist/esm/utils/astFilterProcessing.uspec.js +0 -2729
  190. package/dist/esm/utils/dataProcessing.uspec.d.ts +0 -2
  191. package/dist/esm/utils/dataProcessing.uspec.d.ts.map +0 -1
  192. package/dist/esm/utils/dataProcessing.uspec.js +0 -204
  193. package/dist/esm/utils/queryConstructor.uspec.d.ts +0 -2
  194. package/dist/esm/utils/queryConstructor.uspec.d.ts.map +0 -1
  195. package/dist/esm/utils/queryConstructor.uspec.js +0 -223
  196. package/dist/esm/utils/report.ispec.d.ts +0 -2
  197. package/dist/esm/utils/report.ispec.d.ts.map +0 -1
  198. package/dist/esm/utils/report.ispec.js +0 -46
  199. package/dist/esm/utils/tableProcessing.ispec.d.ts +0 -2
  200. package/dist/esm/utils/tableProcessing.ispec.d.ts.map +0 -1
  201. package/dist/esm/utils/tableProcessing.ispec.js +0 -61
@@ -1,1152 +0,0 @@
1
- import { convertASTToPivotData, convertGroupBy } from './convert';
2
- import { convertColumnInfoToColumnInternal } from '../../utils/columnProcessing';
3
- function generateCaseWhenColumnAst(columnField, valueField, caseValue) {
4
- const defaultCaseWhen = {
5
- type: 'expr',
6
- expr: {
7
- type: 'aggr_func',
8
- name: 'SUM',
9
- args: {
10
- expr: {
11
- type: 'case',
12
- expr: null,
13
- args: [
14
- {
15
- type: 'when',
16
- cond: {
17
- type: 'binary_expr',
18
- operator: '=',
19
- left: {
20
- type: 'column_ref',
21
- table: null,
22
- column: 'category',
23
- },
24
- right: {
25
- type: 'single_quote_string',
26
- value: 'Food',
27
- },
28
- },
29
- result: {
30
- type: 'column_ref',
31
- table: null,
32
- column: 'amount',
33
- },
34
- },
35
- {
36
- type: 'else',
37
- result: {
38
- type: 'number',
39
- value: 0,
40
- },
41
- },
42
- ],
43
- },
44
- },
45
- over: null,
46
- },
47
- as: 'total_food_spend',
48
- };
49
- defaultCaseWhen.expr.args.expr.args[0].cond.left.column = columnField;
50
- defaultCaseWhen.expr.args.expr.args[0].result.column = valueField;
51
- defaultCaseWhen.expr.args.expr.args[0].cond.right.value = caseValue;
52
- return defaultCaseWhen;
53
- }
54
- describe('convert', () => {
55
- const emptySelect = {
56
- with: null,
57
- type: 'select',
58
- options: null,
59
- distinct: null,
60
- columns: [],
61
- from: [
62
- {
63
- db: null,
64
- table: 'transactions',
65
- as: null,
66
- },
67
- ],
68
- where: null,
69
- groupby: null,
70
- having: null,
71
- orderby: null,
72
- limit: null,
73
- };
74
- const schema = [
75
- {
76
- viewQuery: 'SELECT * FROM transactions',
77
- name: 'transactions',
78
- isVisible: true,
79
- _id: '1',
80
- clientId: 'dummy',
81
- displayName: 'transactions',
82
- columns: [
83
- {
84
- name: 'created_at',
85
- fieldType: 'date',
86
- displayName: 'created_at',
87
- isVisible: true,
88
- _id: '1',
89
- },
90
- {
91
- name: 'amount',
92
- fieldType: 'int4',
93
- displayName: 'amount',
94
- isVisible: true,
95
- _id: '2',
96
- },
97
- {
98
- name: 'merchant',
99
- fieldType: 'text',
100
- displayName: 'merchant',
101
- isVisible: true,
102
- _id: '3',
103
- },
104
- {
105
- name: 'user_name',
106
- fieldType: 'text',
107
- displayName: 'user_name',
108
- isVisible: true,
109
- _id: '4',
110
- },
111
- ],
112
- },
113
- ];
114
- describe('convertGroupBy', () => {
115
- const defaultSelectAST = {
116
- with: null,
117
- type: 'select',
118
- options: null,
119
- distinct: null,
120
- columns: [
121
- {
122
- type: 'expr',
123
- expr: {
124
- type: 'column_ref',
125
- table: null,
126
- column: 'created_at',
127
- },
128
- as: null,
129
- },
130
- {
131
- type: 'expr',
132
- expr: {
133
- type: 'column_ref',
134
- table: null,
135
- column: 'amount',
136
- },
137
- as: null,
138
- },
139
- {
140
- type: 'expr',
141
- expr: {
142
- type: 'column_ref',
143
- table: null,
144
- column: 'merchant',
145
- },
146
- as: null,
147
- },
148
- ],
149
- from: [
150
- {
151
- db: null,
152
- table: 'transactions',
153
- as: null,
154
- },
155
- ],
156
- where: null,
157
- groupby: null,
158
- having: null,
159
- orderby: null,
160
- limit: null,
161
- };
162
- const sumAggAST = {
163
- type: 'expr',
164
- expr: {
165
- type: 'aggr_func',
166
- name: 'SUM',
167
- args: {
168
- expr: {
169
- type: 'column_ref',
170
- table: null,
171
- column: 'amount',
172
- },
173
- },
174
- over: null,
175
- },
176
- as: 'amount',
177
- };
178
- it('should process the aggregation, value and row fields from the ast', () => {
179
- const pivotAST = { ...defaultSelectAST };
180
- pivotAST.columns = [...pivotAST.columns, sumAggAST];
181
- pivotAST.groupby = [
182
- {
183
- type: 'column_ref',
184
- table: null,
185
- column: {
186
- expr: {
187
- type: 'default',
188
- value: 'created_at',
189
- },
190
- },
191
- },
192
- ];
193
- const result = convertGroupBy(pivotAST, null, schema);
194
- expect(result?.pivot?.rowField).toEqual('created_at');
195
- expect(result?.pivot?.valueField).toEqual('amount');
196
- // @ts-ignore
197
- expect(result.ast.groupby).toEqual(null);
198
- // @ts-ignore
199
- expect(result.ast.columns.length).toEqual(3);
200
- });
201
- it('should process an ast with 2 group by columns for the 2d pivot information from the ast and modify the ast to only have basic column selections', () => {
202
- const pivotAST = { ...defaultSelectAST };
203
- pivotAST.columns = [...pivotAST.columns, sumAggAST];
204
- pivotAST.groupby = [
205
- {
206
- type: 'double_quote_string',
207
- value: 'merchant',
208
- },
209
- {
210
- type: 'double_quote_string',
211
- value: 'created_at',
212
- },
213
- ];
214
- const result = convertGroupBy(pivotAST, null, schema);
215
- expect(result?.pivot?.rowField).toEqual('created_at');
216
- expect(result?.pivot?.columnField).toEqual('merchant');
217
- expect(result?.pivot?.valueField).toEqual('amount');
218
- // @ts-ignore
219
- expect(result.ast.groupby).toEqual(null);
220
- // @ts-ignore
221
- expect(result.ast.columns.length).toEqual(3);
222
- });
223
- it('should process an ast with case when columns for the 2d pivot information from the ast and modify the ast to only have basic column selections', () => {
224
- const pivotAST = { ...defaultSelectAST };
225
- pivotAST.columns = [
226
- ...pivotAST.columns,
227
- generateCaseWhenColumnAst('merchant', 'amount', 'Food'),
228
- generateCaseWhenColumnAst('merchant', 'amount', 'Clothing'),
229
- ];
230
- pivotAST.groupby = [
231
- {
232
- type: 'double_quote_string',
233
- value: 'created_at',
234
- },
235
- ];
236
- const result = convertGroupBy(pivotAST, null, schema);
237
- expect(result?.pivot?.rowField).toEqual('created_at');
238
- expect(result?.pivot?.columnField).toEqual('merchant');
239
- expect(result?.pivot?.valueField).toEqual('amount');
240
- // @ts-ignore
241
- expect(result.ast.groupby).toEqual(null);
242
- // @ts-ignore
243
- expect(result.ast.columns.length).toEqual(3);
244
- });
245
- it('should maintain columns that are in the schema but convert them to a basic ast column select format', () => {
246
- const dateTruncAst = { ...defaultSelectAST };
247
- const schemaInfo = [...schema];
248
- // @ts-ignore
249
- schemaInfo[0].columns.push({
250
- name: 'updated_at',
251
- fieldType: 'date',
252
- displayName: 'updated_at',
253
- isVisible: true,
254
- _id: '3',
255
- });
256
- dateTruncAst.columns = [
257
- ...defaultSelectAST.columns,
258
- {
259
- type: 'expr',
260
- expr: {
261
- type: 'function',
262
- name: 'DATE_TRUNC',
263
- args: {
264
- type: 'expr_list',
265
- value: [
266
- {
267
- type: 'single_quote_string',
268
- value: 'month',
269
- },
270
- {
271
- type: 'column_ref',
272
- table: null,
273
- column: 'updated_at',
274
- },
275
- ],
276
- },
277
- },
278
- as: 'month',
279
- },
280
- ];
281
- const result = convertGroupBy(dateTruncAst, null, schemaInfo);
282
- // @ts-ignore
283
- expect(result.ast.columns.length).toEqual(4);
284
- });
285
- it('should parse out extract columns from the ast column list and replace them with the basic column select', () => {
286
- const extractAst = { ...defaultSelectAST };
287
- const schemaInfo = [...schema];
288
- // @ts-ignore
289
- schemaInfo[0].columns.push({
290
- name: 'updated_at',
291
- fieldType: 'date',
292
- displayName: 'updated_at',
293
- isVisible: true,
294
- _id: '3',
295
- });
296
- extractAst.columns = [
297
- ...defaultSelectAST.columns,
298
- {
299
- expr: {
300
- type: 'extract',
301
- args: {
302
- field: 'month',
303
- source: {
304
- type: 'column_ref',
305
- table: null,
306
- column: 'updated_at',
307
- },
308
- },
309
- },
310
- as: 'month',
311
- },
312
- ];
313
- extractAst.groupby = [
314
- {
315
- type: 'column_ref',
316
- table: null,
317
- column: 'user_name',
318
- },
319
- {
320
- type: 'column_ref',
321
- table: null,
322
- column: 'updated_at',
323
- },
324
- ];
325
- const result = convertGroupBy(extractAst, null, schemaInfo);
326
- // @ts-ignore
327
- expect(result.ast.columns.length).toEqual(5);
328
- });
329
- it('should take field type into account and apply a numeric value field if it is present', () => {
330
- const extractAst = emptySelect;
331
- extractAst.columns = [
332
- {
333
- type: 'expr',
334
- expr: {
335
- type: 'double_quote_string',
336
- column: 'created_at',
337
- },
338
- as: 'created_at',
339
- },
340
- {
341
- type: 'expr',
342
- expr: {
343
- type: 'double_quote_string',
344
- column: 'amount',
345
- },
346
- as: 'amount',
347
- },
348
- {
349
- type: 'expr',
350
- expr: {
351
- type: 'double_quote_string',
352
- column: 'user_name',
353
- },
354
- as: 'user_name',
355
- },
356
- ];
357
- extractAst.groupby = [
358
- {
359
- type: 'column_ref',
360
- table: null,
361
- column: 'created_at',
362
- },
363
- {
364
- type: 'column_ref',
365
- table: null,
366
- column: 'amount',
367
- },
368
- {
369
- type: 'column_ref',
370
- table: null,
371
- column: 'user_name',
372
- },
373
- ];
374
- const result = convertGroupBy(extractAst, null, schema);
375
- // @ts-ignore
376
- expect(result.pivot.valueField).toEqual('amount');
377
- // @ts-ignore
378
- expect(result.pivot.rowField).toEqual('created_at');
379
- });
380
- it('should set aggregation type to count if there is no numeric field', () => {
381
- const extractAst = emptySelect;
382
- extractAst.columns = [
383
- {
384
- type: 'expr',
385
- expr: {
386
- type: 'double_quote_string',
387
- column: 'created_at',
388
- },
389
- as: 'created_at',
390
- },
391
- {
392
- type: 'expr',
393
- expr: {
394
- type: 'double_quote_string',
395
- column: 'user_name',
396
- },
397
- as: 'user_name',
398
- },
399
- ];
400
- extractAst.groupby = [
401
- {
402
- type: 'column_ref',
403
- table: null,
404
- column: 'created_at',
405
- },
406
- {
407
- type: 'column_ref',
408
- table: null,
409
- column: 'amount',
410
- },
411
- {
412
- type: 'column_ref',
413
- table: null,
414
- column: 'user_name',
415
- },
416
- ];
417
- const result = convertGroupBy(extractAst, null, schema);
418
- // @ts-ignore
419
- expect(result.pivot.aggregationType).toEqual('count');
420
- // @ts-ignore
421
- expect(result.pivot.rowField).toEqual('created_at');
422
- });
423
- it('should extract out non numeric value fields and replace it with null and set the aggregation type to count', () => {
424
- const extractAst = {
425
- with: null,
426
- type: 'select',
427
- options: null,
428
- distinct: null,
429
- columns: [
430
- {
431
- type: 'expr',
432
- expr: {
433
- type: 'column_ref',
434
- table: null,
435
- column: 'user_name',
436
- },
437
- as: null,
438
- },
439
- {
440
- type: 'expr',
441
- expr: {
442
- type: 'aggr_func',
443
- name: 'SUM',
444
- args: {
445
- expr: {
446
- type: 'case',
447
- expr: null,
448
- args: [
449
- {
450
- type: 'when',
451
- cond: {
452
- type: 'binary_expr',
453
- operator: '=',
454
- left: {
455
- type: 'column_ref',
456
- table: null,
457
- column: 'category',
458
- },
459
- right: {
460
- type: 'single_quote_string',
461
- value: 'Food',
462
- },
463
- },
464
- result: {
465
- type: 'number',
466
- value: 1,
467
- },
468
- },
469
- {
470
- type: 'else',
471
- result: {
472
- type: 'number',
473
- value: 0,
474
- },
475
- },
476
- ],
477
- },
478
- },
479
- over: null,
480
- },
481
- as: 'total_food_spend',
482
- },
483
- {
484
- type: 'expr',
485
- expr: {
486
- type: 'aggr_func',
487
- name: 'SUM',
488
- args: {
489
- expr: {
490
- type: 'case',
491
- expr: null,
492
- args: [
493
- {
494
- type: 'when',
495
- cond: {
496
- type: 'binary_expr',
497
- operator: '=',
498
- left: {
499
- type: 'column_ref',
500
- table: null,
501
- column: 'category',
502
- },
503
- right: {
504
- type: 'single_quote_string',
505
- value: 'Fuel',
506
- },
507
- },
508
- result: {
509
- type: 'number',
510
- value: 1,
511
- },
512
- },
513
- {
514
- type: 'else',
515
- result: {
516
- type: 'number',
517
- value: 0,
518
- },
519
- },
520
- ],
521
- },
522
- },
523
- over: null,
524
- },
525
- as: 'total_fuel_spend',
526
- },
527
- {
528
- type: 'expr',
529
- expr: {
530
- type: 'function',
531
- name: 'DATE_TRUNC',
532
- args: {
533
- type: 'expr_list',
534
- value: [
535
- {
536
- type: 'single_quote_string',
537
- value: 'month',
538
- },
539
- {
540
- type: 'column_ref',
541
- table: null,
542
- column: 'created_at',
543
- },
544
- ],
545
- },
546
- },
547
- as: 'month',
548
- },
549
- ],
550
- from: [
551
- {
552
- db: null,
553
- table: 'transactions',
554
- as: null,
555
- },
556
- ],
557
- where: null,
558
- groupby: [
559
- {
560
- type: 'column_ref',
561
- table: null,
562
- column: 'user_name',
563
- },
564
- {
565
- type: 'function',
566
- name: 'DATE_TRUNC',
567
- args: {
568
- type: 'expr_list',
569
- value: [
570
- {
571
- type: 'single_quote_string',
572
- value: 'month',
573
- },
574
- {
575
- type: 'column_ref',
576
- table: null,
577
- column: 'created_at',
578
- },
579
- ],
580
- },
581
- },
582
- ],
583
- having: null,
584
- orderby: [
585
- {
586
- expr: {
587
- type: 'column_ref',
588
- table: null,
589
- column: 'user_name',
590
- },
591
- type: 'ASC',
592
- },
593
- {
594
- expr: {
595
- type: 'function',
596
- name: 'DATE_TRUNC',
597
- args: {
598
- type: 'expr_list',
599
- value: [
600
- {
601
- type: 'single_quote_string',
602
- value: 'month',
603
- },
604
- {
605
- type: 'column_ref',
606
- table: null,
607
- column: 'created_at',
608
- },
609
- ],
610
- },
611
- },
612
- type: 'ASC',
613
- },
614
- ],
615
- limit: null,
616
- };
617
- const result = convertGroupBy(extractAst, null, schema);
618
- // @ts-ignore
619
- expect(result.pivot.aggregationType).toEqual('count');
620
- // @ts-ignore
621
- expect(result.pivot.rowField).toEqual('created_at');
622
- });
623
- it('should be able to handle this case', () => {
624
- const newAST = {
625
- with: null,
626
- type: 'select',
627
- options: null,
628
- distinct: {
629
- type: null,
630
- },
631
- columns: [
632
- {
633
- type: 'expr',
634
- expr: {
635
- type: 'function',
636
- name: 'DATE_TRUNC',
637
- args: {
638
- type: 'expr_list',
639
- value: [
640
- {
641
- type: 'single_quote_string',
642
- value: 'week',
643
- },
644
- {
645
- type: 'double_quote_string',
646
- value: 'created_at',
647
- },
648
- ],
649
- },
650
- },
651
- as: 'week_start',
652
- },
653
- {
654
- type: 'expr',
655
- expr: {
656
- type: 'aggr_func',
657
- name: 'SUM',
658
- args: {
659
- expr: {
660
- type: 'double_quote_string',
661
- value: 'amount',
662
- },
663
- },
664
- over: null,
665
- },
666
- as: 'total_amount',
667
- },
668
- {
669
- type: 'expr',
670
- expr: {
671
- type: 'aggr_func',
672
- name: 'COUNT',
673
- args: {
674
- expr: {
675
- type: 'star',
676
- value: '*',
677
- },
678
- },
679
- over: null,
680
- },
681
- as: 'transaction_count',
682
- },
683
- ],
684
- from: [
685
- {
686
- db: null,
687
- table: 'transactions',
688
- as: null,
689
- },
690
- ],
691
- where: null,
692
- groupby: [
693
- {
694
- type: 'function',
695
- name: 'DATE_TRUNC',
696
- args: {
697
- type: 'expr_list',
698
- value: [
699
- {
700
- type: 'single_quote_string',
701
- value: 'week',
702
- },
703
- {
704
- type: 'double_quote_string',
705
- value: 'created_at',
706
- },
707
- ],
708
- },
709
- },
710
- ],
711
- having: null,
712
- orderby: null,
713
- limit: null,
714
- window: null,
715
- };
716
- // @ts-ignore
717
- const result = convertGroupBy(newAST, null, schema);
718
- // @ts-ignore
719
- expect(result.pivot.aggregationType).toEqual('sum');
720
- // @ts-ignore
721
- expect(result.pivot.rowField).toEqual('created_at');
722
- });
723
- it('should extract any date_trunc, timestamp_trunc and date_part to row field', () => {
724
- const extractAst = {
725
- with: null,
726
- type: 'select',
727
- options: null,
728
- distinct: null,
729
- columns: [
730
- {
731
- type: 'expr',
732
- expr: {
733
- type: 'function',
734
- name: {
735
- name: [
736
- {
737
- type: 'default',
738
- value: 'date_trunc',
739
- },
740
- ],
741
- },
742
- args: {
743
- type: 'expr_list',
744
- value: [
745
- {
746
- type: 'single_quote_string',
747
- value: 'year',
748
- },
749
- {
750
- type: 'column_ref',
751
- table: null,
752
- column: {
753
- expr: {
754
- type: 'double_quote_string',
755
- value: 'created_at',
756
- },
757
- },
758
- },
759
- ],
760
- },
761
- },
762
- as: 'year',
763
- },
764
- {
765
- type: 'expr',
766
- expr: {
767
- type: 'column_ref',
768
- table: null,
769
- column: {
770
- expr: {
771
- type: 'double_quote_string',
772
- value: 'id',
773
- },
774
- },
775
- },
776
- as: null,
777
- },
778
- {
779
- type: 'expr',
780
- expr: {
781
- type: 'column_ref',
782
- table: null,
783
- column: {
784
- expr: {
785
- type: 'double_quote_string',
786
- value: 'amount',
787
- },
788
- },
789
- },
790
- as: null,
791
- },
792
- {
793
- type: 'expr',
794
- expr: {
795
- type: 'column_ref',
796
- table: null,
797
- column: {
798
- expr: {
799
- type: 'double_quote_string',
800
- value: 'merchant',
801
- },
802
- },
803
- },
804
- as: null,
805
- },
806
- {
807
- type: 'expr',
808
- expr: {
809
- type: 'column_ref',
810
- table: null,
811
- column: {
812
- expr: {
813
- type: 'double_quote_string',
814
- value: 'user_name',
815
- },
816
- },
817
- },
818
- as: null,
819
- },
820
- {
821
- type: 'expr',
822
- expr: {
823
- type: 'column_ref',
824
- table: null,
825
- column: {
826
- expr: {
827
- type: 'double_quote_string',
828
- value: 'category',
829
- },
830
- },
831
- },
832
- as: null,
833
- },
834
- ],
835
- from: [
836
- {
837
- db: null,
838
- table: 'transactions',
839
- as: null,
840
- },
841
- ],
842
- where: null,
843
- groupby: null,
844
- having: null,
845
- orderby: null,
846
- limit: {
847
- seperator: '',
848
- value: [],
849
- },
850
- };
851
- const result = convertGroupBy(extractAst, null, schema);
852
- // @ts-ignore
853
- expect(result.pivot.aggregationType).toEqual('sum');
854
- // @ts-ignore
855
- expect(result.pivot.valueField).toEqual('amount');
856
- // @ts-ignore
857
- expect(result.pivot.rowField).toEqual('created_at');
858
- });
859
- });
860
- describe('convertASTToPivotData', () => {
861
- it('should convert an aggregate function to a value field only pivot', () => {
862
- const extractAst = emptySelect;
863
- extractAst.columns = [
864
- {
865
- type: 'expr',
866
- expr: {
867
- type: 'aggr_func',
868
- name: 'SUM',
869
- args: {
870
- expr: {
871
- type: 'column_ref',
872
- table: null,
873
- column: 'amount',
874
- },
875
- },
876
- over: null,
877
- },
878
- as: null,
879
- },
880
- ];
881
- // @ts-ignore
882
- const columnInteralArray = schema[0].columns.map((column) => {
883
- return convertColumnInfoToColumnInternal(column);
884
- });
885
- const result = convertASTToPivotData(extractAst, columnInteralArray);
886
- expect(result).toBeDefined();
887
- expect(result?.valueField).toEqual('amount');
888
- });
889
- it('should convert a CASE WHEN function to the right pivot', () => {
890
- const extractAst = emptySelect;
891
- extractAst.columns = [
892
- {
893
- type: 'expr',
894
- expr: {
895
- type: 'double_quote_string',
896
- column: 'user_name',
897
- },
898
- as: null,
899
- },
900
- generateCaseWhenColumnAst('merchant', 'amount', 'Food'),
901
- ];
902
- extractAst.groupby = [
903
- {
904
- type: 'column_ref',
905
- table: null,
906
- column: 'user_name',
907
- },
908
- ];
909
- // @ts-ignore
910
- const columnInteralArray = schema[0].columns.map((column) => {
911
- return convertColumnInfoToColumnInternal(column);
912
- });
913
- const result = convertASTToPivotData(extractAst, columnInteralArray);
914
- expect(result).toBeDefined();
915
- expect(result?.valueField).toEqual('amount');
916
- expect(result?.rowField).toEqual('user_name');
917
- expect(result?.columnField).toEqual('merchant');
918
- });
919
- it('should use the first two group by fields as the pivot row field and column field', () => {
920
- const extractAst = emptySelect;
921
- extractAst.columns = [
922
- {
923
- type: 'expr',
924
- expr: {
925
- type: 'aggr_func',
926
- name: 'SUM',
927
- args: {
928
- expr: {
929
- type: 'column_ref',
930
- table: null,
931
- column: 'amount',
932
- },
933
- },
934
- over: null,
935
- },
936
- as: null,
937
- },
938
- {
939
- type: 'expr',
940
- expr: {
941
- type: 'double_quote_string',
942
- column: 'user_name',
943
- },
944
- as: null,
945
- },
946
- {
947
- type: 'expr',
948
- expr: {
949
- type: 'double_quote_string',
950
- column: 'merchant',
951
- },
952
- as: null,
953
- },
954
- ];
955
- extractAst.groupby = [
956
- {
957
- type: 'column_ref',
958
- table: null,
959
- column: 'user_name',
960
- },
961
- {
962
- type: 'column_ref',
963
- table: null,
964
- column: 'merchant',
965
- },
966
- ];
967
- // @ts-ignore
968
- const columnInteralArray = schema[0].columns.map((column) => {
969
- return convertColumnInfoToColumnInternal(column);
970
- });
971
- const result = convertASTToPivotData(extractAst, columnInteralArray);
972
- expect(result).toBeDefined();
973
- expect(result?.valueField).toEqual('amount');
974
- expect(result?.rowField).toEqual('user_name');
975
- expect(result?.columnField).toEqual('merchant');
976
- });
977
- it('should always use date_trunc columns as the row field', () => {
978
- const extractAst = emptySelect;
979
- extractAst.columns = [
980
- {
981
- type: 'expr',
982
- expr: {
983
- type: 'aggr_func',
984
- name: 'SUM',
985
- args: {
986
- expr: {
987
- type: 'column_ref',
988
- table: null,
989
- column: 'amount',
990
- },
991
- },
992
- over: null,
993
- },
994
- as: null,
995
- },
996
- {
997
- type: 'expr',
998
- expr: {
999
- type: 'double_quote_string',
1000
- column: 'user_name',
1001
- },
1002
- as: null,
1003
- },
1004
- {
1005
- type: 'expr',
1006
- expr: {
1007
- type: 'double_quote_string',
1008
- column: 'created_at',
1009
- },
1010
- as: null,
1011
- },
1012
- ];
1013
- extractAst.groupby = [
1014
- {
1015
- type: 'column_ref',
1016
- table: null,
1017
- column: 'user_name',
1018
- },
1019
- {
1020
- type: 'function',
1021
- name: 'date_trunct',
1022
- args: {
1023
- type: 'expr_list',
1024
- value: [
1025
- {
1026
- type: 'single_quote_string',
1027
- value: 'month',
1028
- },
1029
- {
1030
- type: 'column_ref',
1031
- table: null,
1032
- column: 'created_at',
1033
- },
1034
- ],
1035
- },
1036
- },
1037
- ];
1038
- // @ts-ignore
1039
- const columnInteralArray = schema[0].columns.map((column) => {
1040
- return convertColumnInfoToColumnInternal(column);
1041
- });
1042
- const result = convertASTToPivotData(extractAst, columnInteralArray);
1043
- expect(result).toBeDefined();
1044
- expect(result?.valueField).toEqual('amount');
1045
- expect(result?.rowField).toEqual('created_at');
1046
- expect(result?.columnField).toEqual('user_name');
1047
- });
1048
- it('should process aliasing properly for pivots', () => {
1049
- const extractAst = emptySelect;
1050
- extractAst.columns = [
1051
- {
1052
- type: 'expr',
1053
- expr: {
1054
- type: 'aggr_func',
1055
- name: 'SUM',
1056
- args: {
1057
- expr: {
1058
- type: 'column_ref',
1059
- table: null,
1060
- column: 'amount',
1061
- },
1062
- },
1063
- over: null,
1064
- },
1065
- as: 'total_sum',
1066
- },
1067
- {
1068
- type: 'expr',
1069
- expr: {
1070
- type: 'double_quote_string',
1071
- column: 'created_at',
1072
- },
1073
- as: 'date_info',
1074
- },
1075
- ];
1076
- extractAst.groupby = [
1077
- {
1078
- type: 'column_ref',
1079
- table: null,
1080
- column: 'date_info',
1081
- },
1082
- ];
1083
- // @ts-ignore
1084
- const columnInteralArray = schema[0].columns.map((column) => {
1085
- return convertColumnInfoToColumnInternal(column);
1086
- });
1087
- const result = convertASTToPivotData(extractAst, columnInteralArray);
1088
- expect(result).toBeDefined();
1089
- expect(result?.valueField).toEqual('amount');
1090
- expect(result?.rowField).toEqual('created_at');
1091
- expect(result?.aggregationType).toEqual('sum');
1092
- expect(result?.rowFieldType).toEqual('date');
1093
- expect(result?.sortFieldType).toEqual('date');
1094
- });
1095
- it('should not sign a numeric type to row or column field', () => {
1096
- const extractAst = emptySelect;
1097
- extractAst.columns = [
1098
- {
1099
- type: 'expr',
1100
- expr: {
1101
- type: 'double_quote_string',
1102
- column: 'created_at',
1103
- },
1104
- as: 'created_at',
1105
- },
1106
- {
1107
- type: 'expr',
1108
- expr: {
1109
- type: 'double_quote_string',
1110
- column: 'amount',
1111
- },
1112
- as: 'amount',
1113
- },
1114
- {
1115
- type: 'expr',
1116
- expr: {
1117
- type: 'double_quote_string',
1118
- column: 'user_name',
1119
- },
1120
- as: 'user_name',
1121
- },
1122
- ];
1123
- extractAst.groupby = [
1124
- {
1125
- type: 'column_ref',
1126
- table: null,
1127
- column: 'created_at',
1128
- },
1129
- {
1130
- type: 'column_ref',
1131
- table: null,
1132
- column: 'amount',
1133
- },
1134
- {
1135
- type: 'column_ref',
1136
- table: null,
1137
- column: 'user_name',
1138
- },
1139
- ];
1140
- // @ts-ignore
1141
- const columnInteralArray = schema[0].columns.map((column) => {
1142
- return convertColumnInfoToColumnInternal(column);
1143
- });
1144
- const result = convertASTToPivotData(extractAst, columnInteralArray);
1145
- expect(result).toBeDefined();
1146
- expect(result?.rowField).toEqual('created_at');
1147
- expect(result?.aggregationType).toEqual(undefined);
1148
- expect(result?.rowFieldType).toEqual('date');
1149
- expect(result?.columnField).toEqual('user_name');
1150
- });
1151
- });
1152
- });