scenario.ts 9.61 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 } from "../src/common/types";
28
import { Query} from "../src/common/query";
29 30 31 32 33

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

interface AdapterScenario {
    materializedView: View;
    noSelectionView: View;
    withSelectionView: View;
    subDimensionView: View;
    join4View: View;
    dateView: View;
46
    aggrView: View;
47 48 49 50
    clauseView: View;
    multiFilterView: View;
    multiClauseView: View;
    notEqualView: View;
51 52
    gtltView: View;
    geleView: View;
53
    notMatchFilterView: View;
54
    notOriginCount: View;
55 56
}

57 58 59 60
interface DataCtrlScenario {
    wrongMet: Query;
    wrongDim: Query;
    correct: Query;
61
    clausal: Query;
62
}
63

64 65
const config = ConfigParser.parse("config/test.yaml");

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
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);
81

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

const clauses: { [key: string]: Clause }  = {
    "view0dim7": new Clause({filters: [filters["dim:7"]]}),
132 133 134 135
    "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"]]}),
136
    "view0dim0": new Clause({filters: [filters["dim:0:0"], filters["dim:0:1"]]}),
137
    "view9dim2": new Clause({filters: [filters["dim:2"]]}),
138
    "view7dim5": new Clause({filters: [filters["dim:5"]]})
139 140
};

141
const wrongMet = new Metric({
142
    name: "met:-1",
143 144 145 146 147 148
    aggregation: AggregationType.COUNT,
    dataType: "integer"
});
const wrongDim = new Dimension({ name: "dim:11", dataType: "integer" });

const subdimAux = new Dimension({
149
    name: "sub:0",
150 151 152 153 154 155 156 157
    dataType: "integer",
    parent: dims[0],
    relation: RelationType.DAY
});

const subdims = [
    subdimAux,
    new Dimension({
158
        name: "sub:1",
159
        dataType: "integer",
160
        parent: dims[1],
161 162 163
        relation: RelationType.DAY
    }),
    new Dimension({
164
        name: "sub:2",
165 166 167 168 169
        dataType: "integer",
        parent: subdimAux,
        relation: RelationType.DAY
    }),
    new Dimension({
170
        name: "sub:3",
171 172 173 174 175
        dataType: "integer",
        parent: null,
        relation: RelationType.DAY
    }),
    new Dimension({
176
        name: "sub:4",
177 178 179 180
        dataType: "integer",
        parent: dims[1],
        relation: RelationType.DAY
    })
181 182 183 184 185
].sort((a, b) => {
    const aValue = parseInt(a.name.split(":")[1], 10);
    const bValue = parseInt(b.name.split(":")[1], 10);
    return aValue - bValue;
});
186 187 188

const dateSubDim = [
    new Dimension ({
189
        name: "dim:0:month",
190
        dataType: "integer",
191
        parent: dims[0],
192 193 194
        relation: RelationType.MONTH
    }),
    new Dimension ({
195
        name: "dim:0:day",
196
        dataType: "integer",
197
        parent: dims[0],
198 199 200
        relation: RelationType.DAY
    }),
    new Dimension ({
201
        name: "dim:0:year",
202
        dataType: "integer",
203
        parent: dims[0],
204 205 206
        relation: RelationType.YEAR
    }),
    new Dimension ({
207
        name: "dim:0:dow",
208
        dataType: "integer",
209
        parent: dims[0],
210 211 212 213 214 215 216 217
        relation: RelationType.DAYOFWEEK
    }),
];

const dateView = new View({
    metrics: [],
    dimensions: dateSubDim,
    materialized: false,
218
    origin: false,
219
    childViews: [views[0]]
220 221
});

222
const aggrView = new View({
223
    metrics: [mets[0], mets[1], mets[6], mets[10], mets[11]],
224 225 226
    dimensions: [],
    materialized: false,
    origin: false,
227
    childViews: [views[0], views[2], views[3], views[4], views[7], views[8]]
228 229
});

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
const clauseView = new View({
    metrics: [mets[0], mets[1], mets[2]],
    dimensions: [dims[0]],
    materialized: false,
    origin: false,
    childViews: [views[0]],
    clauses: [clauses.view0dim7]
});

