Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -329,6 +329,28 @@ Array [
]
`;

exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.js (with additions) 13`] = `
Object {
"order_users": Object {
"relationship": "belongsTo",
"sql": [Function],
},
}
`;

exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.js (with additions) 14`] = `
Object {
"line_items": Object {
"relationship": "hasMany",
"sql": [Function],
},
"order_users": Object {
"relationship": "belongsTo",
"sql": [Function],
},
}
`;

exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.yml (with additions) 1`] = `
Object {
"completed_at": Object {
Expand Down Expand Up @@ -702,6 +724,28 @@ Array [
]
`;

exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.yml (with additions) 13`] = `
Object {
"order_users": Object {
"relationship": "belongsTo",
"sql": [Function],
},
}
`;

exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.yml (with additions) 14`] = `
Object {
"line_items": Object {
"relationship": "hasMany",
"sql": [Function],
},
"order_users": Object {
"relationship": "belongsTo",
"sql": [Function],
},
}
`;

exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.js (with additions) 1`] = `
Object {
"completed_at": Object {
Expand Down Expand Up @@ -1003,6 +1047,28 @@ Array [
]
`;

exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.js (with additions) 13`] = `
Object {
"order_users": Object {
"relationship": "belongsTo",
"sql": [Function],
},
}
`;

exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.js (with additions) 14`] = `
Object {
"line_items": Object {
"relationship": "hasMany",
"sql": [Function],
},
"order_users": Object {
"relationship": "belongsTo",
"sql": [Function],
},
}
`;

exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.yml (with additions) 1`] = `
Object {
"completed_at": Object {
Expand Down Expand Up @@ -1348,6 +1414,28 @@ Array [
]
`;

exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.yml (with additions) 13`] = `
Object {
"order_users": Object {
"relationship": "belongsTo",
"sql": [Function],
},
}
`;

exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.yml (with additions) 14`] = `
Object {
"line_items": Object {
"relationship": "hasMany",
"sql": [Function],
},
"order_users": Object {
"relationship": "belongsTo",
"sql": [Function],
},
}
`;

exports[`Schema Testing Views allows to override \`title\`, \`description\`, \`meta\`, and \`format\` on includes members 1`] = `
Object {
"accessPolicy": undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cubes:
- name: line_items
sql_table: public.line_items
public: false

dimensions:
- name: id
sql: id
type: number
primary_key: true
public: true

- name: product_id
sql: product_id
type: number

- name: order_id
sql: order_id
type: number

# - name: quantity
# sql: quantity
# type: number

- name: price
sql: price
type: number

measures:
- name: count
type: count

- name: sum_price
sql: "{price}"
type: sum
public: false
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ cube('ordersExt', {
},
},

joins: {
line_items: {
relationship: 'one_to_many',
sql: `${CUBE}.id = ${line_items}.order_id`,
}
},

segments: {
anotherStatus: {
description: 'Just another one',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ cubes:
sql: status
type: count_distinct

joins:
- name: line_items
sql: '{CUBE.id} = {line_items.order_id}'
relationship: one_to_many

segments:
- name: anotherStatus
description: Just another one
Expand Down
34 changes: 33 additions & 1 deletion packages/cubejs-schema-compiler/test/unit/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import { prepareCompiler, prepareJsCompiler, prepareYamlCompiler } from './PrepareCompiler';
import { createCubeSchema, createCubeSchemaWithCustomGranularitiesAndTimeShift, createCubeSchemaWithAccessPolicy } from './utils';

const CUBE_COMPONENTS = ['dimensions', 'measures', 'segments', 'hierarchies', 'preAggregations', 'accessPolicy'];
const CUBE_COMPONENTS = ['dimensions', 'measures', 'segments', 'hierarchies', 'preAggregations', 'accessPolicy', 'joins'];

describe('Schema Testing', () => {
const schemaCompile = async () => {
Expand Down Expand Up @@ -807,6 +807,10 @@ describe('Schema Testing', () => {
path.join(process.cwd(), '/test/unit/fixtures/order_users.yml'),
'utf8'
);
const orderLineItems = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/line_items.yml'),
'utf8'
);
const ordersExt = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/orders_ext.js'),
'utf8'
Expand All @@ -825,6 +829,10 @@ describe('Schema Testing', () => {
content: orderUsers,
fileName: 'order_users.yml',
},
{
content: orderLineItems,
fileName: 'line_items.yml',
},
]);
await compiler.compile();
compiler.throwIfAnyErrors();
Expand Down Expand Up @@ -887,6 +895,10 @@ describe('Schema Testing', () => {
path.join(process.cwd(), '/test/unit/fixtures/order_users.yml'),
'utf8'
);
const orderLineItems = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/line_items.yml'),
'utf8'
);
const ordersExt = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/orders_ext.yml'),
'utf8'
Expand All @@ -905,6 +917,10 @@ describe('Schema Testing', () => {
content: orderUsers,
fileName: 'order_users.yml',
},
{
content: orderLineItems,
fileName: 'line_items.yml',
},
]);
await compiler.compile();
compiler.throwIfAnyErrors();
Expand Down Expand Up @@ -967,6 +983,10 @@ describe('Schema Testing', () => {
path.join(process.cwd(), '/test/unit/fixtures/order_users.yml'),
'utf8'
);
const orderLineItems = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/line_items.yml'),
'utf8'
);
const ordersExt = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/orders_ext.yml'),
'utf8'
Expand All @@ -985,6 +1005,10 @@ describe('Schema Testing', () => {
content: orderUsers,
fileName: 'order_users.yml',
},
{
content: orderLineItems,
fileName: 'line_items.yml',
},
]);
await compiler.compile();
compiler.throwIfAnyErrors();
Expand Down Expand Up @@ -1043,6 +1067,10 @@ describe('Schema Testing', () => {
path.join(process.cwd(), '/test/unit/fixtures/order_users.yml'),
'utf8'
);
const orderLineItems = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/line_items.yml'),
'utf8'
);
const ordersExt = fs.readFileSync(
path.join(process.cwd(), '/test/unit/fixtures/orders_ext.js'),
'utf8'
Expand All @@ -1061,6 +1089,10 @@ describe('Schema Testing', () => {
content: orderUsers,
fileName: 'order_users.yml',
},
{
content: orderLineItems,
fileName: 'line_items.yml',
},
]);
await compiler.compile();
compiler.throwIfAnyErrors();
Expand Down
Loading