Skip to content

Commit

Permalink
feat: Add meta property for cube definition (#7327) Thanks @mharrisb1 !
Browse files Browse the repository at this point in the history
* feat: include meta property for cube schema

* feat: add support for null and number types in YAML transpilation

* chore: add test for cube meta

* chore(docs): add meta field to cube and view reference

* fix: only allow null values in meta children

* fix: unnamed dimension

* fix: remove support for nulls in meta

* chore: revert removal of support for nulls in meta

* chore: add back null type support within `meta`

* chore(docs): add back docs

---------

Co-authored-by: Pavel Tiunov <[email protected]>
  • Loading branch information
mharrisb1 and paveltiunov authored Dec 12, 2023
1 parent e575d07 commit 0ea12c4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/pages/reference/data-model/cube.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,33 @@ cubes:
</CodeTabs>
### meta
Custom metadata. Can be used to pass any information to the frontend.
<CodeTabs>
```javascript
cube(`orders`, {
sql_table: `orders`,
title: `Product Orders`,
meta: {
any: `value`,
}
});
```

```yaml
cubes:
- name: orders
sql_table: orders
title: Product Orders
meta:
any: value
```
</CodeTabs>
### extends
You can extend cubes in order to reuse all declared members of a cube. In the
Expand Down
23 changes: 23 additions & 0 deletions docs/pages/reference/data-model/view.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,29 @@ views:
</CodeTabs>
### meta
Custom metadata. Can be used to pass any information to the frontend.
<CodeTabs>
```javascript
view(`active_users`, {
meta: {
any: "value",
}
});
```

```yaml
views:
- name: active_users
meta:
any: value
```
</CodeTabs>
### `cubes`

Use `cubes` parameter in view to include exposed cubes in bulk. You can build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class CubeToMetaTransformer {
public: isCubeVisible,
description: cube.description,
connectedComponent: this.joinGraph.connectedComponents()[cube.name],
meta: cube.meta,
measures: R.compose(
R.map((nameToMetric) => ({
...this.measureConfig(cube.name, cubeTitle, nameToMetric),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ const baseSchema = {
rewriteQueries: Joi.boolean().strict(),
shown: Joi.boolean().strict(),
public: Joi.boolean().strict(),
meta: Joi.any(),
joins: Joi.object().pattern(identifierRegex, Joi.object().keys({
sql: Joi.func().required(),
relationship: Joi.any().valid(
Expand Down
4 changes: 4 additions & 0 deletions packages/cubejs-schema-compiler/src/compiler/YamlCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export class YamlCompiler {
return this.extractProgramBodyIfNeeded(ast);
} else if (typeof obj === 'boolean') {
return t.booleanLiteral(obj);
} else if (typeof obj === 'number') {
return t.numericLiteral(obj);
} else if (obj === null && propertyPath.includes('meta')) {
return t.nullLiteral();
}

if (typeof obj === 'object' && obj !== null) {
Expand Down
32 changes: 32 additions & 0 deletions packages/cubejs-schema-compiler/test/unit/yaml-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,36 @@ describe('Yaml Schema Testing', () => {
expect(e.message).toContain('name isn\'t defined for dimension: ');
}
});

it('accepts cube meta', async () => {
const { compiler } = prepareYamlCompiler(
`
cubes:
- name: Users
sql: SELECT * FROM e2e.users
meta:
scalars:
example_string: "foo"
example_integer: 1
example_float: 1.0
example_boolean: true
example_null: null
sequence:
- 1
- 2
- 3
mixed_sequence:
- 1
- "foo"
- 3
dimensions:
- name: id
sql: id
type: number
primaryKey: true
`
);

await compiler.compile();
});
});

0 comments on commit 0ea12c4

Please sign in to comment.