scenario.ts 11.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
 * Departamento de Informatica - Universidade Federal do Parana
 *
 * This file is part of blendb.
 *
 * blendb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * blendb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with blendb.  If not, see <http://www.gnu.org/licenses/>.
 */

21
import { ConfigParser } from "../src/util/configParser";
22 23 24
import { Metric } from "../src/core/metric";
import { Dimension } from "../src/core/dimension";
import { View } from "../src/core/view";
25 26
import { Filter, FilterOperator } from "../src/core/filter";
import { Clause } from "../src/core/clause";
27
import { AggregationType, RelationType , DataType} from "../src/common/types";
28
import { Query} from "../src/common/query";
29
import { ViewHandler } from "../src/util/viewHandler";
30 31 32 33 34

interface EngineScenario {
    metrics: Metric[];
    dimensions: Dimension[];
    subDimensions: Dimension[];
35 36
    wrongMet: Metric;
    wrongDim: Dimension;
37 38 39 40 41 42 43 44 45 46
    views: View[];
}

interface AdapterScenario {
    materializedView: View;
    noSelectionView: View;
    withSelectionView: View;
    subDimensionView: View;
    join4View: View;
    dateView: View;
47
    aggrView: View;
48 49 50 51
    clauseView: View;
    multiFilterView: View;
    multiClauseView: View;
    notEqualView: View;
52 53
    gtltView: View;
    geleView: View;
54
    notMatchFilterView: View;
55
    notOriginCount: View;
56 57
    unMaterializebleView: View;
    partialJoinView: View;
58
    propagatedClauseView: View;
59
    propagatedClauseAggrView: View;
60 61
}

62 63 64 65
interface DataCtrlScenario {
    wrongMet: Query;
    wrongDim: Query;
    correct: Query;
66
    clausal: Query;
67
}
68

69 70
const configPath =  process.env.BLENDB_SCHEMA_FILE;
const config = ConfigParser.parse(configPath);
71

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
const mets = config.metrics.sort((a, b) => {
    const aValue = parseInt(a.name.split(":")[1], 10);
    const bValue = parseInt(b.name.split(":")[1], 10);
    return aValue - bValue;
});
const dims = config.dimensions.sort((a, b) => {
    const aValue = parseInt(a.name.split(":")[1], 10);
    const bValue = parseInt(b.name.split(":")[1], 10);
    return aValue - bValue;
});
const views = config.buildViews.sort((a, b) => {
    const aValue = parseInt(a.alias.split(" ")[1], 10);
    const bValue = parseInt(b.alias.split(" ")[1], 10);
    return aValue - bValue;
}).map((item) => item.view);
87

88 89 90 91 92 93 94 95 96 97 98
const filters: { [key: string]: Filter } = {
    "dim:0:0" : new Filter({
        target: dims[0],
        operator: FilterOperator.EQUAL,
        value: "2017-01-02"
    }),
    "dim:0:1" : new Filter({
        target: dims[0],
        operator: FilterOperator.EQUAL,
        value: "2017-01-03"
    }),
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    "dim:0:gt" : new Filter({
        target: dims[0],
        operator: FilterOperator.GREATER,
        value: "2017-01-02"
    }),
    "dim:0:lt" : new Filter({
        target: dims[0],
        operator: FilterOperator.LOWER,
        value: "2017-01-04"
    }),
    "dim:0:ge" : new Filter({
        target: dims[0],
        operator: FilterOperator.GREATEREQ,
        value: "2017-01-02"
    }),
    "dim:0:le" : new Filter({
        target: dims[0],
        operator: FilterOperator.LOWEREQ,
        value: "2017-01-04"
    }),
119 120 121 122 123
    "dim:2" : new Filter({
        target: dims[2],
        operator: FilterOperator.NOTEQUAL,
        value: "1"
    }),
124 125 126 127 128
    "dim:4" : new Filter({
        target: dims[4],
        operator: FilterOperator.NOTEQUAL,
        value: "dim:4:1"
    }),
129 130
    "dim:5" : new Filter({
        target: dims[5],
131
        operator: FilterOperator.NOTEQUAL,
132
        value: "true"
133 134 135 136 137 138 139 140 141 142
    }),
    "dim:7" : new Filter({
        target: dims[7],
        operator: FilterOperator.EQUAL,
        value: "1"
    })
};

const clauses: { [key: string]: Clause }  = {
    "view0dim7": new Clause({filters: [filters["dim:7"]]}),
143 144 145 146
    "view0gt": new Clause({filters: [filters["dim:0:gt"]]}),
    "view0lt": new Clause({filters: [filters["dim:0:lt"]]}),
    "view0ge": new Clause({filters: [filters["dim:0:ge"]]}),
    "view0le": new Clause({filters: [filters["dim:0:le"]]}),
147
    "view0dim0": new Clause({filters: [filters["dim:0:0"], filters["dim:0:1"]]}),
148
    "view9dim2": new Clause({filters: [filters["dim:2"]]}),
149
    "view6dim4": new Clause({filters: [filters["dim:4"]]}),
150
    "view7dim5": new Clause({filters: [filters["dim:5"]]})
151 152
};

