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 config = ConfigParser.parse("config/test.yaml");

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
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);
86

87 88 89 90 91 92 93 94 95 96 97
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"
    }),
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    "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"
    }),
118 119 120 121 122
    "dim:2" : new Filter({
        target: dims[2],
        operator: FilterOperator.NOTEQUAL,
        value: "1"
    }),
123 124 125 126 127
    "dim:4" : new Filter({
        target: dims[4],
        operator: FilterOperator.NOTEQUAL,
        value: "dim:4:1"
    }),
128 129
    "dim:5" : new Filter({
        target: dims[5],
130
        operator: FilterOperator.NOTEQUAL,
131
        value: "true"
132 133 134 135 136 137 138 139 140 141
    }),
    "dim:7" : new Filter({
        target: dims[7],
        operator: FilterOperator.EQUAL,
        value: "1"
    })
};

const clauses: { [key: string]: Clause }  = {
    "view0dim7": new Clause({filters: [filters["dim:7"]]}),
142 143 144 145
    "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"]]}),
146
    "view0dim0": new Clause({filters: [filters["dim:0:0"], filters["dim:0:1"]]}),
147
    "view9dim2": new Clause({filters: [filters["dim:2"]]}),
148
    "view6dim4": new Clause({filters: [filters["dim:4"]]}),
149
    "view7dim5": new Clause({filters: [filters["dim:5"]]})
150 151
};

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

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

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

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

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

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

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

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

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

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

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

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

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

280
const subDimView = ViewHandler.queryJoin({
281
    metrics: [mets[0]],
282 283 284 285 286 287 288 289 290 291 292
    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]])
]);
293

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

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

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

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

316
const unMaterializebleView = ViewHandler.queryJoin({
317
    metrics: [mets[7], mets[9]],
318 319 320 321 322 323 324 325 326 327 328 329 330
    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]]))]);
331

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

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

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

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

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

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