Commit c070f7f8 authored by Felipe Wu's avatar Felipe Wu

[002] update adapter

Signed-off-by: 's avatarFelipe Wu <felipeshiwu@gmail.com>
parent e19e3210
Pipeline #20089 failed with stages
in 35 seconds
......@@ -8,10 +8,6 @@ import { Client, ConfigOptions } from "elasticsearch";
/** @hidden */
const elasticsearch = require('elasticsearch');
/**
* Adapter which connects with a Elasticsearch database.
*/
......@@ -37,7 +33,7 @@ export class ElasticsearchAdapter extends Adapter {
*/
/** A Elasticsearch query is JSON format, the header always begin with size:0 */
let initial = {
let query = {
size: 0,
query: {
bool: {}
......@@ -48,16 +44,16 @@ export class ElasticsearchAdapter extends Adapter {
let filter = {"match": { "TP_SEXO": "2" }};
let match = [];
match.push(filter);
Object.assign(initial.query.bool, {must: match});
Object.assign(query.query.bool, {must: match});
//console.log(JSON.stringify(initial));
console.log(JSON.stringify(view));
console.log(JSON.stringify(view, null, 2));
/** Aggregation is used to define the dimention and the aggregation */
let aggregation = {
group_by_estado: {
terms: {
field: "CO_UF_NASC.keyword",
size: 1000,
size: 10000,
order: {
average_idade: "asc"
}
......@@ -69,10 +65,10 @@ export class ElasticsearchAdapter extends Adapter {
}
};
Object.assign(initial, {aggs: aggregation});
Object.assign(query, {aggs: aggregation});
return initial;
return query;
}
/**
......@@ -85,11 +81,8 @@ export class ElasticsearchAdapter extends Adapter {
*/
public getDataFromView(view: View, cb: (error: Error, result?: any[]) => void): void {
const query = this.getQueryFromView(view);
//console.log(JSON.stringify(query));
//console.log(JSON.stringify(view));
//cb(null, []);
//this.executeQuery(query, cb);
this.teste(query, cb);
this.executeQuery(query, cb);
//this.executeFixQuery(query, cb);
}
/**
......@@ -99,7 +92,7 @@ export class ElasticsearchAdapter extends Adapter {
* @param cb.error - Error information when the method fails.
* @param cb.result - Query result.
*/
private teste(query: object, cb: (error: Error, result?: any[]) => void): void {
private executeQuery(query: object, cb: (error: Error, result?: any[]) => void): void {
this.client.search({
index: 'teste',
body: query
......@@ -109,7 +102,7 @@ export class ElasticsearchAdapter extends Adapter {
})
}
private executeQuery(query: object, cb: (error: Error, result?: any[]) => void): void {
private executeFixQuery(query: object, cb: (error: Error, result?: any[]) => void): void {
this.client.search({
index: 'teste',
body: {
......@@ -125,7 +118,7 @@ export class ElasticsearchAdapter extends Adapter {
"group_by_estado": {
"terms": {
"field": "CO_UF_NASC.keyword",
"size": 1000,
"size": 10000,
"order": {
"average_idade": "asc"
}
......@@ -149,60 +142,14 @@ export class ElasticsearchAdapter extends Adapter {
cb(err, [result]);
})
}
/**
/**
* Asynchronously insert one register into a given Source.
* @param source - Insertion "location".
* @param cb - Callback function which contains the query result.
* @param cb.error - Error information when the method fails.
* @param cb.result - Query result.
*/
public insertIntoSource(source: Source, data: any[], cb: (err: Error, result: any[]) => void): void {
// const query = this.getQueryFromSource(source, data);
const query = {};
this.executeQuery(query, cb);
}
/**
* Cast BlenDB data types to be used in MonetDB queries.
* @param quotedValue - SQL query attribute wrapped by quotes.
* @param dt - Attribute data type.
*/
/*protected typeCast(quotedValue: string, dt: DataType): string {
switch (dt) {
case DataType.DATE:
return "CAST(" + quotedValue + " AS TIMESTAMP)";
case DataType.INTEGER:
return "CAST(" + quotedValue + " AS INTEGER)";
case DataType.BOOLEAN:
return "CAST(" + quotedValue + " AS BOOLEAN)";
default:
return quotedValue;
}
public insertIntoSource(source: Source, data: any[], cb: (err: Error, result?: any[]) => void): void {
}
/**
* Translate filter operator to be used in MonetDB queries.
* @param lSide - Operation left side operator.
* @param rSide - Operation right side operator.
* @param op - Operation to be performed.
*/
/*protected applyOperator(lSide: string, rSide: string, op: FilterOperator): string {
switch (op) {
case FilterOperator.EQUAL:
return lSide + " = " + rSide;
case FilterOperator.NOTEQUAL:
return "NOT(" + lSide + " = " + rSide + ")";
case FilterOperator.GREATER:
return lSide + " > " + rSide;
case FilterOperator.LOWER:
return lSide + " < " + rSide;
case FilterOperator.GREATEREQ:
return lSide + " >= " + rSide;
case FilterOperator.LOWEREQ:
return lSide + " <= " + rSide;
default:
return "";
}
}*/
}
......@@ -64,7 +64,7 @@ else if (config.adapters[0] === "monet") {
app.use(MonetMw(config.connections[0]));
}
else if (config.adpters[0] === "elasticsearch") {
else if (config.adapters[0] === "elasticsearch") {
app.use(ElasticsearchMw(config.connections[0]));
}
......
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