scenario.ts 7 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
}

53 54 55 56
interface DataCtrlScenario {
    wrongMet: Query;
    wrongDim: Query;
    correct: Query;
57
    clausal: Query;
58
}
59

60 61 62 63 64
const config = ConfigParser.parse("config/test.yaml");

const mets = config.metrics;
const dims = config.dimensions;
const views = config.views;
65

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
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"
    }),
    "dim:3" : new Filter({
        target: dims[3],
        operator: FilterOperator.NOTEQUAL,
        value: "dim:3:1"
    }),
    "dim:7" : new Filter({
        target: dims[7],
        operator: FilterOperator.EQUAL,
        value: "1"
    })
};

const clauses: { [key: string]: Clause }  = {
    "view0dim7": new Clause({filters: [filters["dim:7"]]}),
    "view0dim0": new Clause({filters: [filters["dim:0:0"], filters["dim:0:1"]]}),
    "view3dim3": new Clause({filters: [filters["dim:3"]]})
};

95 96 97 98 99 100 101 102
const wrongMet = new Metric({
    name: "met:11",
    aggregation: AggregationType.COUNT,
    dataType: "integer"
});
const wrongDim = new Dimension({ name: "dim:11", dataType: "integer" });

const subdimAux = new Dimension({
103
    name: "sub:0",
104 105 106 107 108 109 110 111
    dataType: "integer",
    parent: dims[0],
    relation: RelationType.DAY
});

const subdims = [
    subdimAux,
    new Dimension({
112
        name: "sub:1",
113
        dataType: "integer",
114
        parent: dims[1],
115 116 117
        relation: RelationType.DAY
    }),
    new Dimension({
118
        name: "sub:2",
119 120 121 122 123
        dataType: "integer",
        parent: subdimAux,
        relation: RelationType.DAY
    }),
    new Dimension({
124
        name: "sub:3",
125 126 127 128 129
        dataType: "integer",
        parent: null,
        relation: RelationType.DAY
    }),
    new Dimension({
130
        name: "sub:4",
131 132 133 134 135 136 137 138
        dataType: "integer",
        parent: dims[1],
        relation: RelationType.DAY
    })
];

const dateSubDim = [
    new Dimension ({
139
        name: "dim:0:month",
140
        dataType: "integer",
141
        parent: dims[0],
142 143 144
        relation: RelationType.MONTH
    }),
    new Dimension ({
145
        name: "dim:0:day",
146
        dataType: "integer",
147
        parent: dims[0],
148 149 150
        relation: RelationType.DAY
    }),
    new Dimension ({
151
        name: "dim:0:year",
152
        dataType: "integer",
153
        parent: dims[0],
154 155 156
        relation: RelationType.YEAR
    }),
    new Dimension ({
157
        name: "dim:0:dow",
158
        dataType: "integer",
159
        parent: dims[0],
160 161 162 163 164 165 166 167
        relation: RelationType.DAYOFWEEK
    }),
];

const dateView = new View({
    metrics: [],
    dimensions: dateSubDim,
    materialized: false,
168
    origin: false,
169
    childViews: [views[0]]
170 171
});

172 173 174 175 176
const aggrView = new View({
    metrics: [mets[0], mets[1], mets[6]],
    dimensions: [],
    materialized: false,
    origin: false,
177
    childViews: [views[0], views[2], views[4]]
178 179
});

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
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: [],
    dimensions: [dims[3]],
    materialized: false,
    origin: false,
    childViews: [views[3]],
    clauses: [clauses.view3dim3]
});

216 217
const subDimView = new View({
    metrics: [mets[0]],
218
    dimensions: [subdims[0], subdims[1], dims[7], dims[8]],
219
    materialized: false,
220
    origin: false,
221
    childViews: [views[0], views[1], views[4]]
222 223 224
});

const join4View = new View({
225 226
    metrics: [mets[0], mets[1], mets[2], mets[3], mets[4], mets[5]],
    dimensions: [dims[2], dims[7], dims[8]],
227
    materialized: false,
228
    origin: false,
229
    childViews: [views[0], views[1], views[2], views[4]]
230 231 232 233 234 235
});

const noSelView = new View({
    metrics: [mets[0], mets[3]],
    dimensions: [],
    materialized: false,
236
    origin: false,
237
    childViews: [views[0], views[1]]
238 239 240
});

const withSelView = new View({
241 242
    metrics: [mets[0], mets[1]],
    dimensions: [dims[7], dims[8]],
243
    materialized: false,
244
    origin: false,
245
    childViews: [views[0], views[4]]
246 247 248
});

export const engineScenario: EngineScenario = {
249 250 251 252
    metrics: mets,
    dimensions: dims,
    wrongMet: wrongMet,
    wrongDim: wrongDim,
253
    subDimensions: subdims,
254
    views: views
255 256 257 258 259 260 261 262
};

export const adapterScenario: AdapterScenario = {
    materializedView: views[0],
    noSelectionView: noSelView,
    withSelectionView: withSelView,
    subDimensionView: subDimView,
    join4View: join4View,
263
    dateView: dateView,
264 265 266 267 268
    aggrView: aggrView,
    clauseView: clauseView,
    multiFilterView: multiFilterView,
    multiClauseView: multiClauseView,
    notEqualView: notEqualView
269
};
270 271 272 273

export const dataCtrlScenario: DataCtrlScenario = {
    wrongMet: { metrics: [wrongMet], dimensions: [dims[0]] },
    wrongDim: { metrics: [mets[0]], dimensions: [wrongDim] },
274 275
    correct: { metrics: [mets[0]], dimensions: [dims[0]] },
    clausal: { metrics: [mets[0]], dimensions: [dims[7]] }
276
};