Skip to content

Commit 9ee00cf

Browse files
committed
duplicate names
1 parent aec801e commit 9ee00cf

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

packages/cubejs-schema-compiler/src/compiler/CubeEvaluator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ export class CubeEvaluator extends CubeSymbols {
217217
const uniqueHierarchyNames = new Set();
218218
if (Array.isArray(cube.hierarchies)) {
219219
cube.hierarchies = cube.hierarchies.map(hierarchy => {
220+
if (uniqueHierarchyNames.has(hierarchy.name)) {
221+
errorReporter.error(`Duplicate hierarchy name '${hierarchy.name}' in cube '${cube.name}'`);
222+
}
220223
uniqueHierarchyNames.add(hierarchy.name);
221224

222225
return ({

packages/cubejs-schema-compiler/src/compiler/CubeValidator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ const cubeSchema = inherit(baseSchema, {
759759
sql: Joi.func(),
760760
sqlTable: Joi.func(),
761761
hierarchies: Joi.array().items(Joi.object().keys({
762-
name: Joi.string().required(),
762+
name: identifier,
763763
title: Joi.string(),
764764
public: Joi.boolean().strict(),
765765
levels: Joi.func()

packages/cubejs-schema-compiler/test/unit/fixtures/hierarchies.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cubes:
2828
type: string
2929
hierarchies:
3030
- name: orders_hierarchy
31+
title: Hello Hierarchy
3132
levels:
3233
- "{CUBE}.status"
3334
- number

packages/cubejs-schema-compiler/test/unit/hierarchies.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Cube hierarchies', () => {
2121
expect(ordersView.config.hierarchies).toEqual([
2222
{
2323
name: 'orders_users_view.orders_hierarchy',
24+
title: 'Hello Hierarchy',
2425
public: true,
2526
levels: [
2627
'orders_users_view.status',
@@ -60,4 +61,45 @@ describe('Cube hierarchies', () => {
6061

6162
await expect(compiler.compile()).rejects.toThrow('Only dimensions can be part of a hierarchy. Please remove the \'count\' member from the \'orders_hierarchy\' hierarchy.');
6263
});
64+
65+
it(('does not accept wrong name'), async () => {
66+
const { compiler } = prepareYamlCompiler(`cubes:
67+
- name: orders
68+
sql_table: orders
69+
dimensions:
70+
- name: id
71+
sql: id
72+
type: number
73+
primary_key: true
74+
75+
hierarchies:
76+
- name: hello wrong name
77+
levels:
78+
- id
79+
`);
80+
81+
await expect(compiler.compile()).rejects.toThrow('with value "hello wrong name" fails to match the identifier pattern');
82+
});
83+
84+
it(('duplicated hierarchy'), async () => {
85+
const { compiler } = prepareYamlCompiler(`cubes:
86+
- name: orders
87+
sql_table: orders
88+
dimensions:
89+
- name: id
90+
sql: id
91+
type: number
92+
primary_key: true
93+
94+
hierarchies:
95+
- name: test_hierarchy
96+
levels:
97+
- id
98+
- name: test_hierarchy
99+
levels:
100+
- id
101+
`);
102+
103+
await expect(compiler.compile()).rejects.toThrow('Duplicate hierarchy name \'test_hierarchy\' in cube \'orders\'');
104+
});
63105
});

0 commit comments

Comments
 (0)