Commit c39d572d authored by Felipe Wu's avatar Felipe Wu

[004] split functions aggr

Signed-off-by: 's avatarFelipe Wu <felipeshiwu@gmail.com>
parent 640217ea
Pipeline #20091 failed with stages
in 28 seconds
......@@ -40,16 +40,16 @@ export class ElasticsearchAdapter extends Adapter {
}
};
let filter = {"match": { [view.clauses[0].filters[0].target.name]: view.clauses[0].filters[0].value }};
let filter = {};
let match = [];
match.push(filter);
/** Query is used to define the filters */
for(let i=1;i<view.clauses[0].filters.length; i++) {
filter = {"match": { [view.clauses[0].filters[i].target.name]: view.clauses[0].filters[i].value }};
match.push(filter);
}
Object.assign(query.query.bool, {must: match});
//console.log(JSON.stringify(initial));
/** Query is used to define the filters */
if (view.clauses.length > 0) {
for(let i=0;i<view.clauses[0].filters.length; i++) {
filter = {"match": { [view.clauses[0].filters[i].target.name]: view.clauses[0].filters[i].value }};
match.push(filter);
}
Object.assign(query.query.bool, {must: match});
}
/** Aggregation is used to define the dimention and the aggregation */
const func = this.getAggregateFunction(view.metrics[0].aggregation, view.origin);
......@@ -159,7 +159,7 @@ export class ElasticsearchAdapter extends Adapter {
public insertIntoSource(source: Source, data: any[], cb: (err: Error, result?: any[]) => void): void {
}
private getAggregateFunction(aggrType: AggregationType, origin: boolean): string {
private getAggregateFunction(aggrType: AggregationType): string {
switch (aggrType) {
case AggregationType.SUM:
return "sum";
......@@ -176,4 +176,38 @@ export class ElasticsearchAdapter extends Adapter {
}
}
private translateAggs(view: View, query: object,
numDimensions: number): object {
if (numDimensions == view.dimensions.length) {
let func = "";
let aggrName = "";
let partialQuery = {};
for (let i=0; i<view.metrics.length; i++) {
func = this.getAggregateFunction(view.metrics[i].aggregation);
aggrName = func + "_" + view.metrics[i].name.toLowerCase();
Object.assign(partialQuery, { [aggrName]: {[func]: {field: view.metrics[i].name}}});
}
return partialQuery;
}
let group_by = "group_by_" + view.dimensions[numDimensions].name;
let aggregation = {
[group_by]: {
terms: {
field: view.dimensions[0].name + ".keyword",
size: 10000
},
aggs: {}
}
};
let aggregate =
for (let i=0; i<view.dimensions.length; i++) {
Object.assign(aggregation.[group_by].aggs, {[aggrName]: {[func]: {field: view.metrics[0].name}}});
Object.assign(query, {aggs: aggregation});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment