Skip to content

Commit

Permalink
chore: ecom schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Nov 27, 2023
1 parent de1bf48 commit 47bd58a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 39 deletions.
41 changes: 2 additions & 39 deletions packages/cubejs-schema-compiler/test/unit/pre-aggregations.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { prepareCompiler, prepareYamlCompiler } from './PrepareCompiler';
import { createSchemaYaml } from './utils';
import { createECommerceSchema, createSchemaYaml } from './utils';
import { PostgresQuery } from '../../src';

describe('pre-aggregations', () => {
Expand Down Expand Up @@ -95,44 +95,7 @@ describe('pre-aggregations', () => {
// @link https://github.com/cube-js/cube/issues/6623
it('view and pre-aggregation granularity', async () => {
const { compiler, cubeEvaluator, joinGraph } = prepareYamlCompiler(
createSchemaYaml({
cubes: [{
name: 'orders',
sql_table: 'orders',
measures: [{
name: 'count',
type: 'count',
}],
dimensions: [{
name: 'created_at',
sql: 'created_at',
type: 'time',
}],
preAggregations: [{
name: 'orders_by_day_with_day',
measures: ['count'],
timeDimension: 'created_at',
granularity: 'day',
partition_granularity: 'day',
build_range_start: {
sql: 'SELECT NOW() - INTERVAL \'1000 day\'',
},
build_range_end: {
sql: 'SELECT NOW()'
},
}]
}],
views: [{
name: 'orders_view',
cubes: [{
join_path: 'orders',
includes: [
'created_at',
'count'
]
}]
}]
})
createSchemaYaml(createECommerceSchema())
);

await compiler.compile();
Expand Down
52 changes: 52 additions & 0 deletions packages/cubejs-schema-compiler/test/unit/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import YAML from 'js-yaml';

interface CreateCubeSchemaOptions {
name: string,
publicly?: boolean,
Expand Down Expand Up @@ -69,6 +71,15 @@ export function createCubeSchema({ name, refreshKey = '', preAggregations = '',
`;
}

export type CreateSchemaOptions = {
cubes?: unknown[],
views?: unknown[]
};

export function createSchemaYaml(schema: CreateSchemaOptions): string {
return YAML.dump(schema);
}

export function createCubeSchemaYaml({ name, sqlTable }: CreateCubeSchemaOptions): string {
return `
cubes:
Expand Down Expand Up @@ -98,6 +109,47 @@ export function createCubeSchemaYaml({ name, sqlTable }: CreateCubeSchemaOptions
`;
}

export function createECommerceSchema() {
return {
cubes: [{
name: 'orders',
sql_table: 'orders',
measures: [{
name: 'count',
type: 'count',
}],
dimensions: [{
name: 'created_at',
sql: 'created_at',
type: 'time',
}],
preAggregations: [{
name: 'orders_by_day_with_day',
measures: ['count'],
timeDimension: 'created_at',
granularity: 'day',
partition_granularity: 'day',
build_range_start: {
sql: 'SELECT NOW() - INTERVAL \'1000 day\'',
},
build_range_end: {
sql: 'SELECT NOW()'
},
}]
}],
views: [{
name: 'orders_view',
cubes: [{
join_path: 'orders',
includes: [
'created_at',
'count'
]
}]
}]
};
}

/**
* Returns joined test cubes schema. Schema looks like: A -< B -< C >- D >- E.
* The original data set can be found under the link.
Expand Down

0 comments on commit 47bd58a

Please sign in to comment.