Skip to content
Snippets Groups Projects
Commit a3bf602b authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira
Browse files

Merge branch 'issue/94' into 'develop'

Issue #94: Update view join algorithm

See merge request !82
parents d2c88631 73cd631e
No related branches found
No related tags found
1 merge request!82Issue #94: Update view join algorithm
Pipeline #18972 passed
...@@ -116,7 +116,7 @@ export class ViewHandler { ...@@ -116,7 +116,7 @@ export class ViewHandler {
partialJoin = views.map((i) => (i)); partialJoin = views.map((i) => (i));
if (q.metrics.length === 0) { // ignore metView if there are 0 metrics if (q.metrics.length === 0) { // ignore metView if there are 0 metrics
while (partialJoin.length > 1) { if (partialJoin.length > 0) {
qOpt = {metrics: partialQuery.metrics, dimensions: partialQuery.dimensions, clauses: clausesToCover}; qOpt = {metrics: partialQuery.metrics, dimensions: partialQuery.dimensions, clauses: clausesToCover};
partialQuery = new Query(qOpt); partialQuery = new Query(qOpt);
reduced = ViewHandler.applyReduce(partialJoin, partialQuery); reduced = ViewHandler.applyReduce(partialJoin, partialQuery);
...@@ -134,7 +134,7 @@ export class ViewHandler { ...@@ -134,7 +134,7 @@ export class ViewHandler {
metView = partialJoin[metViewId]; metView = partialJoin[metViewId];
partialJoin.splice(metViewId, 1); partialJoin.splice(metViewId, 1);
while (partialJoin.length > 1) { if (partialJoin.length > 0) {
partialJoin.push(metView); // MetView is now the last view partialJoin.push(metView); // MetView is now the last view
qOpt = {metrics: partialQuery.metrics, dimensions: partialQuery.dimensions, clauses: clausesToCover}; qOpt = {metrics: partialQuery.metrics, dimensions: partialQuery.dimensions, clauses: clausesToCover};
partialQuery = new Query(qOpt); partialQuery = new Query(qOpt);
...@@ -309,76 +309,33 @@ export class ViewHandler { ...@@ -309,76 +309,33 @@ export class ViewHandler {
} }
/** /**
* Finds the pair of views most realted in a set of views and * Apply JOIN operation in a set of views.
* applies the JOIN operation in this set. * Returns a set with the joined view.
* Returns a set with the joined view and without the most
* related view.
* @param v - Set of candidated views to be joined. * @param v - Set of candidated views to be joined.
*/ */
private static applyJoin(v: View[]): View[] { private static applyJoin(v: View[]): View[] {
/*
At this point 2 views will be joined, first the
similarity with each pair of views is calculated,
the pair with the biggedt similarity will be joined.
Similarity is calculated with the number of common
dimensions in the keys.
*/
const views = v.map((i) => i); const views = v.map((i) => i);
let similarity = 0;
let idx0 = 0;
let idx1 = 1;
for (let i = 0; i < views.length; ++i) {
for (let j = i + 1 ; j < views.length; ++j) {
const pi = views[i].dimensions;
const pj = views[j].dimensions;
let score = this.similarDimensions (pi, pj);
if (similarity < score) {
similarity = score;
idx0 = i;
idx1 = j;
}
}
}
const partial0 = views[idx0]; let dims: Dimension[] = [];
const partial1 = views[idx1]; let mets: Metric[] = [];
let clauses: Clause[] = [];
views.splice(idx1, 1); for (let i = 0; i < views.length; ++i) {
views.splice(idx0, 1); mets = mets.concat(views[i].metrics);
dims = dims.concat(views[i].dimensions);
clauses = clauses.concat(views[i].clauses);
}
let dims = partial0.dimensions.concat(partial1.dimensions);
dims = ViewHandler.removeDuplicatedDimensions(dims); dims = ViewHandler.removeDuplicatedDimensions(dims);
let mets = partial0.metrics.concat(partial1.metrics);
mets = ViewHandler.removeDuplicatedMetrics(mets); mets = ViewHandler.removeDuplicatedMetrics(mets);
let clauses = partial0.clauses.concat(partial1.clauses);
clauses = ViewHandler.removeDuplicatedClauses(clauses); clauses = ViewHandler.removeDuplicatedClauses(clauses);
const qOpts: QueryOpts = {metrics: mets, dimensions: dims, clauses: clauses}; const qOpts: QueryOpts = {metrics: mets, dimensions: dims, clauses: clauses};
const partialQuery = new Query(qOpts); const partialQuery = new Query(qOpts);
const partial = ViewHandler.queryJoin(partialQuery, [partial0, partial1]); const partial = ViewHandler.queryJoin(partialQuery, views);
views.push(partial); return [partial];
return views;
}
/**
* Calculates the similarity of two sets of dimensions. In other
* other how many dimensions are in both sets.
* @param a - A set of dimensions.
* @param b - Another set of dimensions.
*/
private static similarDimensions(a: Dimension[], b: Dimension[]): number {
let count = 0;
for (let i = 0; i < a.length; ++i) {
if (b.some((itemB) => a[i].name === itemB.name)) {
count++;
}
}
return count;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment