@emartech/data-aggregator-language
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -29,3 +29,3 @@ { | ||
}, | ||
"version": "2.1.1" | ||
"version": "2.2.0" | ||
} |
@@ -8,3 +8,3 @@ # Data Aggregator Language | ||
```js | ||
const input = [{ | ||
const input = [{ | ||
date: '2017-09-16', | ||
@@ -14,3 +14,4 @@ reservations: { | ||
gold: 5 | ||
} | ||
}, | ||
customers: ['brad'] | ||
}, { | ||
@@ -21,3 +22,4 @@ date: '2017-09-17', | ||
gold: 2 | ||
} | ||
}, | ||
customers: ['angelina'] | ||
}] | ||
@@ -39,4 +41,5 @@ ``` | ||
Examples below are for the `input` defined above. | ||
### Constants | ||
* LENGTH | ||
* LENGTH | ||
* `LENGTH` (yields 2) | ||
@@ -57,5 +60,9 @@ * `LENGTH + 3` (yields 5) | ||
+, -, *, / | ||
For example, `(LAST reservations.silver + 3) * 2 / 2` (yields 6) | ||
### Set Operators | ||
Set Operators may not be mixed with any of the other operators. | ||
* UNION | ||
* `UNION customers` (yields ['brad', 'angelina']) | ||
## Using with Webpack | ||
@@ -62,0 +69,0 @@ Because of the [way the underlying Chevrotain library is implemented](https://github.com/SAP/chevrotain/blob/master/examples/parser/minification/README.md), name mangling |
@@ -11,3 +11,3 @@ 'use strict'; | ||
parser.input = lexer.tokenize(text).tokens; | ||
const cst = parser.additionExpression(); | ||
const cst = parser.expression(); | ||
const value = interpreter.visit(cst); | ||
@@ -14,0 +14,0 @@ |
@@ -10,4 +10,12 @@ 'use strict'; | ||
aggregate = subject([ | ||
{ date: '2017-08-15', campaigns: { email: { open: 3 }, values_for_test: [4, 10, 2] } }, | ||
{ date: '2017-08-16', campaigns: { email: { open: 4 }, values_for_test: [2, 9] } } | ||
{ | ||
date: '2017-08-15', | ||
campaigns: { email: { open: 3 }, values_for_test: [4, 10, 2] }, | ||
programs: { ids: ['1', '2'] } | ||
}, | ||
{ | ||
date: '2017-08-16', | ||
campaigns: { email: { open: 4 }, values_for_test: [2, 9] }, | ||
programs: { ids: ['2', '3', '4'] } | ||
} | ||
]); | ||
@@ -138,2 +146,9 @@ }); | ||
describe('Set Operators', () => { | ||
describe('Union Operator', () => { | ||
it('exists', () => { | ||
expect(aggregate('UNION programs.ids')).to.deep.eql(['1', '2', '3', '4']); | ||
}); | ||
}); | ||
}); | ||
@@ -140,0 +155,0 @@ describe('when there is a parsing error', () => { |
@@ -19,2 +19,14 @@ 'use strict'; | ||
expression(ctx) { | ||
return this.visit(ctx.expression); | ||
} | ||
setOperationExpression(ctx) { | ||
return this.visit(ctx.expression); | ||
} | ||
unionExpression(ctx) { | ||
return this._period.union(this.visit(ctx.stringExpression)); | ||
} | ||
additionExpression(ctx) { | ||
@@ -21,0 +33,0 @@ return this.visit(ctx.lhs) + this._accumulateAdditiveRhs(ctx.rhs); |
@@ -14,2 +14,3 @@ 'use strict'; | ||
averageOperator, | ||
unionOperator, | ||
lengthConstant, | ||
@@ -33,2 +34,18 @@ plusOperator, | ||
$.RULE('expression', () => { | ||
$.OR([ | ||
{ ALT: () => $.SUBRULE($.additionExpression, { LABEL: 'expression' }) }, | ||
{ ALT: () => $.SUBRULE($.setOperationExpression, { LABEL: 'expression' }) } | ||
]); | ||
}); | ||
$.RULE('setOperationExpression', () => { | ||
$.SUBRULE($.unionExpression, { LABEL: 'expression' }); | ||
}); | ||
$.RULE('unionExpression', () => { | ||
$.CONSUME(unionOperator); | ||
$.SUBRULE($.stringExpression); | ||
}); | ||
$.RULE('additionExpression', () => { | ||
@@ -35,0 +52,0 @@ $.SUBRULE($.minusExpression, { LABEL: 'lhs' }); |
@@ -25,2 +25,7 @@ 'use strict'; | ||
const unionOperator = createToken({ | ||
name: 'unionOperator', | ||
pattern: /UNION/ | ||
}); | ||
const plusOperator = createToken({ | ||
@@ -77,2 +82,3 @@ name: 'plusOperator', | ||
averageOperator, | ||
unionOperator, | ||
lengthConstant, | ||
@@ -79,0 +85,0 @@ plusOperator, |
@@ -11,3 +11,2 @@ 'use strict'; | ||
get lastDay() { | ||
@@ -17,3 +16,2 @@ return this._data.last(); | ||
sum(propertyName) { | ||
@@ -23,3 +21,2 @@ return this._data.sumBy(propertyName); | ||
average(propertyName) { | ||
@@ -30,3 +27,2 @@ let values = this._data.map(propertyName).compact(); | ||
last(properytName) { | ||
@@ -39,3 +35,2 @@ return this._data | ||
every(propertyName) { | ||
@@ -49,2 +44,5 @@ return this._data.map(propertyName).compact().value(); | ||
union(propertyName) { | ||
return this._data.map(propertyName).flatten().uniq().value(); | ||
} | ||
@@ -55,3 +53,2 @@ get empty() { | ||
get emptyLastDay() { | ||
@@ -58,0 +55,0 @@ return !this._data.last(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23610
20
557
93