Skip to content

Commit 25bcfd8

Browse files
KSDaemonmarianore-muttdata
authored andcommitted
fix(schema-compiler): Fix incorrect transpilation of yaml models (cube-js#9465)
1 parent 3f39c09 commit 25bcfd8

File tree

2 files changed

+83
-23
lines changed

2 files changed

+83
-23
lines changed

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,12 @@ export class YamlCompiler {
127127
private transformYamlCubeObj(cubeObj, errorsReport: ErrorReporter) {
128128
camelizeCube(cubeObj);
129129

130-
if (cubeObj.measures) {
131-
cubeObj.measures = this.yamlArrayToObj(cubeObj.measures, 'measure', errorsReport);
132-
}
133-
134-
if (cubeObj.dimensions) {
135-
cubeObj.dimensions = this.yamlArrayToObj(cubeObj.dimensions, 'dimension', errorsReport);
136-
}
137-
138-
if (cubeObj.segments) {
139-
cubeObj.segments = this.yamlArrayToObj(cubeObj.segments, 'segment', errorsReport);
140-
}
141-
142-
if (cubeObj.preAggregations) {
143-
cubeObj.preAggregations = this.yamlArrayToObj(cubeObj.preAggregations, 'preAggregation', errorsReport);
144-
}
145-
146-
if (cubeObj.joins) {
147-
cubeObj.joins = this.yamlArrayToObj(cubeObj.joins, 'join', errorsReport);
148-
}
149-
150-
if (cubeObj.hierarchies) {
151-
cubeObj.hierarchies = this.yamlArrayToObj(cubeObj.hierarchies, 'hierarchies', errorsReport);
152-
}
130+
cubeObj.measures = this.yamlArrayToObj(cubeObj.measures || [], 'measure', errorsReport);
131+
cubeObj.dimensions = this.yamlArrayToObj(cubeObj.dimensions || [], 'dimension', errorsReport);
132+
cubeObj.segments = this.yamlArrayToObj(cubeObj.segments || [], 'segment', errorsReport);
133+
cubeObj.preAggregations = this.yamlArrayToObj(cubeObj.preAggregations || [], 'preAggregation', errorsReport);
134+
cubeObj.joins = this.yamlArrayToObj(cubeObj.joins || [], 'join', errorsReport);
135+
cubeObj.hierarchies = this.yamlArrayToObj(cubeObj.hierarchies || [], 'hierarchies', errorsReport);
153136

154137
return this.transpileYaml(cubeObj, [], cubeObj.name, errorsReport);
155138
}

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,83 @@ describe('Yaml Schema Testing', () => {
128128
}
129129
});
130130

131+
it('empty (null) dimensions', async () => {
132+
const { compiler } = prepareYamlCompiler(
133+
`cubes:
134+
- name: Users
135+
sql: SELECT * FROM e2e.users
136+
dimensions:
137+
`
138+
);
139+
140+
await compiler.compile();
141+
});
142+
143+
it('empty (null) measures', async () => {
144+
const { compiler } = prepareYamlCompiler(
145+
`cubes:
146+
- name: Users
147+
sql: SELECT * FROM e2e.users
148+
measures:
149+
`
150+
);
151+
152+
await compiler.compile();
153+
});
154+
155+
it('empty (null) segments', async () => {
156+
const { compiler } = prepareYamlCompiler(
157+
`cubes:
158+
- name: Users
159+
sql: SELECT * FROM e2e.users
160+
segments:
161+
`
162+
);
163+
164+
await compiler.compile();
165+
});
166+
167+
it('empty (null) preAggregations', async () => {
168+
const { compiler } = prepareYamlCompiler(
169+
`cubes:
170+
- name: Users
171+
sql: SELECT * FROM e2e.users
172+
dimensions: []
173+
measures: []
174+
segments: []
175+
preAggregations:
176+
joins: []
177+
hierarchies: []
178+
`
179+
);
180+
181+
await compiler.compile();
182+
});
183+
184+
it('empty (null) joins', async () => {
185+
const { compiler } = prepareYamlCompiler(
186+
`cubes:
187+
- name: Users
188+
sql: SELECT * FROM e2e.users
189+
joins:
190+
`
191+
);
192+
193+
await compiler.compile();
194+
});
195+
196+
it('empty (null) hierarchies', async () => {
197+
const { compiler } = prepareYamlCompiler(
198+
`cubes:
199+
- name: Users
200+
sql: SELECT * FROM e2e.users
201+
hierarchies:
202+
`
203+
);
204+
205+
await compiler.compile();
206+
});
207+
131208
it('unnamed measure', async () => {
132209
const { compiler } = prepareYamlCompiler(
133210
`cubes:

0 commit comments

Comments
 (0)