scenario.ts 4.99 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 25
import { Metric } from "../src/core/metric";
import { Dimension } from "../src/core/dimension";
import { View } from "../src/core/view";
import { AggregationType, RelationType } from "../src/common/types";
26
import { Query} from "../src/common/query";
27 28 29 30 31

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

interface AdapterScenario {
    materializedView: View;
    noSelectionView: View;
    withSelectionView: View;
    subDimensionView: View;
    join4View: View;
    dateView: View;
44
    aggrView: View;
45 46
}

47 48 49 50 51
interface DataCtrlScenario {
    wrongMet: Query;
    wrongDim: Query;
    correct: Query;
}
52

53 54 55 56 57
const config = ConfigParser.parse("config/test.yaml");

const mets = config.metrics;
const dims = config.dimensions;
const views = config.views;
58 59 60 61 62 63 64 65 66

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({
67
    name: "sub:0",
68 69 70 71 72 73 74 75
    dataType: "integer",
    parent: dims[0],
    relation: RelationType.DAY
});

const subdims = [
    subdimAux,
    new Dimension({
76
        name: "sub:1",
77
        dataType: "integer",
78
        parent: dims[1],
79 80 81
        relation: RelationType.DAY
    }),
    new Dimension({
82
        name: "sub:2",
83 84 85 86 87
        dataType: "integer",
        parent: subdimAux,
        relation: RelationType.DAY
    }),
    new Dimension({
88
        name: "sub:3",
89 90 91 92 93
        dataType: "integer",
        parent: null,
        relation: RelationType.DAY
    }),
    new Dimension({
94
        name: "sub:4",
95 96 97 98 99 100 101 102
        dataType: "integer",
        parent: dims[1],
        relation: RelationType.DAY
    })
];

const dateSubDim = [
    new Dimension ({
103
        name: "dim:0:month",
104
        dataType: "integer",
105
        parent: dims[0],
106 107 108
        relation: RelationType.MONTH
    }),
    new Dimension ({
109
        name: "dim:0:day",
110
        dataType: "integer",
111
        parent: dims[0],
112 113 114
        relation: RelationType.DAY
    }),
    new Dimension ({
115
        name: "dim:0:year",
116
        dataType: "integer",
117
        parent: dims[0],
118 119 120
        relation: RelationType.YEAR
    }),
    new Dimension ({
121
        name: "dim:0:dow",
122
        dataType: "integer",
123
        parent: dims[0],
124 125 126 127 128 129 130 131
        relation: RelationType.DAYOFWEEK
    }),
];

const dateView = new View({
    metrics: [],
    dimensions: dateSubDim,
    materialized: false,
132
    origin: false,
133
    childViews: [views[0]]
134 135
});

136 137 138 139 140
const aggrView = new View({
    metrics: [mets[0], mets[1], mets[6]],
    dimensions: [],
    materialized: false,
    origin: false,
141
    childViews: [views[0], views[2], views[4]]
142 143
});

144 145
const subDimView = new View({
    metrics: [mets[0]],
146
    dimensions: [subdims[0], subdims[1], dims[7], dims[8]],
147
    materialized: false,
148
    origin: false,
149
    childViews: [views[0], views[1], views[4]]
150 151 152
});

const join4View = new View({
153 154
    metrics: [mets[0], mets[1], mets[2], mets[3], mets[4], mets[5]],
    dimensions: [dims[2], dims[7], dims[8]],
155
    materialized: false,
156
    origin: false,
157
    childViews: [views[0], views[1], views[2], views[4]]
158 159 160 161 162 163
});

const noSelView = new View({
    metrics: [mets[0], mets[3]],
    dimensions: [],
    materialized: false,
164
    origin: false,
165
    childViews: [views[0], views[1]]
166 167 168
});

const withSelView = new View({
169 170
    metrics: [mets[0], mets[1]],
    dimensions: [dims[7], dims[8]],
171
    materialized: false,
172
    origin: false,
173
    childViews: [views[0], views[4]]
174 175 176
});

export const engineScenario: EngineScenario = {
177 178 179 180
    metrics: mets,
    dimensions: dims,
    wrongMet: wrongMet,
    wrongDim: wrongDim,
181
    subDimensions: subdims,
182
    views: views
183 184 185 186 187 188 189 190
};

export const adapterScenario: AdapterScenario = {
    materializedView: views[0],
    noSelectionView: noSelView,
    withSelectionView: withSelView,
    subDimensionView: subDimView,
    join4View: join4View,
191 192
    dateView: dateView,
    aggrView: aggrView
193
};
194 195 196 197 198 199

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