@sisense/sdk-data 1.8.0 → 1.10.0
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/dimensional-model/attributes.d.ts +11 -0
- package/dist/dimensional-model/attributes.js +20 -1
- package/dist/dimensional-model/base.d.ts +0 -11
- package/dist/dimensional-model/base.js +0 -17
- package/dist/dimensional-model/dimensions.js +5 -4
- package/dist/dimensional-model/factory.js +0 -1
- package/dist/dimensional-model/filters/factory.d.ts +49 -0
- package/dist/dimensional-model/filters/factory.js +56 -1
- package/dist/dimensional-model/filters/filters.js +0 -3
- package/dist/dimensional-model/filters/utils/attribute-measure-util.d.ts +47 -0
- package/dist/dimensional-model/filters/utils/attribute-measure-util.js +77 -0
- package/dist/dimensional-model/filters/utils/condition-filter-util.d.ts +19 -0
- package/dist/dimensional-model/filters/utils/condition-filter-util.js +162 -0
- package/dist/dimensional-model/filters/utils/filter-code-util.d.ts +13 -0
- package/dist/dimensional-model/filters/utils/filter-code-util.js +49 -0
- package/dist/dimensional-model/filters/utils/filter-from-jaql-util.d.ts +67 -0
- package/dist/dimensional-model/filters/utils/filter-from-jaql-util.js +149 -0
- package/dist/dimensional-model/filters/utils/filter-types-util.d.ts +15 -0
- package/dist/dimensional-model/filters/utils/filter-types-util.js +71 -0
- package/dist/dimensional-model/filters/utils/{modern-analytics-filters/types.d.ts → types.d.ts} +48 -48
- package/dist/dimensional-model/filters/utils/types.js +96 -0
- package/dist/dimensional-model/measures/factory.d.ts +13 -0
- package/dist/dimensional-model/measures/factory.js +15 -0
- package/dist/dimensional-model/measures/measures.js +1 -4
- package/dist/dimensional-model/types.d.ts +10 -1
- package/dist/dimensional-model/types.js +1 -3
- package/dist/utils.js +1 -1
- package/package.json +4 -4
- package/dist/dimensional-model/filters/utils/filter-jaql-util.d.ts +0 -25
- package/dist/dimensional-model/filters/utils/filter-jaql-util.js +0 -167
- package/dist/dimensional-model/filters/utils/modern-analytics-filters/condition-filter-util.d.ts +0 -2
- package/dist/dimensional-model/filters/utils/modern-analytics-filters/condition-filter-util.js +0 -27
- package/dist/dimensional-model/filters/utils/modern-analytics-filters/condition-types-util.d.ts +0 -24
- package/dist/dimensional-model/filters/utils/modern-analytics-filters/condition-types-util.js +0 -138
- package/dist/dimensional-model/filters/utils/modern-analytics-filters/filter-types-util.d.ts +0 -31
- package/dist/dimensional-model/filters/utils/modern-analytics-filters/filter-types-util.js +0 -114
- package/dist/dimensional-model/filters/utils/modern-analytics-filters/types.js +0 -97
- /package/dist/dimensional-model/filters/utils/{modern-analytics-filters/date-time-filter-util.d.ts → date-time-filter-util.d.ts} +0 -0
- /package/dist/dimensional-model/filters/utils/{modern-analytics-filters/date-time-filter-util.js → date-time-filter-util.js} +0 -0
|
@@ -125,3 +125,14 @@ export declare function createAttribute(json: any): Attribute;
|
|
|
125
125
|
* @internal
|
|
126
126
|
*/
|
|
127
127
|
export declare function createLevel(json: any): LevelAttribute;
|
|
128
|
+
/**
|
|
129
|
+
* Normalize attribute name
|
|
130
|
+
*
|
|
131
|
+
* @param tableName - Table name (e.g., Commerce Sales)
|
|
132
|
+
* @param columnName - Column name (e.g., Order Date)
|
|
133
|
+
* @param dateLevel - Date level (e.g., Years)
|
|
134
|
+
* @param modelName - module name (e.g., DM)
|
|
135
|
+
* @return full normalized attribute name (e.g., DM.CommerceSales.OrderDate.Years)
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
export declare function normalizeAttributeName(tableName: string, columnName: string, dateLevel?: string, modelName?: string): string;
|
|
@@ -207,7 +207,7 @@ export class DimensionalLevelAttribute extends DimensionalAttribute {
|
|
|
207
207
|
}
|
|
208
208
|
static translateJaqlToGranularity(json) {
|
|
209
209
|
const returnUnsupported = (lvl) => {
|
|
210
|
-
console.warn('Unsupported granularity');
|
|
210
|
+
console.warn('Unsupported granularity', lvl);
|
|
211
211
|
return lvl;
|
|
212
212
|
};
|
|
213
213
|
if (json.dateTimeLevel) {
|
|
@@ -281,3 +281,22 @@ export function createAttribute(json) {
|
|
|
281
281
|
export function createLevel(json) {
|
|
282
282
|
return new DimensionalLevelAttribute(json.name || json.title, json.attribute || json.expression || json.dim, json.granularity, json.format, json.desc || json.description);
|
|
283
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Normalize attribute name
|
|
286
|
+
*
|
|
287
|
+
* @param tableName - Table name (e.g., Commerce Sales)
|
|
288
|
+
* @param columnName - Column name (e.g., Order Date)
|
|
289
|
+
* @param dateLevel - Date level (e.g., Years)
|
|
290
|
+
* @param modelName - module name (e.g., DM)
|
|
291
|
+
* @return full normalized attribute name (e.g., DM.CommerceSales.OrderDate.Years)
|
|
292
|
+
* @internal
|
|
293
|
+
*/
|
|
294
|
+
export function normalizeAttributeName(tableName, columnName, dateLevel, modelName) {
|
|
295
|
+
return ((modelName && modelName.length > 0 ? modelName + '.' : '') +
|
|
296
|
+
normalizeName(tableName) +
|
|
297
|
+
'.' +
|
|
298
|
+
normalizeName(columnName) +
|
|
299
|
+
(dateLevel && dateLevel.length > 0
|
|
300
|
+
? '.' + DimensionalLevelAttribute.translateJaqlToGranularity({ level: dateLevel })
|
|
301
|
+
: ''));
|
|
302
|
+
}
|
|
@@ -41,14 +41,3 @@ export declare abstract class DimensionalElement implements Element {
|
|
|
41
41
|
* @internal
|
|
42
42
|
*/
|
|
43
43
|
export declare function normalizeName(name: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Normalize attribute name
|
|
46
|
-
*
|
|
47
|
-
* @param tableName - Table name (e.g., Commerce Sales)
|
|
48
|
-
* @param columnName - Column name (e.g., Order Date)
|
|
49
|
-
* @param dateLevel - Date level (e.g., Years)
|
|
50
|
-
* @param modelName - module name (e.g., DM)
|
|
51
|
-
* @return full normalized attribute name (e.g., DM.CommerceSales.OrderDate.Years)
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
export declare function normalizeAttributeName(tableName: string, columnName: string, dateLevel?: string, modelName?: string): string;
|
|
@@ -51,20 +51,3 @@ export function normalizeName(name) {
|
|
|
51
51
|
}
|
|
52
52
|
return normalizedName;
|
|
53
53
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Normalize attribute name
|
|
56
|
-
*
|
|
57
|
-
* @param tableName - Table name (e.g., Commerce Sales)
|
|
58
|
-
* @param columnName - Column name (e.g., Order Date)
|
|
59
|
-
* @param dateLevel - Date level (e.g., Years)
|
|
60
|
-
* @param modelName - module name (e.g., DM)
|
|
61
|
-
* @return full normalized attribute name (e.g., DM.CommerceSales.OrderDate.Years)
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
|
-
export function normalizeAttributeName(tableName, columnName, dateLevel, modelName) {
|
|
65
|
-
return ((modelName && modelName.length > 0 ? modelName + '.' : '') +
|
|
66
|
-
normalizeName(tableName) +
|
|
67
|
-
'.' +
|
|
68
|
-
normalizeName(columnName) +
|
|
69
|
-
(dateLevel && dateLevel.length > 0 ? '.' + dateLevel : ''));
|
|
70
|
-
}
|
|
@@ -247,7 +247,7 @@ export function createDimension(json) {
|
|
|
247
247
|
const type = DimensionalDimension.parseType(json.dimtype || json.type);
|
|
248
248
|
// date dimension
|
|
249
249
|
if (type == MetadataTypes.DateDimension) {
|
|
250
|
-
return new DimensionalDateDimension(name, expression);
|
|
250
|
+
return new DimensionalDateDimension(name, expression, description);
|
|
251
251
|
}
|
|
252
252
|
// attributes
|
|
253
253
|
const atts = Object.getOwnPropertyNames(json)
|
|
@@ -258,12 +258,12 @@ export function createDimension(json) {
|
|
|
258
258
|
let att;
|
|
259
259
|
for (let i = 0; i < json.attributes.length; i++) {
|
|
260
260
|
att = json.attributes[i];
|
|
261
|
-
atts.push(new DimensionalAttribute(att.name, att.expression, att.type));
|
|
261
|
+
atts.push(new DimensionalAttribute(att.name, att.expression, att.type, att.description));
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
// default attribute
|
|
265
265
|
else if (expression) {
|
|
266
|
-
atts.push(new DimensionalAttribute(name, expression));
|
|
266
|
+
atts.push(new DimensionalAttribute(name, expression, type, description));
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
// nested dimensions
|
|
@@ -295,5 +295,6 @@ export function createDimension(json) {
|
|
|
295
295
|
export function createDateDimension(json) {
|
|
296
296
|
const name = json.name || json.title;
|
|
297
297
|
const expression = json.expression || json.dim;
|
|
298
|
-
|
|
298
|
+
const description = json.desc || json.description;
|
|
299
|
+
return new DimensionalDateDimension(name, expression, description);
|
|
299
300
|
}
|
|
@@ -523,6 +523,39 @@ export declare function today(dimension: DateDimension): Filter;
|
|
|
523
523
|
* @internal
|
|
524
524
|
*/
|
|
525
525
|
export declare function measureBase(attribute: Attribute, measure: Measure, operatorA?: string, valueA?: number, operatorB?: string, valueB?: number): Filter;
|
|
526
|
+
/**
|
|
527
|
+
* Creates a filter to isolate a measure value equal to a given number.
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* Filter for categories that have an average revenue equal 50 in the Sample ECommerce data model.
|
|
531
|
+
* ```ts
|
|
532
|
+
* filterFactory.measureEquals(
|
|
533
|
+
* measures.average(DM.Commerce.Revenue),
|
|
534
|
+
* 50
|
|
535
|
+
* )
|
|
536
|
+
* ```
|
|
537
|
+
* @param measure - Measure to filter by
|
|
538
|
+
* @param value - Value
|
|
539
|
+
* @returns A filter instance
|
|
540
|
+
*/
|
|
541
|
+
export declare function measureEquals(measure: BaseMeasure, value: number): Filter;
|
|
542
|
+
/**
|
|
543
|
+
* Creates a filter to isolate a measure value greater than to a given number.
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* Filter for categories that have an average revenue greater than
|
|
547
|
+
* to 50 in the Sample ECommerce data model.
|
|
548
|
+
* ```ts
|
|
549
|
+
* filterFactory.measureGreaterThan(
|
|
550
|
+
* measures.average(DM.Commerce.Revenue),
|
|
551
|
+
* 50
|
|
552
|
+
* )
|
|
553
|
+
* ```
|
|
554
|
+
* @param measure - Measure to filter by
|
|
555
|
+
* @param value - Min value
|
|
556
|
+
* @returns A filter instance
|
|
557
|
+
*/
|
|
558
|
+
export declare function measureGreaterThan(measure: BaseMeasure, value: number): Filter;
|
|
526
559
|
/**
|
|
527
560
|
* Creates a filter to isolate a measure value greater than or equal to a given number.
|
|
528
561
|
*
|
|
@@ -557,6 +590,22 @@ export declare function measureGreaterThanOrEqual(measure: BaseMeasure, value: n
|
|
|
557
590
|
* @returns A filter instance
|
|
558
591
|
*/
|
|
559
592
|
export declare function measureLessThanOrEqual(measure: BaseMeasure, value: number): Filter;
|
|
593
|
+
/**
|
|
594
|
+
* Creates a filter to isolate a measure value less than a given number.
|
|
595
|
+
*
|
|
596
|
+
* @example
|
|
597
|
+
* Filter for categories that have an average revenue less than 100 in the Sample ECommerce data model.
|
|
598
|
+
* ```ts
|
|
599
|
+
* filterFactory.measureLessThan(
|
|
600
|
+
* measures.average(DM.Commerce.Revenue),
|
|
601
|
+
* 100
|
|
602
|
+
* )
|
|
603
|
+
* ```
|
|
604
|
+
* @param measure - Measure to filter by
|
|
605
|
+
* @param value - Value
|
|
606
|
+
* @returns A filter instance
|
|
607
|
+
*/
|
|
608
|
+
export declare function measureLessThan(measure: BaseMeasure, value: number): Filter;
|
|
560
609
|
/**
|
|
561
610
|
* Creates a filter to isolate a measure value between or equal to two given numbers.
|
|
562
611
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TextOperators, NumericOperators, DateOperators, LogicalOperators, RankingOperators, LogicalAttributeFilter, MembersFilter, ExcludeFilter, NumericFilter, MeasureFilter, RankingFilter, TextFilter, DateRangeFilter, RelativeDateFilter, } from './filters.js';
|
|
2
|
-
import { createGenericFilter } from './utils/filter-jaql-util.js';
|
|
2
|
+
import { createGenericFilter } from './utils/filter-from-jaql-util.js';
|
|
3
3
|
// LOGICAL FILTERS
|
|
4
4
|
/**
|
|
5
5
|
* Creates a filter representing the union of multiple filters on the same attribute. The resulting
|
|
@@ -600,6 +600,43 @@ export function today(dimension) {
|
|
|
600
600
|
export function measureBase(attribute, measure, operatorA, valueA, operatorB, valueB) {
|
|
601
601
|
return new MeasureFilter(attribute, measure, operatorA, valueA, operatorB, valueB);
|
|
602
602
|
}
|
|
603
|
+
/**
|
|
604
|
+
* Creates a filter to isolate a measure value equal to a given number.
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* Filter for categories that have an average revenue equal 50 in the Sample ECommerce data model.
|
|
608
|
+
* ```ts
|
|
609
|
+
* filterFactory.measureEquals(
|
|
610
|
+
* measures.average(DM.Commerce.Revenue),
|
|
611
|
+
* 50
|
|
612
|
+
* )
|
|
613
|
+
* ```
|
|
614
|
+
* @param measure - Measure to filter by
|
|
615
|
+
* @param value - Value
|
|
616
|
+
* @returns A filter instance
|
|
617
|
+
*/
|
|
618
|
+
export function measureEquals(measure, value) {
|
|
619
|
+
return measureBase(measure.attribute, measure, NumericOperators.Equals, value);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Creates a filter to isolate a measure value greater than to a given number.
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* Filter for categories that have an average revenue greater than
|
|
626
|
+
* to 50 in the Sample ECommerce data model.
|
|
627
|
+
* ```ts
|
|
628
|
+
* filterFactory.measureGreaterThan(
|
|
629
|
+
* measures.average(DM.Commerce.Revenue),
|
|
630
|
+
* 50
|
|
631
|
+
* )
|
|
632
|
+
* ```
|
|
633
|
+
* @param measure - Measure to filter by
|
|
634
|
+
* @param value - Min value
|
|
635
|
+
* @returns A filter instance
|
|
636
|
+
*/
|
|
637
|
+
export function measureGreaterThan(measure, value) {
|
|
638
|
+
return measureBase(measure.attribute, measure, NumericOperators.FromNotEqual, value);
|
|
639
|
+
}
|
|
603
640
|
/**
|
|
604
641
|
* Creates a filter to isolate a measure value greater than or equal to a given number.
|
|
605
642
|
*
|
|
@@ -638,6 +675,24 @@ export function measureGreaterThanOrEqual(measure, value) {
|
|
|
638
675
|
export function measureLessThanOrEqual(measure, value) {
|
|
639
676
|
return measureBase(measure.attribute, measure, NumericOperators.To, value);
|
|
640
677
|
}
|
|
678
|
+
/**
|
|
679
|
+
* Creates a filter to isolate a measure value less than a given number.
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* Filter for categories that have an average revenue less than 100 in the Sample ECommerce data model.
|
|
683
|
+
* ```ts
|
|
684
|
+
* filterFactory.measureLessThan(
|
|
685
|
+
* measures.average(DM.Commerce.Revenue),
|
|
686
|
+
* 100
|
|
687
|
+
* )
|
|
688
|
+
* ```
|
|
689
|
+
* @param measure - Measure to filter by
|
|
690
|
+
* @param value - Value
|
|
691
|
+
* @returns A filter instance
|
|
692
|
+
*/
|
|
693
|
+
export function measureLessThan(measure, value) {
|
|
694
|
+
return measureBase(measure.attribute, measure, NumericOperators.ToNotEqual, value);
|
|
695
|
+
}
|
|
641
696
|
/**
|
|
642
697
|
* Creates a filter to isolate a measure value between or equal to two given numbers.
|
|
643
698
|
*
|
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
5
|
-
/* eslint-disable max-lines */
|
|
6
5
|
/* eslint-disable max-params */
|
|
7
6
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
8
|
-
/* eslint-disable max-lines-per-function */
|
|
9
|
-
/* eslint-disable complexity */
|
|
10
7
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
11
8
|
import hash from 'object-hash';
|
|
12
9
|
import { DimensionalElement } from '../base.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Attribute, BaseMeasure, LevelAttribute } from '../../interfaces.js';
|
|
2
|
+
import { FilterJaql } from '../../types.js';
|
|
3
|
+
import { FilterJaqlInternal, RankingFilterJaql } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an attribute or level attribute from the provided parameters
|
|
6
|
+
*
|
|
7
|
+
* @param dim - Dimension expression
|
|
8
|
+
* @param table - Table name
|
|
9
|
+
* @param column - Column name
|
|
10
|
+
* @param level - Date level
|
|
11
|
+
* @param dataType - Data type
|
|
12
|
+
* @returns attribute or level attribute
|
|
13
|
+
*/
|
|
14
|
+
export declare const createAttributeHelper: (dim: string, table: string, column: string, level: string | undefined, dataType: string) => Attribute | LevelAttribute;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an attribute or level attribute from the provided filter JAQL object
|
|
17
|
+
*
|
|
18
|
+
* @param jaql - Filter JAQL object
|
|
19
|
+
* @returns attribute or level attribute
|
|
20
|
+
*/
|
|
21
|
+
export declare const createAttributeFromFilterJaql: (jaql: FilterJaql | FilterJaqlInternal) => Attribute | LevelAttribute;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a measure from the provided parameters
|
|
24
|
+
*
|
|
25
|
+
* @param dim - Dimension expression
|
|
26
|
+
* @param table - Table name
|
|
27
|
+
* @param column - Column name
|
|
28
|
+
* @param level - Date level
|
|
29
|
+
* @param dataType - Data type
|
|
30
|
+
* @param agg - Aggregation function
|
|
31
|
+
* @returns measure
|
|
32
|
+
*/
|
|
33
|
+
export declare const createMeasureHelper: (dim: string, table: string, column: string, level: string | undefined, dataType: string, agg: string) => BaseMeasure;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a measure from the provided filter JAQL object
|
|
36
|
+
*
|
|
37
|
+
* @param jaql - Filter JAQL object
|
|
38
|
+
* @returns Measure
|
|
39
|
+
*/
|
|
40
|
+
export declare const createMeasureFromFilterJaql: (jaql: FilterJaqlInternal) => BaseMeasure | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a measure from the provided ranking filter JAQL object
|
|
43
|
+
*
|
|
44
|
+
* @param jaql - Ranking filter Jaql object
|
|
45
|
+
* @returns Measure
|
|
46
|
+
*/
|
|
47
|
+
export declare const createMeasureFromRankingFilterJaql: (jaql: RankingFilterJaql) => BaseMeasure;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { DimensionalAttribute, DimensionalLevelAttribute, normalizeAttributeName, } from '../../attributes.js';
|
|
2
|
+
import { isNumber } from '../../simple-column-types.js';
|
|
3
|
+
import { MetadataTypes } from '../../types.js';
|
|
4
|
+
import * as measureFactory from '../../measures/factory.js';
|
|
5
|
+
const DATA_MODEL_MODULE_NAME = 'DM';
|
|
6
|
+
/**
|
|
7
|
+
* Creates an attribute or level attribute from the provided parameters
|
|
8
|
+
*
|
|
9
|
+
* @param dim - Dimension expression
|
|
10
|
+
* @param table - Table name
|
|
11
|
+
* @param column - Column name
|
|
12
|
+
* @param level - Date level
|
|
13
|
+
* @param dataType - Data type
|
|
14
|
+
* @returns attribute or level attribute
|
|
15
|
+
*/
|
|
16
|
+
export const createAttributeHelper = (dim, table, column, level, dataType) => {
|
|
17
|
+
if (level) {
|
|
18
|
+
const dateLevel = DimensionalLevelAttribute.translateJaqlToGranularity({ level });
|
|
19
|
+
const levelAttribute = new DimensionalLevelAttribute(column, dim, dateLevel);
|
|
20
|
+
levelAttribute.composeCode = normalizeAttributeName(table, column, level, DATA_MODEL_MODULE_NAME);
|
|
21
|
+
return levelAttribute;
|
|
22
|
+
}
|
|
23
|
+
const attributeType = isNumber(dataType)
|
|
24
|
+
? MetadataTypes.NumericAttribute
|
|
25
|
+
: MetadataTypes.TextAttribute;
|
|
26
|
+
const attribute = new DimensionalAttribute(column, dim, attributeType);
|
|
27
|
+
attribute.composeCode = normalizeAttributeName(table, column, undefined, DATA_MODEL_MODULE_NAME);
|
|
28
|
+
return attribute;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Creates an attribute or level attribute from the provided filter JAQL object
|
|
32
|
+
*
|
|
33
|
+
* @param jaql - Filter JAQL object
|
|
34
|
+
* @returns attribute or level attribute
|
|
35
|
+
*/
|
|
36
|
+
export const createAttributeFromFilterJaql = (jaql) => {
|
|
37
|
+
return createAttributeHelper(jaql.dim, jaql.table, jaql.column, jaql.level, jaql.datatype);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Creates a measure from the provided parameters
|
|
41
|
+
*
|
|
42
|
+
* @param dim - Dimension expression
|
|
43
|
+
* @param table - Table name
|
|
44
|
+
* @param column - Column name
|
|
45
|
+
* @param level - Date level
|
|
46
|
+
* @param dataType - Data type
|
|
47
|
+
* @param agg - Aggregation function
|
|
48
|
+
* @returns measure
|
|
49
|
+
*/
|
|
50
|
+
export const createMeasureHelper = (dim, table, column, level, dataType, agg) => {
|
|
51
|
+
const attribute = createAttributeHelper(dim, table, column, level, dataType);
|
|
52
|
+
const measure = measureFactory.aggregate(attribute, agg);
|
|
53
|
+
measure.composeCode = `measureFactory.${agg}(${attribute.composeCode})`;
|
|
54
|
+
return measure;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Creates a measure from the provided filter JAQL object
|
|
58
|
+
*
|
|
59
|
+
* @param jaql - Filter JAQL object
|
|
60
|
+
* @returns Measure
|
|
61
|
+
*/
|
|
62
|
+
export const createMeasureFromFilterJaql = (jaql) => {
|
|
63
|
+
const { dim, table, column, level, datatype: dataType, agg } = jaql;
|
|
64
|
+
if (!agg)
|
|
65
|
+
return undefined;
|
|
66
|
+
return createMeasureHelper(dim, table, column, level, dataType, agg);
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Creates a measure from the provided ranking filter JAQL object
|
|
70
|
+
*
|
|
71
|
+
* @param jaql - Ranking filter Jaql object
|
|
72
|
+
* @returns Measure
|
|
73
|
+
*/
|
|
74
|
+
export const createMeasureFromRankingFilterJaql = (jaql) => {
|
|
75
|
+
const { dim, table, column, level, datatype: dataType, agg } = jaql;
|
|
76
|
+
return createMeasureHelper(dim, table, column, level, dataType, agg);
|
|
77
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConditionFilterJaql, ConditionFilterType } from './types.js';
|
|
2
|
+
import { Attribute, BaseMeasure, Filter } from '../../interfaces.js';
|
|
3
|
+
export declare const getSelectedConditionOption: (filter: ConditionFilterJaql) => ConditionFilterType;
|
|
4
|
+
/**
|
|
5
|
+
* Creates an attribute filter from the provided attribute and condition filter JAQL object
|
|
6
|
+
*
|
|
7
|
+
* @param attribute - Provided attribute
|
|
8
|
+
* @param conditionFilterJaql - Condition filter JAQL object
|
|
9
|
+
* @returns attribute filter
|
|
10
|
+
*/
|
|
11
|
+
export declare const createAttributeFilterFromConditionFilterJaql: (attribute: Attribute, conditionFilterJaql: ConditionFilterJaql) => Filter;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a measure filter from the provided measure and condition filter JAQL object
|
|
14
|
+
*
|
|
15
|
+
* @param measure - Provided measure
|
|
16
|
+
* @param conditionFilterJaql - Condition filter JAQL object
|
|
17
|
+
* @returns measure filter
|
|
18
|
+
*/
|
|
19
|
+
export declare const createMeasureFilterFromConditionFilterJaql: (measure: BaseMeasure, conditionFilterJaql: ConditionFilterJaql) => Filter;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { ConditionFilterType } from './types.js';
|
|
2
|
+
import { withComposeCode } from './filter-code-util.js';
|
|
3
|
+
import * as filterFactory from '../factory.js';
|
|
4
|
+
import { createMeasureFromRankingFilterJaql } from './attribute-measure-util.js';
|
|
5
|
+
const isTopCondition = (filter) => filter.top !== undefined;
|
|
6
|
+
const isBottomCondition = (filter) => filter.bottom !== undefined;
|
|
7
|
+
const isExcludeCondition = (filter) => { var _a; return !!((_a = filter.exclude) === null || _a === void 0 ? void 0 : _a.members); };
|
|
8
|
+
const isMembersCondition = (filter) => !!filter.members && !!filter.isCondition;
|
|
9
|
+
const isWithinCondition = (filter) => { var _a, _b; return ((_a = filter.last) === null || _a === void 0 ? void 0 : _a.anchor) !== undefined || ((_b = filter.next) === null || _b === void 0 ? void 0 : _b.anchor) !== undefined; };
|
|
10
|
+
const isGreaterThanCondition = (filter) => filter.fromNotEqual !== undefined;
|
|
11
|
+
const isGreaterThanOrEqualCondition = (filter) => filter.from !== undefined && !filter.isBetween;
|
|
12
|
+
const isLessThanCondition = (filter) => filter.toNotEqual !== undefined;
|
|
13
|
+
const isLessThanOrEqualCondition = (filter) => filter.to !== undefined && !filter.isBetween;
|
|
14
|
+
const isEqualsCondition = (filter) => filter.equals !== undefined;
|
|
15
|
+
const isNotEqualCondition = (filter) => filter.doesntEqual !== undefined;
|
|
16
|
+
const isEmptyCondition = (filter) => !!(filter.equals === '' && filter.isEmpty);
|
|
17
|
+
const isNotEmptyCondition = (filter) => !!(filter.doesntEqual === '' && filter.isEmpty);
|
|
18
|
+
const isContainsCondition = (filter) => filter.contains !== undefined;
|
|
19
|
+
const isDoesntContainCondition = (filter) => filter.doesntContain !== undefined;
|
|
20
|
+
const isStartsWithCondition = (filter) => filter.startsWith !== undefined;
|
|
21
|
+
const isDoesntStartsWithCondition = (filter) => filter.doesntStartWith !== undefined;
|
|
22
|
+
const isEndsWithCondition = (filter) => filter.endsWith !== undefined;
|
|
23
|
+
const isDoesntEndWithCondition = (filter) => filter.doesntEndWith !== undefined;
|
|
24
|
+
const isBetweenCondition = (filter) => filter.from !== undefined && filter.to !== undefined;
|
|
25
|
+
const isNotBetweenCondition = (filter) => { var _a, _b; return ((_a = filter.exclude) === null || _a === void 0 ? void 0 : _a.from) !== undefined && ((_b = filter.exclude) === null || _b === void 0 ? void 0 : _b.to) !== undefined; };
|
|
26
|
+
const isMultipleCondition = (filter) => !!(filter.or || filter.and);
|
|
27
|
+
export const getSelectedConditionOption = (filter) => {
|
|
28
|
+
if (isBottomCondition(filter))
|
|
29
|
+
return ConditionFilterType.BOTTOM;
|
|
30
|
+
if (isTopCondition(filter))
|
|
31
|
+
return ConditionFilterType.TOP;
|
|
32
|
+
if (isExcludeCondition(filter))
|
|
33
|
+
return ConditionFilterType.IS_NOT;
|
|
34
|
+
if (isWithinCondition(filter))
|
|
35
|
+
return ConditionFilterType.IS_WITHIN;
|
|
36
|
+
if (isGreaterThanCondition(filter))
|
|
37
|
+
return ConditionFilterType.GREATER_THAN;
|
|
38
|
+
if (isGreaterThanOrEqualCondition(filter))
|
|
39
|
+
return ConditionFilterType.GREATER_THAN_OR_EQUAL;
|
|
40
|
+
if (isLessThanCondition(filter))
|
|
41
|
+
return ConditionFilterType.LESS_THAN;
|
|
42
|
+
if (isLessThanOrEqualCondition(filter))
|
|
43
|
+
return ConditionFilterType.LESS_THAN_OR_EQUAL;
|
|
44
|
+
if (isEqualsCondition(filter))
|
|
45
|
+
return ConditionFilterType.EQUALS;
|
|
46
|
+
if (isNotEqualCondition(filter))
|
|
47
|
+
return ConditionFilterType.DOESNT_EQUAL;
|
|
48
|
+
if (isEmptyCondition(filter))
|
|
49
|
+
return ConditionFilterType.IS_EMPTY;
|
|
50
|
+
if (isNotEmptyCondition(filter))
|
|
51
|
+
return ConditionFilterType.IS_NOT_EMPTY;
|
|
52
|
+
if (isContainsCondition(filter))
|
|
53
|
+
return ConditionFilterType.CONTAINS;
|
|
54
|
+
if (isDoesntContainCondition(filter))
|
|
55
|
+
return ConditionFilterType.DOESNT_CONTAIN;
|
|
56
|
+
if (isDoesntEndWithCondition(filter))
|
|
57
|
+
return ConditionFilterType.DOESNT_END_WITH;
|
|
58
|
+
if (isDoesntStartsWithCondition(filter))
|
|
59
|
+
return ConditionFilterType.DOESNT_START_WITH;
|
|
60
|
+
if (isEndsWithCondition(filter))
|
|
61
|
+
return ConditionFilterType.ENDS_WITH;
|
|
62
|
+
if (isStartsWithCondition(filter))
|
|
63
|
+
return ConditionFilterType.STARTS_WITH;
|
|
64
|
+
if (isBetweenCondition(filter))
|
|
65
|
+
return ConditionFilterType.BETWEEN;
|
|
66
|
+
if (isNotBetweenCondition(filter))
|
|
67
|
+
return ConditionFilterType.IS_NOT_BETWEEN;
|
|
68
|
+
if (isMembersCondition(filter))
|
|
69
|
+
return ConditionFilterType.IS;
|
|
70
|
+
if (isMultipleCondition(filter))
|
|
71
|
+
return ConditionFilterType.MULTIPLE_CONDITION;
|
|
72
|
+
return ConditionFilterType.NONE;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Creates an attribute filter from the provided attribute and condition filter JAQL object
|
|
76
|
+
*
|
|
77
|
+
* @param attribute - Provided attribute
|
|
78
|
+
* @param conditionFilterJaql - Condition filter JAQL object
|
|
79
|
+
* @returns attribute filter
|
|
80
|
+
*/
|
|
81
|
+
export const createAttributeFilterFromConditionFilterJaql = (attribute, conditionFilterJaql) => {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
const conditionType = getSelectedConditionOption(conditionFilterJaql);
|
|
84
|
+
switch (conditionType) {
|
|
85
|
+
case ConditionFilterType.BOTTOM:
|
|
86
|
+
if (conditionFilterJaql.by && 'agg' in conditionFilterJaql.by) {
|
|
87
|
+
return withComposeCode(filterFactory.bottomRanking)(attribute, createMeasureFromRankingFilterJaql(conditionFilterJaql.by), conditionFilterJaql[ConditionFilterType.BOTTOM]);
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
case ConditionFilterType.EQUALS:
|
|
91
|
+
return withComposeCode(filterFactory.equals)(attribute, conditionFilterJaql[ConditionFilterType.EQUALS]);
|
|
92
|
+
case ConditionFilterType.GREATER_THAN:
|
|
93
|
+
return withComposeCode(filterFactory.greaterThan)(attribute, conditionFilterJaql[ConditionFilterType.GREATER_THAN]);
|
|
94
|
+
case ConditionFilterType.GREATER_THAN_OR_EQUAL:
|
|
95
|
+
return withComposeCode(filterFactory.greaterThanOrEqual)(attribute, conditionFilterJaql[ConditionFilterType.GREATER_THAN_OR_EQUAL]);
|
|
96
|
+
case ConditionFilterType.TOP:
|
|
97
|
+
if (conditionFilterJaql.by) {
|
|
98
|
+
return withComposeCode(filterFactory.topRanking)(attribute, createMeasureFromRankingFilterJaql(conditionFilterJaql.by), conditionFilterJaql[ConditionFilterType.TOP]);
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
case ConditionFilterType.STARTS_WITH:
|
|
102
|
+
return withComposeCode(filterFactory.startsWith)(attribute, conditionFilterJaql[ConditionFilterType.STARTS_WITH]);
|
|
103
|
+
case ConditionFilterType.DOESNT_START_WITH:
|
|
104
|
+
return withComposeCode(filterFactory.doesntStartWith)(attribute, conditionFilterJaql[ConditionFilterType.DOESNT_START_WITH]);
|
|
105
|
+
case ConditionFilterType.ENDS_WITH:
|
|
106
|
+
return withComposeCode(filterFactory.endsWith)(attribute, conditionFilterJaql[ConditionFilterType.ENDS_WITH]);
|
|
107
|
+
case ConditionFilterType.DOESNT_END_WITH:
|
|
108
|
+
return withComposeCode(filterFactory.doesntEndWith)(attribute, conditionFilterJaql[ConditionFilterType.DOESNT_END_WITH]);
|
|
109
|
+
case ConditionFilterType.CONTAINS:
|
|
110
|
+
return withComposeCode(filterFactory.contains)(attribute, conditionFilterJaql[ConditionFilterType.CONTAINS]);
|
|
111
|
+
case ConditionFilterType.DOESNT_CONTAIN:
|
|
112
|
+
return withComposeCode(filterFactory.doesntContain)(attribute, conditionFilterJaql[ConditionFilterType.DOESNT_CONTAIN]);
|
|
113
|
+
case ConditionFilterType.LESS_THAN:
|
|
114
|
+
return withComposeCode(filterFactory.lessThan)(attribute, conditionFilterJaql[ConditionFilterType.LESS_THAN]);
|
|
115
|
+
case ConditionFilterType.LESS_THAN_OR_EQUAL:
|
|
116
|
+
return withComposeCode(filterFactory.lessThanOrEqual)(attribute, conditionFilterJaql[ConditionFilterType.LESS_THAN_OR_EQUAL]);
|
|
117
|
+
case ConditionFilterType.BETWEEN:
|
|
118
|
+
return withComposeCode(filterFactory.between)(attribute, conditionFilterJaql.from, conditionFilterJaql.to);
|
|
119
|
+
case ConditionFilterType.IS_NOT_BETWEEN:
|
|
120
|
+
return withComposeCode(filterFactory.exclude)(withComposeCode(filterFactory.between)(attribute, (_a = conditionFilterJaql.exclude) === null || _a === void 0 ? void 0 : _a.from, (_b = conditionFilterJaql.exclude) === null || _b === void 0 ? void 0 : _b.to));
|
|
121
|
+
case ConditionFilterType.MULTIPLE_CONDITION:
|
|
122
|
+
if (conditionFilterJaql.and) {
|
|
123
|
+
return withComposeCode(filterFactory.intersection)(conditionFilterJaql.and.map((c) => createAttributeFilterFromConditionFilterJaql(attribute, c)));
|
|
124
|
+
}
|
|
125
|
+
if (conditionFilterJaql.or) {
|
|
126
|
+
return withComposeCode(filterFactory.union)(conditionFilterJaql.or.map((c) => createAttributeFilterFromConditionFilterJaql(attribute, c)));
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
case ConditionFilterType.AFTER:
|
|
130
|
+
case ConditionFilterType.BEFORE:
|
|
131
|
+
case ConditionFilterType.IS_EMPTY:
|
|
132
|
+
case ConditionFilterType.IS_NOT_EMPTY:
|
|
133
|
+
// TODO Handle these cases later; may need filterFactory function added first
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
throw 'Jaql contains unsupported condition filter: ' + JSON.stringify(conditionFilterJaql);
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Creates a measure filter from the provided measure and condition filter JAQL object
|
|
140
|
+
*
|
|
141
|
+
* @param measure - Provided measure
|
|
142
|
+
* @param conditionFilterJaql - Condition filter JAQL object
|
|
143
|
+
* @returns measure filter
|
|
144
|
+
*/
|
|
145
|
+
export const createMeasureFilterFromConditionFilterJaql = (measure, conditionFilterJaql) => {
|
|
146
|
+
const conditionType = getSelectedConditionOption(conditionFilterJaql);
|
|
147
|
+
switch (conditionType) {
|
|
148
|
+
case ConditionFilterType.EQUALS:
|
|
149
|
+
return withComposeCode(filterFactory.measureEquals)(measure, conditionFilterJaql[ConditionFilterType.EQUALS]);
|
|
150
|
+
case ConditionFilterType.GREATER_THAN:
|
|
151
|
+
return withComposeCode(filterFactory.measureGreaterThan)(measure, conditionFilterJaql[ConditionFilterType.GREATER_THAN]);
|
|
152
|
+
case ConditionFilterType.GREATER_THAN_OR_EQUAL:
|
|
153
|
+
return withComposeCode(filterFactory.measureGreaterThanOrEqual)(measure, conditionFilterJaql[ConditionFilterType.GREATER_THAN_OR_EQUAL]);
|
|
154
|
+
case ConditionFilterType.LESS_THAN:
|
|
155
|
+
return withComposeCode(filterFactory.measureLessThan)(measure, conditionFilterJaql[ConditionFilterType.LESS_THAN]);
|
|
156
|
+
case ConditionFilterType.LESS_THAN_OR_EQUAL:
|
|
157
|
+
return withComposeCode(filterFactory.measureLessThanOrEqual)(measure, conditionFilterJaql[ConditionFilterType.LESS_THAN_OR_EQUAL]);
|
|
158
|
+
case ConditionFilterType.BETWEEN:
|
|
159
|
+
return withComposeCode(filterFactory.measureBetween)(measure, conditionFilterJaql.from, conditionFilterJaql.to);
|
|
160
|
+
}
|
|
161
|
+
throw 'Jaql contains unsupported condition filter: ' + JSON.stringify(conditionFilterJaql);
|
|
162
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stringifies the argument
|
|
3
|
+
*
|
|
4
|
+
* @param arg - argument to stringify
|
|
5
|
+
* @returns stringified argument
|
|
6
|
+
*/
|
|
7
|
+
export declare function stringifyHelper(arg: any): string;
|
|
8
|
+
/**
|
|
9
|
+
* High order function to construct compose code for filter factory functions
|
|
10
|
+
*
|
|
11
|
+
* @param func - filter factory function
|
|
12
|
+
*/
|
|
13
|
+
export declare function withComposeCode(func: (...args: any[]) => any): (...args: any[]) => any;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stringifies the argument
|
|
3
|
+
*
|
|
4
|
+
* @param arg - argument to stringify
|
|
5
|
+
* @returns stringified argument
|
|
6
|
+
*/
|
|
7
|
+
export function stringifyHelper(arg) {
|
|
8
|
+
try {
|
|
9
|
+
if (arg === null || arg === undefined) {
|
|
10
|
+
return JSON.stringify(arg);
|
|
11
|
+
}
|
|
12
|
+
if (arg === Object(arg) && 'composeCode' in arg) {
|
|
13
|
+
return arg.composeCode;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(arg)) {
|
|
16
|
+
return ('[' +
|
|
17
|
+
arg
|
|
18
|
+
.map((e) => {
|
|
19
|
+
return stringifyHelper(e);
|
|
20
|
+
})
|
|
21
|
+
.join(', ') +
|
|
22
|
+
']');
|
|
23
|
+
}
|
|
24
|
+
if (typeof arg === 'string') {
|
|
25
|
+
return `'${arg}'`;
|
|
26
|
+
}
|
|
27
|
+
if (typeof arg === 'number' || !isNaN(arg)) {
|
|
28
|
+
return arg;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
console.error(e);
|
|
33
|
+
}
|
|
34
|
+
return JSON.stringify(arg);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* High order function to construct compose code for filter factory functions
|
|
38
|
+
*
|
|
39
|
+
* @param func - filter factory function
|
|
40
|
+
*/
|
|
41
|
+
export function withComposeCode(func) {
|
|
42
|
+
return function (...args) {
|
|
43
|
+
const argValues = args.map(stringifyHelper).join(', ');
|
|
44
|
+
const signature = `filterFactory.${func.name}(${argValues})`;
|
|
45
|
+
const filter = func(...args);
|
|
46
|
+
filter.composeCode = signature;
|
|
47
|
+
return filter;
|
|
48
|
+
};
|
|
49
|
+
}
|