Issue #30: Remove ChildView references

Signed-off-by: Lucas Fernandes de Oliveira's avatarLucas Fernandes de Oliveira <lfo14@inf.ufpr.br>
parent 2b5d97fa
Pipeline #11227 passed with stage
in 44 seconds
...@@ -125,7 +125,7 @@ export class PostgresAdapter extends Adapter { ...@@ -125,7 +125,7 @@ export class PostgresAdapter extends Adapter {
} }
else { else {
let children = view.childViews.map((item) => item.view); let children = view.childViews;
for (let i = 0; i < children.length; ++i) { for (let i = 0; i < children.length; ++i) {
r = r.concat(this.searchMaterializedViews(children[i])); r = r.concat(this.searchMaterializedViews(children[i]));
} }
......
...@@ -137,10 +137,10 @@ describe("engine class", () => { ...@@ -137,10 +137,10 @@ describe("engine class", () => {
expect(optimalView.childViews).to.have.length(1); expect(optimalView.childViews).to.have.length(1);
expect(optimalView).satisfy((optView: View) => { expect(optimalView).satisfy((optView: View) => {
return optView.childViews[0].dimensions.some((item) => item.name === subdim[0].name); return optView.dimensions.some((item) => item.name === subdim[0].name);
}); });
expect(optimalView).satisfy((optView: View) => { expect(optimalView).satisfy((optView: View) => {
return optView.childViews[0].dimensions.some((item) => item.name === subdim[1].name); return optView.dimensions.some((item) => item.name === subdim[1].name);
}); });
}); });
...@@ -163,10 +163,10 @@ describe("engine class", () => { ...@@ -163,10 +163,10 @@ describe("engine class", () => {
expect(optimalView.childViews).to.have.length(1); expect(optimalView.childViews).to.have.length(1);
expect(optimalView).satisfy((optView: View) => { expect(optimalView).satisfy((optView: View) => {
return optView.childViews[0].dimensions.some((item) => item.name === subdim[2].name); return optView.dimensions.some((item) => item.name === subdim[2].name);
}); });
expect(optimalView).satisfy((optView: View) => { expect(optimalView).satisfy((optView: View) => {
return optView.childViews[0].dimensions.some((item) => item.name === subdim[4].name); return optView.dimensions.some((item) => item.name === subdim[4].name);
}); });
}); });
......
...@@ -101,11 +101,11 @@ export class Engine { ...@@ -101,11 +101,11 @@ export class Engine {
// If all the metrics and dimensions are the same and only exist one child view // If all the metrics and dimensions are the same and only exist one child view
// return this single child view // return this single child view
if (optimalViews.length === 1 && if (optimalViews.length === 1 &&
optimalViews[0].view.metrics.length === q.metrics.length && optimalViews[0].metrics.length === q.metrics.length &&
optimalViews[0].view.dimensions.length === q.dimensions.length && optimalViews[0].dimensions.length === q.dimensions.length &&
optimalViews[0].view.metrics.every((item) => q.metrics.indexOf(item) !== -1) && optimalViews[0].metrics.every((item) => q.metrics.indexOf(item) !== -1) &&
optimalViews[0].view.dimensions.every((item) => q.dimensions.indexOf(item) !== -1)) { optimalViews[0].dimensions.every((item) => q.dimensions.indexOf(item) !== -1)) {
return optimalViews[0].view; return optimalViews[0];
} }
else { else {
let options = { let options = {
......
...@@ -27,18 +27,12 @@ export interface LoadView { ...@@ -27,18 +27,12 @@ export interface LoadView {
data: string; data: string;
} }
export interface ChildView {
metrics: Metric[];
dimensions: Dimension[];
view: View;
}
export interface ViewOptions { export interface ViewOptions {
metrics: Metric[]; metrics: Metric[];
dimensions: Dimension[]; dimensions: Dimension[];
origin: boolean; origin: boolean;
materialized?: boolean; materialized?: boolean;
childViews?: ChildView[]; childViews?: View[];
} }
export class View { export class View {
...@@ -47,7 +41,7 @@ export class View { ...@@ -47,7 +41,7 @@ export class View {
public readonly dimensions: Dimension[]; public readonly dimensions: Dimension[];
public readonly materialized: boolean; public readonly materialized: boolean;
public readonly origin: boolean; public readonly origin: boolean;
public childViews: ChildView[]; public childViews: View[];
constructor (options: ViewOptions) { constructor (options: ViewOptions) {
this.metrics = options.metrics.sort(); this.metrics = options.metrics.sort();
......
...@@ -200,7 +200,7 @@ describe("graph class", () => { ...@@ -200,7 +200,7 @@ describe("graph class", () => {
let children = g.cover([], [dim]); let children = g.cover([], [dim]);
expect(children).to.be.an("array"); expect(children).to.be.an("array");
expect(children).to.have.length(1); expect(children).to.have.length(1);
expect(children[0].view.id).to.be.equal(view.id); expect(children[0].id).to.be.equal(view.id);
}); });
it("should create a cover for several vertices", () => { it("should create a cover for several vertices", () => {
...@@ -269,7 +269,7 @@ describe("graph class", () => { ...@@ -269,7 +269,7 @@ describe("graph class", () => {
let children = g.cover([mets[0], mets[1]], [dims[0], dims[1]]); let children = g.cover([mets[0], mets[1]], [dims[0], dims[1]]);
expect(children).to.be.an("array"); expect(children).to.be.an("array");
expect(children).to.have.length(1); expect(children).to.have.length(1);
expect(children[0].view.id).to.be.equal(views[views.length - 1].id); expect(children[0].id).to.be.equal(views[views.length - 1].id);
}); });
it("should create a cover with sub dimensions", () => { it("should create a cover with sub dimensions", () => {
...@@ -308,7 +308,7 @@ describe("graph class", () => { ...@@ -308,7 +308,7 @@ describe("graph class", () => {
let children = g.cover([], [dims[1], dims[2]]); let children = g.cover([], [dims[1], dims[2]]);
expect(children).to.be.an("array"); expect(children).to.be.an("array");
expect(children).to.have.length(1); expect(children).to.have.length(1);
expect(children[0].view.id).to.be.equal(view.id); expect(children[0].id).to.be.equal(view.id);
}); });
it("should return empty when try to cover a empty list", () => { it("should return empty when try to cover a empty list", () => {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* along with blendb. If not, see <http://www.gnu.org/licenses/>. * along with blendb. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { View, ChildView } from "../core/view"; import { View } from "../core/view";
import { Metric } from "../core/metric"; import { Metric } from "../core/metric";
import { Dimension } from "../core/dimension"; import { Dimension } from "../core/dimension";
...@@ -300,13 +300,13 @@ export class Graph { ...@@ -300,13 +300,13 @@ export class Graph {
/* /*
Given a list of metrics and dimensions returns a set Given a list of metrics and dimensions returns a set
of ChildViews that can be used to create a query that of Views (children) that can be used to create a query that
returns the data asked. returns the data asked.
If this set cannot be created, throws a error If this set cannot be created, throws a error
*/ */
public cover(metrics: Metric[], dimensions: Dimension[]): ChildView[] { public cover(metrics: Metric[], dimensions: Dimension[]): View[] {
let output: ChildView[] = []; let output: View[] = [];
let verticesIds = metrics.map((met) => met.name); let verticesIds = metrics.map((met) => met.name);
verticesIds = verticesIds.concat(dimensions.map((dim) => dim.name)); verticesIds = verticesIds.concat(dimensions.map((dim) => dim.name));
for (let i = 0; i < this.vertices.length; ++i) { for (let i = 0; i < this.vertices.length; ++i) {
...@@ -374,7 +374,7 @@ export class Graph { ...@@ -374,7 +374,7 @@ export class Graph {
return edge.isView; return edge.isView;
}).map((edge) => edge.view); }).map((edge) => edge.view);
// Check if there is a intersection between output and options // Check if there is a intersection between output and options
if (output.some((child) => options.some((view) => child.view === view))) { if (output.some((child) => options.some((view) => child === view))) {
// If there is a intersection, does not pick any new view // If there is a intersection, does not pick any new view
v = v.parent; v = v.parent;
continue; continue;
...@@ -414,7 +414,7 @@ export class Graph { ...@@ -414,7 +414,7 @@ export class Graph {
} }
// Check if some of its views were picked // Check if some of its views were picked
if (output.some((child) => views.some((view) => child.view === view))) { if (output.some((child) => views.some((view) => child === view))) {
// If yes, do nothing and return the actual set // If yes, do nothing and return the actual set
return output; return output;
} }
...@@ -431,12 +431,12 @@ export class Graph { ...@@ -431,12 +431,12 @@ export class Graph {
/* /*
From a edge, coohse the best view, based on the metric and dimensions From a edge, coohse the best view, based on the metric and dimensions
that are not cover yet, return a childView. that are not cover yet, return a View.
The algorithm chooses the view that covers more metrics and dimensions The algorithm chooses the view that covers more metrics and dimensions
that are not covered yet, if there is a tie chooses the one with that are not covered yet, if there is a tie chooses the one with
less dimensions, if tie again, the earliest in the list. less dimensions, if tie again, the earliest in the list.
*/ */
private pickEdge (views: View[], metToCover: Metric[], dimToCover: Dimension[]): ChildView { private pickEdge (views: View[], metToCover: Metric[], dimToCover: Dimension[]): View {
// Picks the first option as the best one until now // Picks the first option as the best one until now
let bestView = views[0]; let bestView = views[0];
let bestCoverMet = metToCover.filter((met) => { let bestCoverMet = metToCover.filter((met) => {
...@@ -483,12 +483,7 @@ export class Graph { ...@@ -483,12 +483,7 @@ export class Graph {
} }
} }
return { return bestView;
view: bestView,
metrics: bestCoverMet,
dimensions: bestCoverDim
};
} }
} }
...@@ -130,11 +130,7 @@ const dateView = new View({ ...@@ -130,11 +130,7 @@ const dateView = new View({
dimensions: dateSubDim, dimensions: dateSubDim,
materialized: false, materialized: false,
origin: false, origin: false,
childViews: [{ childViews: [views[0]]
view: views[0],
metrics: [],
dimensions: [dims[0]]
}]
}); });
const aggrView = new View({ const aggrView = new View({
...@@ -142,23 +138,7 @@ const aggrView = new View({ ...@@ -142,23 +138,7 @@ const aggrView = new View({
dimensions: [], dimensions: [],
materialized: false, materialized: false,
origin: false, origin: false,
childViews: [ childViews: [views[0], views[2], views[4]]
{
view: views[0],
metrics: [mets[0], mets[1]],
dimensions: []
},
{
view: views[2],
metrics: [mets[6]],
dimensions: []
},
{
view: views[4],
metrics: [],
dimensions: []
}
]
}); });
const subDimView = new View({ const subDimView = new View({
...@@ -166,23 +146,7 @@ const subDimView = new View({ ...@@ -166,23 +146,7 @@ const subDimView = new View({
dimensions: [subdims[0], subdims[1], dims[7], dims[8]], dimensions: [subdims[0], subdims[1], dims[7], dims[8]],
materialized: false, materialized: false,
origin: false, origin: false,
childViews: [ childViews: [views[0], views[1], views[4]]
{
view: views[0],
metrics: [mets[0]],
dimensions: [dims[0], dims[7]]
},
{
view: views[1],
metrics: [],
dimensions: [dims[1], dims[8]]
},
{
view: views[4],
metrics: [],
dimensions: []
}
]
}); });
const join4View = new View({ const join4View = new View({
...@@ -190,28 +154,7 @@ const join4View = new View({ ...@@ -190,28 +154,7 @@ const join4View = new View({
dimensions: [dims[2], dims[7], dims[8]], dimensions: [dims[2], dims[7], dims[8]],
materialized: false, materialized: false,
origin: false, origin: false,
childViews: [ childViews: [views[0], views[1], views[2], views[4]]
{
view: views[0],
metrics: [mets[0], mets[1], mets[2]],
dimensions: [dims[7]]
},
{
view: views[1],
metrics: [mets[3], mets[4]],
dimensions: [dims[8]]
},
{
view: views[2],
metrics: [mets[5], mets[6]],
dimensions: [dims[2]]
},
{
view: views[4],
metrics: [],
dimensions: []
}
]
}); });
const noSelView = new View({ const noSelView = new View({
...@@ -219,18 +162,7 @@ const noSelView = new View({ ...@@ -219,18 +162,7 @@ const noSelView = new View({
dimensions: [], dimensions: [],
materialized: false, materialized: false,
origin: false, origin: false,
childViews: [ childViews: [views[0], views[1]]
{
view: views[0],
metrics: [mets[0]],
dimensions: []
},
{
view: views[1],
metrics: [mets[3]],
dimensions: []
}
]
}); });
const withSelView = new View({ const withSelView = new View({
...@@ -238,18 +170,7 @@ const withSelView = new View({ ...@@ -238,18 +170,7 @@ const withSelView = new View({
dimensions: [dims[7], dims[8]], dimensions: [dims[7], dims[8]],
materialized: false, materialized: false,
origin: false, origin: false,
childViews: [ childViews: [views[0], views[4]]
{
view: views[0],
metrics: [mets[0], mets[1]],
dimensions: [dims[7]]
},
{
view: views[4],
metrics: [],
dimensions: [dims[7], dims[8]]
}
]
}); });
export const engineScenario: EngineScenario = { export const engineScenario: EngineScenario = {
......
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