semanticdb-core 1.0.29 → 1.0.31
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SchemaType } from '../schema/schema';
|
|
1
2
|
import { GroupbyItemType, LogicformType, PredItemType } from './logicform';
|
|
2
3
|
import { QueryType } from './types/query';
|
|
3
4
|
/**
|
|
@@ -73,3 +74,11 @@ export declare const getFlattenQuery: (query: QueryType) => QueryType;
|
|
|
73
74
|
* ```
|
|
74
75
|
*/
|
|
75
76
|
export declare const getValueByChain: (query: QueryType, chain: string) => any;
|
|
77
|
+
/**
|
|
78
|
+
* 肯定是返回flatten的dimension
|
|
79
|
+
* @param logicform
|
|
80
|
+
*/
|
|
81
|
+
export declare const getDimensionsInLogicform: (logicform: LogicformType, schemasDict: Record<string, SchemaType>) => {
|
|
82
|
+
_id: string;
|
|
83
|
+
level?: string;
|
|
84
|
+
}[];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getValueByChain = exports.getFlattenQuery = exports.isDimensionInLogicform = exports.isDimensionInPred = exports.isDimensionInGroupby = exports.isDimensionInQuery = void 0;
|
|
3
|
+
exports.getDimensionsInLogicform = exports.getValueByChain = exports.getFlattenQuery = exports.isDimensionInLogicform = exports.isDimensionInPred = exports.isDimensionInGroupby = exports.isDimensionInQuery = void 0;
|
|
4
4
|
const date_1 = require("../common/date");
|
|
5
|
+
const schema_utils_1 = require("../schema/schema.utils");
|
|
5
6
|
const tws = (0, date_1.getSupportedTimeWindows)();
|
|
6
7
|
/**
|
|
7
8
|
* 判断一个维度是否在查询中被使用
|
|
@@ -19,7 +20,19 @@ const isDimensionInQuery = (query, dimension, strictMode = true) => {
|
|
|
19
20
|
const flattenQuery = (0, exports.getFlattenQuery)(query);
|
|
20
21
|
if (strictMode) {
|
|
21
22
|
if (typeof dimension === 'string') {
|
|
22
|
-
|
|
23
|
+
if (!(dimension in flattenQuery)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// 如果是单纯的$exists: true, 不认为是。
|
|
27
|
+
const v = flattenQuery[dimension];
|
|
28
|
+
if (v &&
|
|
29
|
+
typeof v === 'object' &&
|
|
30
|
+
'$exists' in v &&
|
|
31
|
+
v['$exists'] === true &&
|
|
32
|
+
Object.keys(v).length === 1) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
23
36
|
}
|
|
24
37
|
else if (dimension._id in flattenQuery) {
|
|
25
38
|
if ((0, date_1.isStandardDateForm)(flattenQuery[dimension._id])) {
|
|
@@ -30,8 +43,16 @@ const isDimensionInQuery = (query, dimension, strictMode = true) => {
|
|
|
30
43
|
}
|
|
31
44
|
}
|
|
32
45
|
}
|
|
33
|
-
for (const k of Object.
|
|
46
|
+
for (const [k, v] of Object.entries(flattenQuery)) {
|
|
34
47
|
if (k.startsWith(`${dimension}_`) || k === dimension) {
|
|
48
|
+
// 如果是单纯的$exists: true, 不认为是。
|
|
49
|
+
if (v &&
|
|
50
|
+
typeof v === 'object' &&
|
|
51
|
+
'$exists' in v &&
|
|
52
|
+
v['$exists'] === true &&
|
|
53
|
+
Object.keys(v).length === 1) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
35
56
|
return true;
|
|
36
57
|
}
|
|
37
58
|
}
|
|
@@ -211,3 +232,28 @@ const getValueByChain = (query, chain) => {
|
|
|
211
232
|
return undefined;
|
|
212
233
|
};
|
|
213
234
|
exports.getValueByChain = getValueByChain;
|
|
235
|
+
/**
|
|
236
|
+
* 肯定是返回flatten的dimension
|
|
237
|
+
* @param logicform
|
|
238
|
+
*/
|
|
239
|
+
const getDimensionsInLogicform = (logicform, schemasDict) => {
|
|
240
|
+
const dimensions = [];
|
|
241
|
+
if (logicform.query) {
|
|
242
|
+
const flattenQuery = (0, exports.getFlattenQuery)(logicform.query);
|
|
243
|
+
for (const [k, v] of Object.entries(flattenQuery)) {
|
|
244
|
+
const property = (0, schema_utils_1.findPropertyByName)(logicform.schema, k, schemasDict);
|
|
245
|
+
if ((property === null || property === void 0 ? void 0 : property.primal_type) === 'date') {
|
|
246
|
+
const gran = (0, date_1.getMinGran)(v);
|
|
247
|
+
dimensions.push({ _id: k, level: gran || 'day' });
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
dimensions.push({ _id: k });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (logicform.groupby) {
|
|
255
|
+
dimensions.push(...logicform.groupby);
|
|
256
|
+
}
|
|
257
|
+
return dimensions;
|
|
258
|
+
};
|
|
259
|
+
exports.getDimensionsInLogicform = getDimensionsInLogicform;
|