Commit 0ce1a94d authored by Felipe Wu's avatar Felipe Wu

[006] sort, datatype finalizado

Signed-off-by: 's avatarFelipe Wu <felipeshiwu@gmail.com>
parent 53427b55
Pipeline #20110 failed with stages
in 33 seconds
import { View } from "../core/view";
import { Source } from "../core/source";
import { FilterOperator } from "../core/filter";
import { Metric } from "../core/metric";
import { Adapter } from "../core/adapter";
import { DataType, AggregationType } from "../common/types";
import { Client, ConfigOptions } from "elasticsearch";
......@@ -70,10 +71,10 @@ export class ElasticsearchAdapter extends Adapter {
*/
public getDataFromView(view: View, cb: (error: Error, result?: any[]) => void): void {
const query = this.getQueryFromView(view);
if (view.clauses.length == 0 || view.dimensions.length > 1) {
this.executeQuery(view.operation.values[0].name, query, cb);
} else {
if (view.clauses.length > 0 || view.dimensions.length == 1) {
this.executeQuery(view.operation.values[0].operation.values[0].name, query, cb);
} else {
this.executeQuery(view.operation.values[0].name, query, cb);
}
}
......@@ -129,7 +130,7 @@ export class ElasticsearchAdapter extends Adapter {
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();
aggrName = view.metrics[i].name.toLowerCase();
Object.assign(partialQuery, { [aggrName]: {[func]: {field: view.metrics[i].name}}});
}
return partialQuery;
......@@ -137,18 +138,29 @@ export class ElasticsearchAdapter extends Adapter {
let returnedQuery = this.translateAggs(view, numDimensions+1);
if (view.dimensions.length > 0) {
let group_by = "group_by_" + view.dimensions[numDimensions].name;
let aggregation = {
[group_by]: {
terms: {
field: view.dimensions[numDimensions].name + ".keyword",
size: 100000
},
aggs: {}
let group_by = "group_by_" + view.dimensions[numDimensions].name;
let dim = view.dimensions[numDimensions].name;
if (view.dimensions[numDimensions].dataType < 3) {
dim = dim;
} else {
dim = dim + ".keyword";
}
let aggregation = {
[group_by]: {
terms: {
field: dim,
size: 100000
},
aggs: {}
}
};
Object.assign(aggregation[group_by], {aggs: returnedQuery});
if (numDimensions == view.dimensions.length - 1 && view.sort.length > 0) {
let aggrName = view.sort[0].name.toLowerCase();
Object.assign(aggregation[group_by].terms, {order: {[aggrName] : "asc"}});
}
};
Object.assign(aggregation[group_by], {aggs: returnedQuery});
return 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