153
const wrongMet = new Metric({
154
    name: "met:-1",
155
    aggregation: AggregationType.COUNT,
156
    dataType: DataType.INTEGER
157
});
158
const wrongDim = new Dimension({ name: "dim:-1", dataType: DataType.INTEGER });
159 160

const subdimAux = new Dimension({
161
    name: "sub:0",
162
    dataType: DataType.INTEGER,
163 164 165 166 167 168 169
    parent: dims[0],
    relation: RelationType.DAY
});

const subdims = [
    subdimAux,
    new Dimension({
170
        name: "sub:1",
171
        dataType: DataType.INTEGER,
172
        parent: dims[1],
173 174 175
        relation: RelationType.DAY
    }),
    new Dimension({
176
        name: "sub:2",
177
        dataType: DataType.INTEGER,
178 179 180 181
        parent: subdimAux,
        relation: RelationType.DAY
    }),
    new Dimension({
182
        name: "sub:3",
183
        dataType: DataType.INTEGER,
184 185 186 187
        parent: null,
        relation: RelationType.DAY
    }),
    new Dimension({
188
        name: "sub:4",
189
        dataType: DataType.INTEGER,
190 191 192
        parent: dims[1],
        relation: RelationType.DAY
    })
193 194 195 196 197
].sort((a, b) => {
    const aValue = parseInt(a.name.split(":")[1], 10);
    const bValue = parseInt(b.name.split(":")[1], 10);
    return aValue - bValue;
});
198 199 200

const dateSubDim = [
    new Dimension ({
201
        name: "dim:0:month",
202
        dataType: DataType.INTEGER,
203
        parent: dims[0],
204 205 206
        relation: RelationType.MONTH
    }),
    new Dimension ({
207
        name: "dim:0:day",
208
        dataType: DataType.INTEGER,
209
        parent: dims[0],
210 211 212
        relation: RelationType.DAY
    }),
    new Dimension ({
213
        name: "dim:0:year",
214
        dataType: DataType.INTEGER,
215
        parent: dims[0],
216
        relation: RelationType.YEAR
217
    })
218 219
];

220
const dateView = ViewHandler.queryReduce({
221 222
    metrics: [],
    dimensions: dateSubDim,
223
}, views[0]);
224

225
const aggrView = ViewHandler.queryJoin({
226
    metrics: [mets[0], mets[1], mets[6], mets[10], mets[11]],
227
    dimensions: [],
228 229 230 231 232 233 234 235 236 237
}, [
    ViewHandler.queryReduce({
        metrics: [mets[0], mets[1], mets[10]],
        dimensions: []
    }, views[0]),
    ViewHandler.queryReduce({
        metrics: [mets[6], mets[11]],
        dimensions: []
    }, views[2])
]);
238

239
const clauseView = ViewHandler.queryReduce({
240 241 242
    metrics: [mets[0], mets[1], mets[2]],
    dimensions: [dims[0]],
    clauses: [clauses.view0dim7]
243
}, views[0]);
244

245
const multiFilterView = ViewHandler.queryReduce({
246 247 248
    metrics: [mets[0], mets[1]],
    dimensions: [dims[0]],
    clauses: [clauses.view0dim0]
249
}, views[0]);
250

251
const multiClauseView = ViewHandler.queryReduce({
252 253 254
    metrics: [mets[0], mets[1]],
    dimensions: [dims[0]],
    clauses: [clauses.view0dim0, clauses.view0dim7]
255
}, views[0]);
256

257
const notEqualView = ViewHandler.queryReduce({
258
    metrics: [],
259 260
    dimensions: [dims[4], dims[5]],
    clauses: [clauses.view7dim5]
261
}, views[7]);
262

263
const gtltView = ViewHandler.queryReduce({
264 265 266
    metrics: [],
    dimensions: [dims[0]],
    clauses: [clauses.view0gt, clauses.view0lt]
267
}, views[0]);
268

269
const geleView = ViewHandler.queryReduce({
270 271 272
    metrics: [],
    dimensions: [dims[0]],
    clauses: [clauses.view0ge, clauses.view0le]
273
}, views[0]);
274

275
const notMatchFilterView = ViewHandler.queryReduce({
276 277 278
    metrics: [mets[0]],
    dimensions: [dims[0]],
    clauses: [clauses.view7dim5]
279
}, views[0]);
280

