Skip to content

Commit 0ea12c4

Browse files
feat: Add meta property for cube definition (#7327) Thanks @mharrisb1 !
* 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]>
1 parent e575d07 commit 0ea12c4

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

docs/pages/reference/data-model/cube.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,33 @@ cubes:
158158
159159
</CodeTabs>
160160
161+
### meta
162+
163+
Custom metadata. Can be used to pass any information to the frontend.
164+
165+
<CodeTabs>
166+
167+
```javascript
168+
cube(`orders`, {
169+
sql_table: `orders`,
170+
title: `Product Orders`,
171+
meta: {
172+
any: `value`,
173+
}
174+
});
175+
```
176+
177+
```yaml
178+
cubes:
179+
- name: orders
180+
sql_table: orders
181+
title: Product Orders
182+
meta:
183+
any: value
184+
```
185+
186+
</CodeTabs>
187+
161188
### extends
162189
163190
You can extend cubes in order to reuse all declared members of a cube. In the

docs/pages/reference/data-model/view.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,29 @@ views:
154154
155155
</CodeTabs>
156156
157+
### meta
158+
159+
Custom metadata. Can be used to pass any information to the frontend.
160+
161+
<CodeTabs>
162+
163+
```javascript
164+
view(`active_users`, {
165+
meta: {
166+
any: "value",
167+
}
168+
});
169+
```
170+
171+
```yaml
172+
views:
173+
- name: active_users
174+
meta:
175+
any: value
176+
```
177+
178+
</CodeTabs>
179+
157180
### `cubes`
158181

159182
Use `cubes` parameter in view to include exposed cubes in bulk. You can build

packages/cubejs-schema-compiler/src/compiler/CubeToMetaTransformer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class CubeToMetaTransformer {
5151
public: isCubeVisible,
5252
description: cube.description,
5353
connectedComponent: this.joinGraph.connectedComponents()[cube.name],
54+
meta: cube.meta,
5455
measures: R.compose(
5556
R.map((nameToMetric) => ({
5657
...this.measureConfig(cube.name, cubeTitle, nameToMetric),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ const baseSchema = {
492492
rewriteQueries: Joi.boolean().strict(),
493493
shown: Joi.boolean().strict(),
494494
public: Joi.boolean().strict(),
495+
meta: Joi.any(),
495496
joins: Joi.object().pattern(identifierRegex, Joi.object().keys({
496497
sql: Joi.func().required(),
497498
relationship: Joi.any().valid(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ export class YamlCompiler {
169169
return this.extractProgramBodyIfNeeded(ast);
170170
} else if (typeof obj === 'boolean') {
171171
return t.booleanLiteral(obj);
172+
} else if (typeof obj === 'number') {
173+
return t.numericLiteral(obj);
174+
} else if (obj === null && propertyPath.includes('meta')) {
175+
return t.nullLiteral();
172176
}
173177

174178
if (typeof obj === 'object' && obj !== null) {

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,36 @@ describe('Yaml Schema Testing', () => {
110110
expect(e.message).toContain('name isn\'t defined for dimension: ');
111111
}
112112
});
113+
114+
it('accepts cube meta', async () => {
115+
const { compiler } = prepareYamlCompiler(
116+
`
117+
cubes:
118+
- name: Users
119+
sql: SELECT * FROM e2e.users
120+
meta:
121+
scalars:
122+
example_string: "foo"
123+
example_integer: 1
124+
example_float: 1.0
125+
example_boolean: true
126+
example_null: null
127+
sequence:
128+
- 1
129+
- 2
130+
- 3
131+
mixed_sequence:
132+
- 1
133+
- "foo"
134+
- 3
135+
dimensions:
136+
- name: id
137+
sql: id
138+
type: number
139+
primaryKey: true
140+
`
141+
);
142+
143+
await compiler.compile();
144+
});
113145
});

0 commit comments

Comments
 (0)