sea-chart 0.0.30 → 0.0.31-beta
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/dist/context.js +41 -14
- package/dist/utils/chart-utils/base-utils.js +23 -23
- package/dist/utils/chart-utils/index.js +2 -10
- package/dist/utils/chart-utils/original-data-utils/index.js +4 -4
- package/dist/utils/chart-utils/sql-statistics-utils.js +101 -87
- package/dist/utils/map.js +1 -1
- package/dist/utils/sql/chart-data-sql.js +146 -193
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CellType, filter2SqlCondition, isNumericColumn, isDateColumn } from 'dtable-utils';
|
|
2
2
|
import { getSqlGroup } from '../column-utils';
|
|
3
|
-
import { CHART_TYPE, DTABLE_DB_SUMMARY_METHOD, CHART_SUMMARY_TYPE,
|
|
3
|
+
import { CHART_TYPE, DTABLE_DB_SUMMARY_METHOD, CHART_SUMMARY_TYPE, CHART_Y_GROUP_TYPE } from '../../constants';
|
|
4
4
|
import { fixGeoGranularity } from '../map';
|
|
5
5
|
|
|
6
6
|
/*
|
|
@@ -16,33 +16,36 @@ class ChartDataSQL {
|
|
|
16
16
|
userId,
|
|
17
17
|
userDepartmentIdsMap
|
|
18
18
|
} = _ref;
|
|
19
|
+
this._chart_column_name_to_sql = (column, groupBy) => {
|
|
20
|
+
return getSqlGroup(column, groupBy);
|
|
21
|
+
};
|
|
19
22
|
this._get_column_by_key = key => {
|
|
20
|
-
return this.
|
|
23
|
+
return this.column_key_map[key];
|
|
21
24
|
};
|
|
22
25
|
this._get_sql_order_by = (sortType, groupName) => {
|
|
23
26
|
if (!sortType) {
|
|
24
|
-
return "
|
|
27
|
+
return "ORDER BY ".concat(groupName);
|
|
25
28
|
}
|
|
26
29
|
return '';
|
|
27
30
|
};
|
|
28
|
-
this._update_filter_sql = (
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
31
|
-
const
|
|
32
|
-
const
|
|
31
|
+
this._update_filter_sql = (include_empty, column, method) => {
|
|
32
|
+
const column_name = (column === null || column === void 0 ? void 0 : column.name) || '';
|
|
33
|
+
if (!include_empty) {
|
|
34
|
+
const sql_column_name = method ? "".concat(method, "(`").concat(column_name, "`)") : "`".concat(column_name, "`");
|
|
35
|
+
const not_include_empty_sql = "".concat(sql_column_name, " IS NOT NULL");
|
|
33
36
|
if (this.filter_sql) {
|
|
34
|
-
this.filter_sql = "WHERE ".concat(
|
|
37
|
+
this.filter_sql = "WHERE ".concat(not_include_empty_sql, " AND ").concat(this.filter_sql);
|
|
35
38
|
} else {
|
|
36
|
-
this.filter_sql = "WHERE ".concat(
|
|
39
|
+
this.filter_sql = "WHERE ".concat(not_include_empty_sql);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
};
|
|
40
43
|
this._summary_column_2_sql = (summary_method, column) => {
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
if (summary_method === 'DISTINCT_VALUES') return "COUNT(DISTINCT ".concat(
|
|
44
|
-
if (summary_method === 'ROW_COUNT') return "COUNT(".concat(
|
|
45
|
-
return "".concat(DTABLE_DB_SUMMARY_METHOD[summary_method], "(").concat(
|
|
44
|
+
const column_name = (column === null || column === void 0 ? void 0 : column.name) || '';
|
|
45
|
+
const valid_column_name = "`".concat(column_name, "`");
|
|
46
|
+
if (summary_method === 'DISTINCT_VALUES') return "COUNT(DISTINCT ".concat(valid_column_name, ")");
|
|
47
|
+
if (summary_method === 'ROW_COUNT') return "COUNT(".concat(valid_column_name, ")");
|
|
48
|
+
return "".concat(DTABLE_DB_SUMMARY_METHOD[summary_method], "(").concat(valid_column_name, ")");
|
|
46
49
|
};
|
|
47
50
|
this._basic_statistic_2_sql = () => {
|
|
48
51
|
let x_axis_column_key, x_axis_date_granularity, x_axis_geolocation_granularity, x_axis_include_empty_cells, y_axis_summary_type, y_axis_summary_method, y_axis_summary_column_key;
|
|
@@ -63,13 +66,13 @@ class ChartDataSQL {
|
|
|
63
66
|
y_axis_summary_method = this.chart['y_axis_summary_method'] || '';
|
|
64
67
|
y_axis_summary_column_key = this.chart['y_axis_summary_column_key'] || '';
|
|
65
68
|
}
|
|
66
|
-
const groupby_column = this.
|
|
69
|
+
const groupby_column = this._get_column_by_key(x_axis_column_key);
|
|
67
70
|
if (!groupby_column) {
|
|
68
71
|
this.error = 'Group_by_column_not_found';
|
|
69
72
|
return '';
|
|
70
73
|
}
|
|
71
74
|
this._update_filter_sql(x_axis_include_empty_cells, groupby_column);
|
|
72
|
-
const groupby_column_name =
|
|
75
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
73
76
|
'date_granularity': x_axis_date_granularity,
|
|
74
77
|
'geolocation_granularity': x_axis_geolocation_granularity
|
|
75
78
|
});
|
|
@@ -80,7 +83,7 @@ class ChartDataSQL {
|
|
|
80
83
|
if (summary_type === 'COUNT') {
|
|
81
84
|
summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
|
|
82
85
|
} else {
|
|
83
|
-
summary_column = this.
|
|
86
|
+
summary_column = this._get_column_by_key(y_axis_summary_column_key);
|
|
84
87
|
if (summary_column) {
|
|
85
88
|
summary_method = y_axis_summary_method.toUpperCase();
|
|
86
89
|
summary_column_name = this._summary_column_2_sql(summary_method, summary_column);
|
|
@@ -98,30 +101,23 @@ class ChartDataSQL {
|
|
|
98
101
|
summary_method,
|
|
99
102
|
summary_column_key
|
|
100
103
|
} = this.chart;
|
|
101
|
-
const
|
|
102
|
-
const groupby_column = this.columnKeyMap[time_column_key];
|
|
104
|
+
const groupby_column = this._get_column_by_key(time_column_key);
|
|
103
105
|
if (!groupby_column) {
|
|
104
|
-
this.error = '
|
|
106
|
+
this.error = 'Group_by_column_not_found';
|
|
105
107
|
return '';
|
|
106
108
|
}
|
|
107
|
-
const columnName = groupby_column.name;
|
|
108
|
-
const isAdvanced = summary_type === CHART_SUMMARY_TYPE.ADVANCED;
|
|
109
|
-
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summary_method] : 'COUNT';
|
|
110
109
|
this._update_filter_sql(true, groupby_column);
|
|
111
|
-
|
|
112
|
-
let
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
if (!
|
|
116
|
-
this.error = '
|
|
110
|
+
const column_name = this._chart_column_name_to_sql(groupby_column, {});
|
|
111
|
+
let summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
|
|
112
|
+
if (summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
113
|
+
const summary_column = this._get_column_by_key(summary_column_key);
|
|
114
|
+
if (!summary_column) {
|
|
115
|
+
this.error = 'Summary_column_not_found';
|
|
117
116
|
return '';
|
|
118
117
|
}
|
|
119
|
-
|
|
120
|
-
sqlString = "select `".concat(columnName, "`, ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(this.filter_sql, " group by `").concat(columnName, "` limit 5000");
|
|
121
|
-
} else {
|
|
122
|
-
sqlString = "select `".concat(columnName, "`, ").concat(method, "(").concat(columnName, ") from `").concat(selectedTable.name, "` ").concat(this.filter_sql, " group by `").concat(columnName, "` limit 5000");
|
|
118
|
+
summary_column_name = this._summary_column_2_sql(summary_method.toUpperCase(), summary_column);
|
|
123
119
|
}
|
|
124
|
-
return
|
|
120
|
+
return "SELECT ".concat(column_name, ", ").concat(summary_column_name, " FROM `").concat(this.table_name, "` ").concat(this.filter_sql, " GROUP BY ").concat(column_name, " LIMIT 0, 5000");
|
|
125
121
|
};
|
|
126
122
|
this._mirror_map_statistic_2_sql = () => {
|
|
127
123
|
const {
|
|
@@ -131,62 +127,57 @@ class ChartDataSQL {
|
|
|
131
127
|
summary_column_key,
|
|
132
128
|
group_column_key
|
|
133
129
|
} = this.chart;
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (!x_groupby_column) {
|
|
138
|
-
this.error = 'X Group by column not found';
|
|
130
|
+
const groupby_column = this._get_column_by_key(column_key);
|
|
131
|
+
if (!groupby_column) {
|
|
132
|
+
this.error = 'Group_by_column_not_found';
|
|
139
133
|
return '';
|
|
140
134
|
}
|
|
141
|
-
const
|
|
142
|
-
if (!
|
|
143
|
-
this.error = '
|
|
135
|
+
const column_groupby_column = this._get_column_by_key(group_column_key);
|
|
136
|
+
if (!column_groupby_column) {
|
|
137
|
+
this.error = 'Column_group_by_column_not_found';
|
|
144
138
|
return '';
|
|
145
139
|
}
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return [];
|
|
140
|
+
this._update_filter_sql(true, groupby_column);
|
|
141
|
+
const column_name = this._chart_column_name_to_sql(groupby_column, {});
|
|
142
|
+
const column_groupby_column_name = this._chart_column_name_to_sql(column_groupby_column, {});
|
|
143
|
+
let summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
|
|
144
|
+
if (summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
145
|
+
const summary_column = this._get_column_by_key(summary_column_key);
|
|
146
|
+
if (!summary_column) {
|
|
147
|
+
this.error = 'Summary_column_not_found';
|
|
148
|
+
return '';
|
|
156
149
|
}
|
|
157
|
-
|
|
158
|
-
sqlString = "select `".concat(columnName, "`, `").concat(groupColumnName, "`, ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(this.filter_sql, " group by `").concat(columnName, "`, `").concat(groupColumnName, "` limit 5000");
|
|
159
|
-
} else {
|
|
160
|
-
sqlString = "select `".concat(columnName, "`, `").concat(groupColumnName, "`, ").concat(method, "(`").concat(columnName, "`) from `").concat(selectedTable.name, "` ").concat(this.filter_sql, " group by `").concat(columnName, "`, `").concat(groupColumnName, "` limit 5000");
|
|
150
|
+
summary_column_name = this._summary_column_2_sql(summary_method.toUpperCase(), summary_column);
|
|
161
151
|
}
|
|
162
|
-
return
|
|
152
|
+
return "SELECT ".concat(column_name, ", ").concat(column_groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(column_name, ", ").concat(column_groupby_column_name, " LIMIT 0, 5000");
|
|
163
153
|
};
|
|
164
154
|
this._trend_map_statistic_2_sql = () => {
|
|
165
155
|
const {
|
|
166
156
|
date_column_key,
|
|
167
157
|
summary_type,
|
|
168
158
|
summary_method,
|
|
169
|
-
date_granularity
|
|
159
|
+
date_granularity,
|
|
160
|
+
summary_column_key
|
|
170
161
|
} = this.chart;
|
|
171
|
-
const
|
|
172
|
-
const groupby_column = this.columnKeyMap[date_column_key];
|
|
162
|
+
const groupby_column = this._get_column_by_key(date_column_key);
|
|
173
163
|
if (!groupby_column) {
|
|
174
|
-
this.error = '
|
|
164
|
+
this.error = 'Group_by_column_not_found';
|
|
175
165
|
return '';
|
|
176
166
|
}
|
|
177
|
-
const columnName = groupby_column.name;
|
|
178
167
|
this._update_filter_sql(true, groupby_column);
|
|
179
|
-
const
|
|
168
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
180
169
|
'date_granularity': date_granularity
|
|
181
170
|
});
|
|
182
|
-
let
|
|
183
|
-
if (summary_type === CHART_SUMMARY_TYPE.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
171
|
+
let summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
|
|
172
|
+
if (summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
173
|
+
const summary_column = this._get_column_by_key(summary_column_key);
|
|
174
|
+
if (!summary_column) {
|
|
175
|
+
this.error = 'Summary_column_not_found';
|
|
176
|
+
return '';
|
|
177
|
+
}
|
|
178
|
+
summary_column_name = this._summary_column_2_sql(summary_method.toUpperCase(), summary_column);
|
|
188
179
|
}
|
|
189
|
-
return
|
|
180
|
+
return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
|
|
190
181
|
};
|
|
191
182
|
this._grouping_statistic_2_sql = () => {
|
|
192
183
|
let x_axis_column_key, x_axis_date_granularity, x_axis_geolocation_granularity, x_axis_include_empty_cells, y_axis_summary_type, y_axis_summary_method, y_axis_summary_column_key;
|
|
@@ -212,21 +203,21 @@ class ChartDataSQL {
|
|
|
212
203
|
const column_groupby_geolocation_granularity = this.chart['column_groupby_geolocation_granularity'] || '';
|
|
213
204
|
const column_groupby_multiple_numeric_column = this.chart['column_groupby_multiple_numeric_column'] || false;
|
|
214
205
|
const summary_columns = this.chart['summary_columns'] || [];
|
|
215
|
-
const groupby_column = this.
|
|
206
|
+
const groupby_column = this._get_column_by_key(x_axis_column_key);
|
|
216
207
|
if (!groupby_column) {
|
|
217
208
|
this.error = 'Group_by_column_not_found';
|
|
218
209
|
return '';
|
|
219
210
|
}
|
|
220
211
|
this._update_filter_sql(x_axis_include_empty_cells, groupby_column);
|
|
221
|
-
const groupby_column_name =
|
|
212
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
222
213
|
'date_granularity': x_axis_date_granularity,
|
|
223
214
|
'geolocation_granularity': x_axis_geolocation_granularity
|
|
224
215
|
});
|
|
225
216
|
const summary_type = y_axis_summary_type.toUpperCase();
|
|
226
217
|
if (summary_type === 'COUNT') {
|
|
227
|
-
const column_groupby_column = this.
|
|
218
|
+
const column_groupby_column = this._get_column_by_key(column_groupby_column_key);
|
|
228
219
|
if (!column_groupby_column) return this._basic_statistic_2_sql();
|
|
229
|
-
const column_groupby_column_name =
|
|
220
|
+
const column_groupby_column_name = this._chart_column_name_to_sql(column_groupby_column, {
|
|
230
221
|
'date_granularity': column_groupby_date_granularity,
|
|
231
222
|
'geolocation_granularity': column_groupby_geolocation_granularity
|
|
232
223
|
});
|
|
@@ -262,7 +253,7 @@ class ChartDataSQL {
|
|
|
262
253
|
if (!column_groupby_column) {
|
|
263
254
|
return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
|
|
264
255
|
}
|
|
265
|
-
const column_groupby_column_name =
|
|
256
|
+
const column_groupby_column_name = this._chart_column_name_to_sql(column_groupby_column, {
|
|
266
257
|
'date_granularity': column_groupby_date_granularity,
|
|
267
258
|
'geolocation_granularity': column_groupby_geolocation_granularity
|
|
268
259
|
});
|
|
@@ -273,13 +264,11 @@ class ChartDataSQL {
|
|
|
273
264
|
x_axis_column_key,
|
|
274
265
|
x_axis_date_granularity,
|
|
275
266
|
x_axis_geolocation_granularity,
|
|
276
|
-
y_axises
|
|
267
|
+
y_axises,
|
|
268
|
+
x_axis_include_empty_cells
|
|
277
269
|
} = this.chart;
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
const groupbyColumn = this._get_column_by_key(x_axis_column_key);
|
|
282
|
-
if (!groupbyColumn) {
|
|
270
|
+
const groupby_column = this._get_column_by_key(x_axis_column_key);
|
|
271
|
+
if (!groupby_column) {
|
|
283
272
|
this.error = 'Group_by_column_not_found';
|
|
284
273
|
return '';
|
|
285
274
|
}
|
|
@@ -287,66 +276,32 @@ class ChartDataSQL {
|
|
|
287
276
|
this.error = 'Y_axis_column_not_found';
|
|
288
277
|
return '';
|
|
289
278
|
}
|
|
290
|
-
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
});
|
|
297
|
-
} else if (groupbyColumn.type === CellType.GEOLOCATION) {
|
|
298
|
-
groupbyName = getSqlGroup(groupbyColumn, {
|
|
299
|
-
geolocation_granularity: x_axis_geolocation_granularity
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
const summaryType = CHART_SUMMARY_TYPE.ADVANCED;
|
|
303
|
-
const summaryColumn = null;
|
|
304
|
-
const summaryMethod = null;
|
|
305
|
-
const sqlArr = [];
|
|
279
|
+
this._update_filter_sql(x_axis_include_empty_cells, groupby_column);
|
|
280
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
281
|
+
date_granularity: x_axis_date_granularity,
|
|
282
|
+
geolocation_granularity: x_axis_geolocation_granularity
|
|
283
|
+
});
|
|
284
|
+
const SQLs = [];
|
|
306
285
|
for (let i = 0, len = y_axises.length; i < len; i++) {
|
|
307
286
|
const stack = y_axises[i];
|
|
308
287
|
const {
|
|
309
|
-
type:
|
|
288
|
+
type: y_axis_type,
|
|
310
289
|
column_groupby_numeric_columns
|
|
311
290
|
} = stack;
|
|
312
|
-
|
|
313
|
-
|
|
291
|
+
let sql = '';
|
|
292
|
+
if (y_axis_type === CHART_TYPE.BAR_STACK && column_groupby_numeric_columns && Array.isArray(column_groupby_numeric_columns) && column_groupby_numeric_columns.length !== 0) {
|
|
314
293
|
// just support summary numeric columns.
|
|
315
|
-
|
|
316
|
-
let numericColumns = [];
|
|
317
|
-
let groupColumnNames = [];
|
|
318
|
-
let groupMethods = [];
|
|
319
|
-
let originalMethods = [];
|
|
320
|
-
if (summaryColumn) {
|
|
321
|
-
const summaryColumnName = isAdvanced ? summaryColumn.name : "`".concat(groupbyColumn.name, "`");
|
|
322
|
-
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
323
|
-
const summaryColumnMethod = this._summary_column_2_sql(method, summaryColumn);
|
|
324
|
-
numericColumns.push(summaryColumn);
|
|
325
|
-
groupColumnNames.push(summaryColumnName);
|
|
326
|
-
groupMethods.push(summaryColumnMethod);
|
|
327
|
-
originalMethods.push(summaryMethod);
|
|
328
|
-
}
|
|
294
|
+
let group_methods = [];
|
|
329
295
|
column_groupby_numeric_columns.forEach(item => {
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
numericColumns.push(numericColumn);
|
|
333
|
-
groupColumnNames.push(groupColumnName);
|
|
334
|
-
groupMethods.push(this._summary_column_2_sql(DTABLE_DB_SUMMARY_METHOD[item.summary_method.toUpperCase()], numericColumn));
|
|
335
|
-
originalMethods.push(item.summary_method);
|
|
336
|
-
});
|
|
337
|
-
const sqlString = "select ".concat(groupbyName, ", ").concat(groupMethods.join(','), " from `").concat(this.table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " order by ").concat(groupbyName, " limit 5000");
|
|
338
|
-
sqlArr.push({
|
|
339
|
-
sqlString,
|
|
340
|
-
groupMethods,
|
|
341
|
-
originalMethods,
|
|
342
|
-
numericColumns,
|
|
343
|
-
groupColumnNames,
|
|
344
|
-
yAxisType
|
|
296
|
+
const numeric_column = this._get_column_by_key(item.column_key);
|
|
297
|
+
group_methods.push(this._summary_column_2_sql(DTABLE_DB_SUMMARY_METHOD[item.summary_method.toUpperCase()], numeric_column));
|
|
345
298
|
});
|
|
299
|
+
sql = "SELECT ".concat(groupby_column_name, ", ").concat(group_methods.join(','), " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 5000");
|
|
346
300
|
}
|
|
301
|
+
SQLs.push(sql);
|
|
347
302
|
}
|
|
348
|
-
if (
|
|
349
|
-
return
|
|
303
|
+
if (SQLs.length !== 0) {
|
|
304
|
+
return SQLs;
|
|
350
305
|
}
|
|
351
306
|
this.error = 'Y_axis_column_not_found';
|
|
352
307
|
return '';
|
|
@@ -357,32 +312,29 @@ class ChartDataSQL {
|
|
|
357
312
|
y_axis_summary_type,
|
|
358
313
|
y_axis_column_key,
|
|
359
314
|
x_axis_geolocation_granularity,
|
|
360
|
-
y_axis_summary_method
|
|
315
|
+
y_axis_summary_method,
|
|
316
|
+
x_axis_include_empty_cells
|
|
361
317
|
} = this.chart;
|
|
362
318
|
const groupby_column = this._get_column_by_key(x_axis_column_key);
|
|
363
319
|
if (!groupby_column) {
|
|
364
320
|
this.error = 'Group_by_column_not_found';
|
|
365
321
|
return '';
|
|
366
322
|
}
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
let groupName = getSqlGroup(groupby_column, {
|
|
323
|
+
this._update_filter_sql(x_axis_include_empty_cells, groupby_column);
|
|
324
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
370
325
|
'date_granularity': 'day',
|
|
371
326
|
'geolocation_granularity': x_axis_geolocation_granularity
|
|
372
327
|
});
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if (!selectedSummaryColumn) {
|
|
328
|
+
let summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
|
|
329
|
+
if (y_axis_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
330
|
+
const summary_column = this._get_column_by_key(y_axis_column_key);
|
|
331
|
+
if (!summary_column) {
|
|
378
332
|
this.error = 'Summary_column_not_found';
|
|
379
333
|
return '';
|
|
380
334
|
}
|
|
335
|
+
summary_column_name = this._summary_column_2_sql(y_axis_summary_method.toUpperCase(), summary_column);
|
|
381
336
|
}
|
|
382
|
-
|
|
383
|
-
const summaryColumnMethod = this._summary_column_2_sql(method, summary_column);
|
|
384
|
-
const sqlCondition = filter2SqlCondition(this.table, this.chart);
|
|
385
|
-
return "SELECT ".concat(groupName, ", ").concat(summaryColumnMethod, " FROM ").concat(this.table_name, " ").concat(sqlCondition, " GROUP BY ").concat(groupName, " ").concat(sqlOrder, " LIMIT 0, 5000");
|
|
337
|
+
return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
|
|
386
338
|
};
|
|
387
339
|
this._combination_chart_statistic_2_sql = () => {
|
|
388
340
|
const x_axis_column_key = this.chart['x_axis_column_key'] || '';
|
|
@@ -403,7 +355,7 @@ class ChartDataSQL {
|
|
|
403
355
|
return '';
|
|
404
356
|
}
|
|
405
357
|
this._update_filter_sql(x_axis_include_empty_cells, groupby_column);
|
|
406
|
-
const groupby_column_name =
|
|
358
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
407
359
|
'date_granularity': x_axis_date_granularity,
|
|
408
360
|
'geolocation_granularity': x_axis_geolocation_granularity
|
|
409
361
|
});
|
|
@@ -503,7 +455,7 @@ class ChartDataSQL {
|
|
|
503
455
|
return '';
|
|
504
456
|
}
|
|
505
457
|
this._update_filter_sql(groupby_include_empty_cells, groupby_column);
|
|
506
|
-
const groupby_column_name =
|
|
458
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
507
459
|
'date_granularity': groupby_date_granularity,
|
|
508
460
|
'geolocation_granularity': groupby_geolocation_granularity
|
|
509
461
|
});
|
|
@@ -584,11 +536,11 @@ class ChartDataSQL {
|
|
|
584
536
|
return '';
|
|
585
537
|
}
|
|
586
538
|
this._update_filter_sql(groupby_include_empty_cells, groupby_column);
|
|
587
|
-
const groupby_column_name =
|
|
539
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
588
540
|
'date_granularity': groupby_date_granularity,
|
|
589
541
|
'geolocation_granularity': groupby_geolocation_granularity
|
|
590
542
|
});
|
|
591
|
-
const column_groupby_column_name =
|
|
543
|
+
const column_groupby_column_name = this._chart_column_name_to_sql(column_groupby_column, {
|
|
592
544
|
'date_granularity': column_groupby_date_granularity,
|
|
593
545
|
'geolocation_granularity': column_groupby_geolocation_granularity
|
|
594
546
|
});
|
|
@@ -625,7 +577,7 @@ class ChartDataSQL {
|
|
|
625
577
|
return '';
|
|
626
578
|
}
|
|
627
579
|
this._update_filter_sql(groupby_include_empty_cells, groupby_column);
|
|
628
|
-
const groupby_column_name =
|
|
580
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
629
581
|
'date_granularity': groupby_date_granularity,
|
|
630
582
|
'geolocation_granularity': groupby_geolocation_granularity
|
|
631
583
|
});
|
|
@@ -701,46 +653,45 @@ class ChartDataSQL {
|
|
|
701
653
|
return "SELECT ".concat(target_summary_column_name, ", ").concat(total_summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " LIMIT 0, 5000");
|
|
702
654
|
};
|
|
703
655
|
this._completeness_chart_statistic_2_sql = () => {
|
|
704
|
-
var _this$_get_column_by_, _this$_get_column_by_2;
|
|
705
656
|
const groupby_column_key = this.chart['groupby_column_key'];
|
|
706
|
-
const
|
|
707
|
-
const
|
|
657
|
+
const target_column_key = this.chart['target_column_key'];
|
|
658
|
+
const completed_column_key = this.chart['completed_column_key'];
|
|
708
659
|
const column_groupby_column_key = this.chart['column_groupby_column_key'];
|
|
709
660
|
const date_granularity = this.chart['date_granularity'];
|
|
710
661
|
const geolocation_granularity = this.chart['geolocation_granularity'];
|
|
711
|
-
|
|
712
|
-
// get column name
|
|
713
662
|
const groupby_column = this._get_column_by_key(groupby_column_key);
|
|
714
|
-
|
|
715
|
-
this._update_filter_sql(x_axis_include_empty_cells, groupby_column);
|
|
716
|
-
const groupbyColumnName = groupby_column === null || groupby_column === void 0 ? void 0 : groupby_column.name;
|
|
717
|
-
if (!groupbyColumnName) {
|
|
663
|
+
if (!groupby_column) {
|
|
718
664
|
this.error = 'Group_by_column_not_found';
|
|
719
665
|
return '';
|
|
720
666
|
}
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
this.error = 'Completed_column_not_found';
|
|
667
|
+
const target_column = this._get_column_by_key(target_column_key);
|
|
668
|
+
if (!target_column) {
|
|
669
|
+
this.error = 'Target_column_not_found';
|
|
725
670
|
return '';
|
|
726
671
|
}
|
|
727
|
-
|
|
728
|
-
|
|
672
|
+
const completed_column = this._get_column_by_key(completed_column_key);
|
|
673
|
+
if (!completed_column) {
|
|
674
|
+
this.error = 'Completed_column_not_found';
|
|
729
675
|
return '';
|
|
730
676
|
}
|
|
677
|
+
const x_axis_include_empty_cells = this.chart['x_axis_include_empty_cells'] || false;
|
|
678
|
+
this._update_filter_sql(x_axis_include_empty_cells, groupby_column);
|
|
679
|
+
const groupby_column_name = groupby_column.name;
|
|
680
|
+
const target_column_name = target_column.name;
|
|
681
|
+
const completed_column_name = completed_column.name;
|
|
731
682
|
if (column_groupby_column_key) {
|
|
732
683
|
const column_groupby_column = this._get_column_by_key(column_groupby_column_key);
|
|
733
684
|
if (!column_groupby_column) {
|
|
734
685
|
this.error = 'Column_group_by_column_not_found';
|
|
735
686
|
return '';
|
|
736
687
|
}
|
|
737
|
-
const column_groupby_column_name =
|
|
688
|
+
const column_groupby_column_name = this._chart_column_name_to_sql(column_groupby_column, {
|
|
738
689
|
'date_granularity': date_granularity,
|
|
739
690
|
'geolocation_granularity': geolocation_granularity
|
|
740
691
|
});
|
|
741
|
-
return "SELECT `".concat(
|
|
692
|
+
return "SELECT `".concat(groupby_column_name, "`, ").concat(column_groupby_column_name, ", SUM(`").concat(target_column_name, "`), SUM(`").concat(completed_column_name, "`) FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY `").concat(groupby_column_name, "`, ").concat(column_groupby_column_name, " LIMIT 0, 5000");
|
|
742
693
|
}
|
|
743
|
-
return "SELECT `".concat(
|
|
694
|
+
return "SELECT `".concat(groupby_column_name, "`, `").concat(target_column_name, "`, `").concat(completed_column_name, "` FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY `").concat(groupby_column_name, "`, `").concat(target_column_name, "`, `").concat(completed_column_name, "` LIMIT 0, 5000");
|
|
744
695
|
};
|
|
745
696
|
this._scatter_statistic_2_sql = () => {
|
|
746
697
|
const x_axis_column_key = this.chart['x_axis_column_key'];
|
|
@@ -752,15 +703,20 @@ class ChartDataSQL {
|
|
|
752
703
|
|
|
753
704
|
// x axis column
|
|
754
705
|
const x_axis_column = this._get_column_by_key(x_axis_column_key);
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
if (!xAxisColumnName) {
|
|
758
|
-
this.error = 'Group_by_column_not_found';
|
|
706
|
+
if (!x_axis_column) {
|
|
707
|
+
this.error = 'X_axis_column_not_found';
|
|
759
708
|
return '';
|
|
760
709
|
}
|
|
710
|
+
|
|
761
711
|
// y axis column
|
|
762
712
|
const y_axis_column = this._get_column_by_key(y_axis_column_key);
|
|
763
|
-
|
|
713
|
+
if (!y_axis_column) {
|
|
714
|
+
this.error = 'Y_axis_column_not_found';
|
|
715
|
+
return '';
|
|
716
|
+
}
|
|
717
|
+
this._update_filter_sql(x_axis_include_empty_cells, x_axis_column);
|
|
718
|
+
const xAxisColumnName = x_axis_column.name;
|
|
719
|
+
const yAxisColumnName = y_axis_column.name;
|
|
764
720
|
if (!yAxisColumnName) {
|
|
765
721
|
this.error = 'Y_axis_column_not_found';
|
|
766
722
|
return '';
|
|
@@ -771,11 +727,11 @@ class ChartDataSQL {
|
|
|
771
727
|
this.error = 'Column_group_by_column_not_found';
|
|
772
728
|
return '';
|
|
773
729
|
}
|
|
774
|
-
const column_groupby_column_name =
|
|
730
|
+
const column_groupby_column_name = this._chart_column_name_to_sql(column_groupby_column, {
|
|
775
731
|
'date_granularity': date_granularity,
|
|
776
732
|
'geolocation_granularity': geolocation_granularity
|
|
777
733
|
});
|
|
778
|
-
return "SELECT `".concat(xAxisColumnName, "`, `").concat(yAxisColumnName, "`, ").concat(column_groupby_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY `").concat(xAxisColumnName, "`, `").concat(yAxisColumnName, "
|
|
734
|
+
return "SELECT `".concat(xAxisColumnName, "`, `").concat(yAxisColumnName, "`, ").concat(column_groupby_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY `").concat(xAxisColumnName, "`, `").concat(yAxisColumnName, "`, ").concat(column_groupby_column_name, " LIMIT 0, 5000");
|
|
779
735
|
}
|
|
780
736
|
return "SELECT `".concat(xAxisColumnName, "`, `").concat(yAxisColumnName, "` FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY `").concat(xAxisColumnName, "`, `").concat(yAxisColumnName, "` LIMIT 0, 5000");
|
|
781
737
|
};
|
|
@@ -788,7 +744,7 @@ class ChartDataSQL {
|
|
|
788
744
|
summary_method,
|
|
789
745
|
summary_column_key
|
|
790
746
|
} = this.chart;
|
|
791
|
-
const groupby_column = this.
|
|
747
|
+
const groupby_column = this._get_column_by_key(geo_column_key);
|
|
792
748
|
if (!groupby_column) {
|
|
793
749
|
this.error = 'Geo_column_not_found';
|
|
794
750
|
return '';
|
|
@@ -797,7 +753,7 @@ class ChartDataSQL {
|
|
|
797
753
|
this._update_filter_sql(false, groupby_column);
|
|
798
754
|
|
|
799
755
|
// map do not have date column ,so date_granularity is not needed
|
|
800
|
-
const groupby_column_name =
|
|
756
|
+
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
801
757
|
'date_granularity': null,
|
|
802
758
|
'geolocation_granularity': geolocation_granularity
|
|
803
759
|
});
|
|
@@ -806,7 +762,7 @@ class ChartDataSQL {
|
|
|
806
762
|
if (uppercase_summary_type === 'COUNT') {
|
|
807
763
|
summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
|
|
808
764
|
} else {
|
|
809
|
-
const summary_column = this.
|
|
765
|
+
const summary_column = this._get_column_by_key(summary_column_key);
|
|
810
766
|
if (summary_column) {
|
|
811
767
|
const uppercase_summary_method = summary_method.toUpperCase();
|
|
812
768
|
summary_column_name = this._summary_column_2_sql(uppercase_summary_method, summary_column);
|
|
@@ -829,23 +785,21 @@ class ChartDataSQL {
|
|
|
829
785
|
this.error = 'Geo_column_not_found';
|
|
830
786
|
return '';
|
|
831
787
|
}
|
|
832
|
-
const columnName = groupby_column.name;
|
|
833
|
-
const isAdvanced = summary_type === CHART_SUMMARY_TYPE.ADVANCED;
|
|
834
|
-
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summary_method] : 'COUNT';
|
|
835
788
|
this._update_filter_sql(false, groupby_column);
|
|
836
|
-
|
|
837
|
-
|
|
789
|
+
const column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
790
|
+
'date_granularity': '',
|
|
791
|
+
'geolocation_granularity': ''
|
|
792
|
+
});
|
|
793
|
+
let summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
|
|
794
|
+
if (summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
838
795
|
const summary_column = this._get_column_by_key(summary_column_key);
|
|
839
796
|
if (!summary_column) {
|
|
840
797
|
this.error = 'Summary_column_not_found';
|
|
841
798
|
return '';
|
|
842
799
|
}
|
|
843
|
-
|
|
844
|
-
sqlString = "select `".concat(columnName, "`, ").concat(summary_column_name, " from ").concat(this.table_name, " ").concat(this.filter_sql, " group by ").concat(columnName, " limit 5000");
|
|
845
|
-
} else {
|
|
846
|
-
sqlString = "select `".concat(columnName, "`, ").concat(method, "(").concat(columnName, ") from ").concat(this.table_name, " ").concat(this.filter_sql, " group by ").concat(columnName, " limit 5000");
|
|
800
|
+
summary_column_name = this._summary_column_2_sql(summary_method.toUpperCase(), summary_column);
|
|
847
801
|
}
|
|
848
|
-
return
|
|
802
|
+
return "SELECT ".concat(column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(column_name, " LIMIT 0, 5000");
|
|
849
803
|
};
|
|
850
804
|
this.to_sql = () => {
|
|
851
805
|
if (this.error) {
|
|
@@ -997,15 +951,14 @@ class ChartDataSQL {
|
|
|
997
951
|
this.table = table;
|
|
998
952
|
this.chart = (chart === null || chart === void 0 ? void 0 : chart.config) || {};
|
|
999
953
|
this.username = username;
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
this.table_name = "`".concat(tableName, "`");
|
|
954
|
+
const table_name = (table === null || table === void 0 ? void 0 : table.name) || '';
|
|
955
|
+
this.table_name = "`".concat(table_name, "`");
|
|
1003
956
|
this.chart_type = (chart === null || chart === void 0 ? void 0 : (_chart$config = chart.config) === null || _chart$config === void 0 ? void 0 : _chart$config.type) || '';
|
|
1004
957
|
|
|
1005
958
|
// columns
|
|
1006
|
-
this.
|
|
959
|
+
this.column_key_map = {};
|
|
1007
960
|
Array.isArray(table.columns) && table.columns.forEach(column => {
|
|
1008
|
-
this.
|
|
961
|
+
this.column_key_map[column.key] = column;
|
|
1009
962
|
});
|
|
1010
963
|
this.filter_sql = filter2SqlCondition(table, chart, username, userId, userDepartmentIdsMap);
|
|
1011
964
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sea-chart",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31beta",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@antv/data-set": "0.11.8",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@antv/scale": "0.3.14",
|
|
24
24
|
"babel-plugin-on-demand-loading": "^0.0.9",
|
|
25
|
-
"dtable-ui-component": "4.4.31",
|
|
25
|
+
"dtable-ui-component": "~4.4.31",
|
|
26
26
|
"dtable-utils": "~4.4.*",
|
|
27
27
|
"prop-types": "15.8.1",
|
|
28
28
|
"react": "^17.0.0",
|