Skip to content

Commit b45a1c4

Browse files
authored
fix(cube): Meta type for switch dimension (#10060)
1 parent 6034850 commit b45a1c4

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

packages/cubejs-schema-compiler/src/compiler/CubeToMetaTransformer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class CubeToMetaTransformer {
103103
R.map((nameToDimension) => ({
104104
name: `${cube.name}.${nameToDimension[0]}`,
105105
title: this.title(cubeTitle, nameToDimension),
106-
type: nameToDimension[1].type,
106+
type: this.dimensionDataType(nameToDimension[1].type),
107107
description: nameToDimension[1].description,
108108
shortTitle: this.title(cubeTitle, nameToDimension, true),
109109
suggestFilterValues:
@@ -197,6 +197,10 @@ export class CubeToMetaTransformer {
197197
return defaultValue;
198198
}
199199

200+
dimensionDataType(dimensionType) {
201+
return dimensionType === 'switch' ? 'string' : dimensionType;
202+
}
203+
200204
measureConfig(cubeName, cubeTitle, nameToMetric) {
201205
const name = `${cubeName}.${nameToMetric[0]}`;
202206
// Support both old 'drillMemberReferences' and new 'drillMembers' keys
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cubes:
2+
- name: orders
3+
sql: SELECT * FROM orders
4+
5+
measures:
6+
- name: count
7+
sql: id
8+
type: count
9+
dimensions:
10+
- name: id
11+
sql: id
12+
type: number
13+
primary_key: true
14+
15+
- name: number
16+
sql: number
17+
type: number
18+
19+
- name: currency
20+
type: switch
21+
values:
22+
- USD
23+
- EUR
24+
- GBP
25+
26+
- name: status
27+
sql: status
28+
type: string
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
import { CubeToMetaTransformer } from 'src/compiler/CubeToMetaTransformer';
5+
import { prepareYamlCompiler } from './PrepareCompiler';
6+
7+
describe('Switch Dimension', () => {
8+
it('Switch dimension meta type', async () => {
9+
const modelContent = fs.readFileSync(
10+
path.join(process.cwd(), '/test/unit/fixtures/switch-dimension.yml'),
11+
'utf8'
12+
);
13+
const { metaTransformer, compiler } = prepareYamlCompiler(modelContent);
14+
await compiler.compile();
15+
16+
const cube = metaTransformer.cubes[0];
17+
const numberDim = cube.config.dimensions.find((d) => d.name === 'orders.number');
18+
const statusDim = cube.config.dimensions.find((d) => d.name === 'orders.status');
19+
const currencyDim = cube.config.dimensions.find((d) => d.name === 'orders.currency');
20+
21+
expect(numberDim.type).toBe('number');
22+
expect(statusDim.type).toBe('string');
23+
expect(currencyDim.type).toBe('string');
24+
});
25+
});

0 commit comments

Comments
 (0)