Skip to content
Snippets Groups Projects

Issue #94: Update view join algorithm

Merged Rafael Dias requested to merge issue/94 into develop
1 file
+ 14
57
Compare changes
  • Side-by-side
  • Inline
+ 14
57
@@ -116,7 +116,7 @@ export class ViewHandler {
partialJoin = views.map((i) => (i));
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};
partialQuery = new Query(qOpt);
reduced = ViewHandler.applyReduce(partialJoin, partialQuery);
@@ -134,7 +134,7 @@ export class ViewHandler {
metView = partialJoin[metViewId];
partialJoin.splice(metViewId, 1);
while (partialJoin.length > 1) {
if (partialJoin.length > 0) {
partialJoin.push(metView); // MetView is now the last view
qOpt = {metrics: partialQuery.metrics, dimensions: partialQuery.dimensions, clauses: clausesToCover};
partialQuery = new Query(qOpt);
@@ -309,76 +309,33 @@ export class ViewHandler {
}
/**
* Finds the pair of views most realted in a set of views and
* applies the JOIN operation in this set.
* Returns a set with the joined view and without the most
* related view.
* Apply JOIN operation in a set of views.
* Returns a set with the joined view.
* @param v - Set of candidated views to be joined.
*/
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);
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];
const partial1 = views[idx1];
let dims: Dimension[] = [];
let mets: Metric[] = [];
let clauses: Clause[] = [];
views.splice(idx1, 1);
views.splice(idx0, 1);
for (let i = 0; i < views.length; ++i) {
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);
let mets = partial0.metrics.concat(partial1.metrics);
mets = ViewHandler.removeDuplicatedMetrics(mets);
let clauses = partial0.clauses.concat(partial1.clauses);
clauses = ViewHandler.removeDuplicatedClauses(clauses);
const qOpts: QueryOpts = {metrics: mets, dimensions: dims, clauses: clauses};
const partialQuery = new Query(qOpts);
const partial = ViewHandler.queryJoin(partialQuery, [partial0, partial1]);
views.push(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;
const partial = ViewHandler.queryJoin(partialQuery, views);
return [partial];
}
/**
Loading