Issue #34: Remove unrelated filters from query

Signed-off-by: Lucas Fernandes de Oliveira's avatarLucas Fernandes de Oliveira <lfo14@inf.ufpr.br>
parent 0b0369aa
Pipeline #11302 passed with stage
in 42 seconds
......@@ -279,4 +279,23 @@ describe("postgres adapter", () => {
done();
});
});
it("should get data when a filter does not have any effect on the query", (done) => {
let view = adapterScenario.notMatchFilterView;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
});
});
......@@ -179,7 +179,12 @@ export class PostgresAdapter extends Adapter {
return clause.id === item.id;
}));
toCover.forEach((item) => conds.push("(" + this.translateClause(item, nameMap) + ")"));
toCover.forEach((item) => {
const clause = "(" + this.translateClause(item, nameMap) + ")";
if (clause !== "()") {
conds.push(clause);
}
});
// Assembly
......@@ -249,11 +254,19 @@ export class PostgresAdapter extends Adapter {
}
private translateClause(clause: Clause, map: {[key: string]: View}): string {
let r = clause.filters.map((item) => this.translateFilter(item, map));
const r = clause.filters.map((item) => {
return this.translateFilter(item, map);
}).filter((item) => {
return item !== "";
});
return r.join(" OR ");
}
private translateFilter(filter: Filter, map: {[key: string]: View}): string {
if (!map[filter.target.name]) {
return "";
}
const viewId = map[filter.target.name].id;
const leftSide = this.buildColumn(filter.target, viewId);
const op = this.translateOperator(filter.operator);
......
......@@ -50,6 +50,7 @@ interface AdapterScenario {
notEqualView: View;
gtltView: View;
geleView: View;
notMatchFilterView: View;
}
interface DataCtrlScenario {
......@@ -257,6 +258,15 @@ const geleView = new View({
clauses: [clauses.view0ge, clauses.view0le]
});
const notMatchFilterView = new View({
metrics: [mets[0]],
dimensions: [dims[0]],
materialized: false,
origin: false,
childViews: [views[0]],
clauses: [clauses.view7dim5]
});
const subDimView = new View({
metrics: [mets[0]],
dimensions: [subdims[0], subdims[1], dims[7], dims[8]],
......@@ -311,7 +321,8 @@ export const adapterScenario: AdapterScenario = {
multiClauseView: multiClauseView,
notEqualView: notEqualView,
gtltView: gtltView,
geleView: geleView
geleView: geleView,
notMatchFilterView: notMatchFilterView
};
export const dataCtrlScenario: DataCtrlScenario = {
......
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