Skip to content

Commit

Permalink
fix(schema-compiler): views sorting (#8228)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilev-alex committed May 2, 2024
1 parent 87b8504 commit 50b459a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/cubejs-schema-compiler/src/compiler/CubeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ export class CubeEvaluator extends CubeSymbols {

public compile(cubes: any[], errorReporter: ErrorReporter) {
super.compile(cubes, errorReporter);
const validCubes = this.cubeList.filter(cube => this.cubeValidator.isCubeValid(cube)).sort(a => (a.isView ? 1 : 0));
const validCubes = this.cubeList.filter(cube => this.cubeValidator.isCubeValid(cube)).sort((a, b) => {
if (a.isView) {
return 1;
} else if (!a.isView && !b.isView) {
return 0;
} else {
return -1;
}
});

for (const cube of validCubes) {
this.evaluatedCubes[cube.name] = this.prepareCube(cube, errorReporter);
Expand Down
48 changes: 47 additions & 1 deletion packages/cubejs-schema-compiler/test/unit/hierarchies.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { prepareYamlCompiler } from './PrepareCompiler';

describe('Cube hierarchies', () => {
it.only('includes cube hierarchies', async () => {
it('includes cube hierarchies', async () => {
const { compiler, metaTransformer } = prepareYamlCompiler(`
cubes:
- name: orders
Expand Down Expand Up @@ -117,4 +117,50 @@ views:
const emptyView = metaTransformer.cubes.find(it => it.config.name === 'empty_view');
expect(emptyView.config.hierarchies.length).toBe(0);
});

it('hierarchies defined on a view only', async () => {
const { compiler, metaTransformer } = prepareYamlCompiler(`
views:
- name: orders_view
cubes:
- join_path: orders
includes: "*"
hierarchies:
- name: hello
levels:
- orders.status
cubes:
- name: orders
sql: SELECT * FROM orders
measures:
- name: count
type: count
dimensions:
- name: id
sql: id
type: number
primary_key: true
- name: status
sql: status
type: string
- name: city
sql: city
type: string
`);

await compiler.compile();

const ordersView = metaTransformer.cubes.find(it => it.config.name === 'orders_view');

expect(ordersView.config.hierarchies).toEqual([
{
name: 'hello',
levels: [
'orders.status',
]
},
]);
});
});

0 comments on commit 50b459a

Please sign in to comment.