Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class CubeToMetaTransformer {
R.map((nameToDimension) => ({
name: `${cube.name}.${nameToDimension[0]}`,
title: this.title(cubeTitle, nameToDimension),
type: nameToDimension[1].type,
type: this.dimensionDataType(nameToDimension[1].type),
description: nameToDimension[1].description,
shortTitle: this.title(cubeTitle, nameToDimension, true),
suggestFilterValues:
Expand Down Expand Up @@ -197,6 +197,10 @@ export class CubeToMetaTransformer {
return defaultValue;
}

dimensionDataType(dimensionType) {
return dimensionType === 'switch' ? 'string' : dimensionType;
}

measureConfig(cubeName, cubeTitle, nameToMetric) {
const name = `${cubeName}.${nameToMetric[0]}`;
// Support both old 'drillMemberReferences' and new 'drillMembers' keys
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cubes:
- name: orders
sql: SELECT * FROM orders

measures:
- name: count
sql: id
type: count
dimensions:
- name: id
sql: id
type: number
primary_key: true

- name: number
sql: number
type: number

- name: currency
type: switch
values:
- USD
- EUR
- GBP

- name: status
sql: status
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fs from 'fs';
import path from 'path';

import { CubeToMetaTransformer } from 'src/compiler/CubeToMetaTransformer';
import { prepareYamlCompiler } from './PrepareCompiler';

describe('Switch Dimension', () => {
it('Switch dimension meta type', async () => {
const modelContent = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/switch-dimension.yml'),
'utf8'
);
const prepared = prepareYamlCompiler(modelContent);
const { metaTransformer } = prepared;
const { compiler } = prepared;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const prepared = prepareYamlCompiler(modelContent);
const { metaTransformer } = prepared;
const { compiler } = prepared;
const { metaTransformer, compiler } = prepareYamlCompiler(modelContent);

await compiler.compile();

const cube = metaTransformer.cubes[0];
const numberDim = cube.config.dimensions.find((d) => d.name === 'orders.number');
const statusDim = cube.config.dimensions.find((d) => d.name === 'orders.status');
const currencyDim = cube.config.dimensions.find((d) => d.name === 'orders.currency');

expect(numberDim.type).toBe('number');
expect(statusDim.type).toBe('string');
expect(currencyDim.type).toBe('string');
});
});
Loading