const multiFilterView = new View({
    metrics: [mets[0], mets[1]],
    dimensions: [dims[0]],
    materialized: false,
    origin: false,
    childViews: [views[0]],
    clauses: [clauses.view0dim0]
});

const multiClauseView = new View({
    metrics: [mets[0], mets[1]],
    dimensions: [dims[0]],
    materialized: false,
    origin: false,
    childViews: [views[0]],
    clauses: [clauses.view0dim0, clauses.view0dim7]
});

const notEqualView = new View({
    metrics: [],
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
    dimensions: [dims[4], dims[5]],
    materialized: false,
    origin: false,
    childViews: [views[7]],
    clauses: [clauses.view7dim5]
});

const gtltView = new View({
    metrics: [],
    dimensions: [dims[0]],
    materialized: false,
    origin: false,
    childViews: [views[0]],
    clauses: [clauses.view0gt, clauses.view0lt]
});

const geleView = new View({
    metrics: [],
    dimensions: [dims[0]],
278 279
    materialized: false,
    origin: false,
280 281
    childViews: [views[0]],
    clauses: [clauses.view0ge, clauses.view0le]
282 283
});

284 285 286 287 288 289 290 291 292
const notMatchFilterView = new View({
    metrics: [mets[0]],
    dimensions: [dims[0]],
    materialized: false,
    origin: false,
    childViews: [views[0]],
    clauses: [clauses.view7dim5]
});

293 294
const subDimView = new View({
    metrics: [mets[0]],
295
    dimensions: [subdims[0], subdims[1], dims[7], dims[8]],
296
    materialized: false,
297
    origin: false,
298
    childViews: [views[0], views[1], views[4]]
299 300 301
});

const join4View = new View({
302 303
    metrics: [mets[0], mets[1], mets[2], mets[3], mets[4], mets[5]],
    dimensions: [dims[2], dims[7], dims[8]],
304
    materialized: false,
305
    origin: false,
306
    childViews: [views[0], views[1], views[2], views[4]]
307 308 309 310 311 312
});

const noSelView = new View({
    metrics: [mets[0], mets[3]],
    dimensions: [],
    materialized: false,
313
    origin: false,
314
    childViews: [views[0], views[1]]
315 316 317
});

const withSelView = new View({
318 319
    metrics: [mets[0], mets[1]],
    dimensions: [dims[7], dims[8]],
320
    materialized: false,
321
    origin: false,
322
    childViews: [views[0], views[4]]
323 324
});

325 326 327 328
const notOriginCount = new View({
    metrics: [mets[5], mets[6], mets[7]],
    dimensions: [dims[2]],
    materialized: true,
329 330
    origin: false,
    clauses: [clauses.view9dim2]
331 332
});

333
export const engineScenario: EngineScenario = {
334 335 336 337
    metrics: mets,
    dimensions: dims,
    wrongMet: wrongMet,
    wrongDim: wrongDim,
338
    subDimensions: subdims,
339
    views: views
340 341 342 343 344 345 346 347
};

export const adapterScenario: AdapterScenario = {
    materializedView: views[0],
    noSelectionView: noSelView,
    withSelectionView: withSelView,
    subDimensionView: subDimView,
    join4View: join4View,
348
    dateView: dateView,
349 350 351 352
    aggrView: aggrView,
    clauseView: clauseView,
    multiFilterView: multiFilterView,
    multiClauseView: multiClauseView,
353 354
    notEqualView: notEqualView,
    gtltView: gtltView,
355
    geleView: geleView,
356 357
    notMatchFilterView: notMatchFilterView,
    notOriginCount: notOriginCount
358
};
359 360 361 362

export const dataCtrlScenario: DataCtrlScenario = {
    wrongMet: { metrics: [wrongMet], dimensions: [dims[0]] },
    wrongDim: { metrics: [mets[0]], dimensions: [wrongDim] },
363 364
    correct: { metrics: [mets[0]], dimensions: [dims[0]] },
    clausal: { metrics: [mets[0]], dimensions: [dims[7]] }
365
};