281
const subDimView = ViewHandler.queryJoin({
282
    metrics: [mets[0]],
283 284 285 286 287 288 289 290 291 292 293
    dimensions: [subdims[0], subdims[1], dims[7], dims[8]]
}, [
    ViewHandler.queryReduce({
        metrics: [mets[0]],
        dimensions: [subdims[0], dims[7]]
    }, views[0]),
    ViewHandler.queryJoin({
        metrics: [],
        dimensions: [subdims[1], dims[7], dims[8]]
    }, [views[1], views[4]])
]);
294

295
const join4View = ViewHandler.queryJoin({
296
    metrics: [mets[0], mets[1], mets[2], mets[3], mets[4], mets[5]],
297 298
    dimensions: [dims[2], dims[7], dims[8]]
}, [views[0], views[1], views[2], views[4]]);
299

300
const noSelView = ViewHandler.queryJoin({
301
    metrics: [mets[0], mets[3]],
302 303
    dimensions: []
}, [views[0], views[1]]);
304

305
const withSelView = ViewHandler.queryJoin({
306
    metrics: [mets[0], mets[1]],
307 308
    dimensions: [dims[7], dims[8]]
}, [views[0], views[4]]);
309

310 311 312
const notOriginCount = new View({
    metrics: [mets[5], mets[6], mets[7]],
    dimensions: [dims[2]],
313 314
    origin: false,
    clauses: [clauses.view9dim2]
315 316
});

317
const unMaterializebleView = ViewHandler.queryJoin({
318
    metrics: [mets[7], mets[9]],
319 320 321 322 323 324 325 326 327 328 329 330 331
    dimensions: [dims[5]]
},
[ViewHandler.queryReduce({
    metrics: [mets[9]],
    dimensions: [dims[5]]
}, views[8]),
ViewHandler.queryReduce({metrics: [mets[7]], dimensions: [dims[5]]},
ViewHandler.queryJoin({metrics: [mets[7]], dimensions: [dims[3], dims[5]]}, [
ViewHandler.queryReduce({metrics: [], dimensions: [dims[3], dims[5]]},
ViewHandler.queryJoin({metrics: [], dimensions: [dims[3], dims[4], dims[5]]}, [
ViewHandler.queryReduce({metrics: [], dimensions: [dims[4], dims[5]]}, views[7]),
ViewHandler.queryReduce({metrics: [], dimensions: [dims[3], dims[4]]}, views[3])
])), views[5]]))]);
332

333
const partialJoinView = ViewHandler.queryJoin({
334
    metrics: [mets[7], mets[8]],
335 336
    dimensions: []
}, [views[3], views[5], views[6]]);
337

338
const propagatedClauseView  = ViewHandler.queryJoin({
339 340 341
    metrics: [mets[8]],
    dimensions: [dims[4]],
    clauses: [clauses.view7dim5, clauses.view6dim4]
342
}, [views[6], views[7]]);
343

344
const propagatedClauseAggrView  = ViewHandler.queryJoin({
345 346 347
    metrics: [mets[8], mets[5]],
    dimensions: [dims[2]],
    clauses: [clauses.view7dim5, clauses.view6dim4, clauses.view9dim2]
348
}, [views[9], views[6], views[7]]);
349

350
export const engineScenario: EngineScenario = {
351 352 353 354
    metrics: mets,
    dimensions: dims,
    wrongMet: wrongMet,
    wrongDim: wrongDim,
355
    subDimensions: subdims,
356
    views: views
357 358 359 360 361 362 363 364
};

export const adapterScenario: AdapterScenario = {
    materializedView: views[0],
    noSelectionView: noSelView,
    withSelectionView: withSelView,
    subDimensionView: subDimView,
    join4View: join4View,
365
    dateView: dateView,
366 367 368 369
    aggrView: aggrView,
    clauseView: clauseView,
    multiFilterView: multiFilterView,
    multiClauseView: multiClauseView,
370 371
    notEqualView: notEqualView,
    gtltView: gtltView,
372
    geleView: geleView,
373
    notMatchFilterView: notMatchFilterView,
374 375
    notOriginCount: notOriginCount,
    unMaterializebleView: unMaterializebleView,
376
    partialJoinView: partialJoinView,
377 378
    propagatedClauseView: propagatedClauseView,
    propagatedClauseAggrView: propagatedClauseAggrView
379
};
380 381 382 383

export const dataCtrlScenario: DataCtrlScenario = {
    wrongMet: { metrics: [wrongMet], dimensions: [dims[0]] },
    wrongDim: { metrics: [mets[0]], dimensions: [wrongDim] },
384 385
    correct: { metrics: [mets[0]], dimensions: [dims[0]] },
    clausal: { metrics: [mets[0]], dimensions: [dims[7]] }
386
};