Skip to content

Commit 424f534

Browse files
docs: Extract naming conventions and introduce name parameters in r… (#6484)
* docs: Extract naming conventions and introduce `name` parameters in reference docs * Update docs/content/Schema/Fundamentals/Syntax.mdx Co-authored-by: Hassan Khan <[email protected]> * Update docs/content/Schema/Fundamentals/Syntax.mdx Co-authored-by: Hassan Khan <[email protected]> * Update docs/content/Schema/Fundamentals/Syntax.mdx * Update docs/content/Schema/Fundamentals/Syntax.mdx --------- Co-authored-by: Hassan Khan <[email protected]>
1 parent 0dc2d4b commit 424f534

File tree

9 files changed

+250
-141
lines changed

9 files changed

+250
-141
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
title: Syntax
3+
permalink: /data-modeling/syntax
4+
category: Data Modeling
5+
subCategory: Fundamentals
6+
menuOrder: 12
7+
redirect_from:
8+
- /schema/fundamentals/working-with-yaml
9+
- /schema/getting-started/yaml
10+
---
11+
12+
Entities within the data model (e.g., cubes, views, measures, dimensions, etc.)
13+
should follow [naming conventions][self-naming] and be defined using a supported
14+
[syntax][self-syntax].
15+
16+
## Naming
17+
18+
Common rules apply to names of entities within the data model. All names must:
19+
20+
- start with a letter
21+
- consist of letters, numbers, and underscore (`_`) symbols only
22+
23+
It is also recommended that names use [snake
24+
case][wiki-snake-case]<!-- and follow the style guide -->.
25+
26+
Good examples of names:
27+
28+
- `orders`, `stripe_invoices`, or `base_payments` (cubes)
29+
- `opportunities`, `cloud_accounts`, or `arr` (views)
30+
- `count`, `avg_price`, or `total_amount_shipped` (measures)
31+
- `name`, `is_shipped`, or `created_at` (dimensions)
32+
- `main`, `orders_by_status`, or `lambda_invoices` (pre-aggregations)
33+
34+
## Model syntax
35+
36+
Cube supports two ways to define data models: with [YAML][wiki-yaml] or
37+
JavaScript syntax.
38+
39+
<InfoBox>
40+
41+
YAML syntax is supported since v0.31.0.
42+
43+
</InfoBox>
44+
45+
YAML data models are placed in `.yml` files in the `schema/` folder, whereas
46+
JavaScript data models are placed in `.js` files in the same folder.
47+
48+
It's recommended to use YAML syntax by default; opt to JavaScript syntax when
49+
you need to have a
50+
[dynamic data model](/schema/advanced/dynamic-schema-creation).
51+
52+
<CodeTabs>
53+
54+
```javascript
55+
cube(`orders`, {
56+
sql: `
57+
SELECT * FROM
58+
orders,
59+
line_items
60+
WHERE
61+
orders.id = line_items.order_id
62+
`,
63+
});
64+
```
65+
66+
```yaml
67+
cubes:
68+
- name: orders
69+
sql: >
70+
SELECT * FROM
71+
orders,
72+
line_items
73+
WHERE
74+
orders.id = line_items.order_id
75+
```
76+
77+
</CodeTabs>
78+
79+
### Syntax comparison
80+
81+
YAML syntax is very similar to JavaScript syntax, with a few key differences:
82+
83+
- In YAML syntax, cubes, views, and context variables should be wrapped in `{}`,
84+
e.g., `{FILTER_PARAMS.Orders.created_at.filter('created_at')}`.
85+
- In YAML syntax, string values only need to have quotes around them if they
86+
contain special values, e.g., `"{CUBE}.user_id = {Users.id}"`.
87+
88+
[self-naming]: #naming
89+
[self-syntax]: #code-syntax
90+
[wiki-snake-case]: https://en.wikipedia.org/wiki/Snake_case
91+
[wiki-yaml]: https://en.wikipedia.org/wiki/YAML

docs/content/Schema/Fundamentals/Working-with-YAML.mdx

Lines changed: 0 additions & 67 deletions
This file was deleted.

docs/content/Schema/Reference/cube.mdx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,6 @@ cubes:
8282
8383
</CodeTabs>
8484
85-
## Naming
86-
87-
There are certain rules to follow for a cube and cube member names:
88-
89-
- Be unique within the project
90-
- Start with a letter
91-
- Consist of numbers, letters and `_`
92-
93-
As a convention, cube names start with upper case letters and member names with
94-
lower case letters. As in JavaScript, [camel case][wiki-camelcase] is used for
95-
multi-word cube and member names.
96-
9785
## Members and Referencing
9886
9987
Cubes have three types of members: measures, dimensions and segments. Each
@@ -228,6 +216,28 @@ cube(`Contacts`, {
228216

229217
## Parameters
230218

219+
### <--{"id" : "Parameters"}--> name
220+
221+
The `name` parameter serves as the identifier of a cube. It must be unique among
222+
_all cubes and views_ within a deployment and follow the [naming
223+
conventions][ref-naming].
224+
225+
<CodeTabs>
226+
227+
```javascript
228+
cube(`orders`, {
229+
sql_table: orders,
230+
});
231+
```
232+
233+
```yaml
234+
cubes:
235+
- name: orders
236+
sql_table: orders
237+
```
238+
239+
</CodeTabs>
240+
231241
### <--{"id" : "Parameters"}--> dataSource
232242
233243
Each cube in schema can have its own `dataSource` name to support scenarios
@@ -1043,4 +1053,4 @@ cubes:
10431053
[ref-restapi-meta]: /rest-api#v-1-meta
10441054
[ref-restapi-sql]: /rest-api#v-1-sql
10451055
[ref-sec-ctx]: /security/context
1046-
[wiki-camelcase]: https://en.wikipedia.org/wiki/Camel_case
1056+
[ref-naming]: /data-modeling/syntax#naming

docs/content/Schema/Reference/dimensions.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ have dimensions like `country`, `age`, `occupation`, etc.
1616

1717
Any dimension should have the following properties: `name`, `sql` and `type`.
1818

19-
## Naming
19+
## Parameters
2020

21-
You can name a dimension by following the same rules as for measure, so each
22-
name should:
21+
### <--{"id" : "Parameters"}--> name
2322

24-
- Be unique within a cube
25-
- Start with a lowercase letter
26-
- Consist of numbers, letters and `_`
23+
The `name` parameter serves as the identifier of a dimension. It must be unique
24+
among all dimensions, measures, and segments within a cube and follow the
25+
[naming conventions][ref-naming].
2726

2827
<CodeTabs>
2928

3029
```javascript
31-
cube(`Products`, {
30+
cube(`products`, {
3231
dimensions: {
3332
price: {
3433
sql: `price`,
@@ -45,20 +44,20 @@ cube(`Products`, {
4544

4645
```yaml
4746
cubes:
48-
- name: Products
47+
- name: products
48+
4949
dimensions:
5050
- name: price
5151
sql: price
5252
type: number
53+
5354
- name: brand_name
5455
sql: brand_name
5556
type: string
5657
```
5758
5859
</CodeTabs>
5960
60-
## Parameters
61-
6261
### <--{"id" : "Parameters"}--> case
6362
6463
The `case` statement is used to define if/then/else conditions to display data.
@@ -399,3 +398,4 @@ cubes:
399398
/schema/reference/types-and-formats#dimensions-types
400399
[ref-subquery]: /schema/fundamentals/additional-concepts#subquery
401400
[self-subquery]: #sub-query
401+
[ref-naming]: /data-modeling/syntax#naming

docs/content/Schema/Reference/joins.mdx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,40 @@ parameter. Quite frequently, `FULL OUTER JOIN` is used to solve [Data
6161
Blending][ref-schema-data-blenging] or similar problems. In that case, it's best
6262
practice to have a separate cube for such an operation.
6363

64-
## Naming
64+
## Parameters
65+
66+
### <--{"id" : "Parameters"}--> name
6567

66-
The name of a join should match the [name of the external
67-
cube][ref-schema-cube-naming]. For example when a `Products` cube is being
68-
joined on to an `Orders` cube, we would define the join as follows:
68+
The name must match the name of the joined cube and, thus, follow the [naming
69+
conventions][ref-naming].
70+
71+
For example, when the `products` cube is joined on to the `orders` cube, we
72+
would define the join as follows:
6973

7074
<CodeTabs>
7175

7276
```javascript
73-
cube('Orders', {
77+
cube(`orders`, {
7478
joins: {
75-
Products: {
79+
products: {
7680
relationship: `belongsTo`,
77-
sql: `${CUBE.id} = ${Products.orderId}`,
81+
sql: `${CUBE.id} = ${products.order_id}`,
7882
},
7983
},
8084
});
8185
```
8286

8387
```yaml
8488
cubes:
85-
- name: Orders
89+
- name: orders
8690
joins:
87-
- name: Products
91+
- name: products
8892
relationship: belongs_to
89-
sql: "{CUBE.id} = {Products.order_id}"
93+
sql: '{CUBE.id} = {products.order_id}'
9094
```
9195
9296
</CodeTabs>
9397
94-
## Parameters
95-
9698
### <--{"id" : "Parameters"}--> relationship
9799
98100
`relationship` enables you to describe the join relationship between joined
@@ -471,9 +473,9 @@ algorithm][wiki-djikstra-alg] to find join path between cubes given requested
471473
members.
472474

473475
[ref-restapi-query-filter-op-set]: /query-format#set
474-
[ref-schema-cube-naming]: /schema/reference/cube#naming
475476
[ref-schema-fundamentals-join-dir]:
476477
/schema/fundamentals/joins#directions-of-joins
477478
[ref-schema-cube-sql]: /schema/reference/cube#parameters-sql
478479
[ref-schema-data-blenging]: /schema/advanced/data-blending#data-blending
480+
[ref-naming]: /data-modeling/syntax#naming
479481
[wiki-djikstra-alg]: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

docs/content/Schema/Reference/measures.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ aggregation over a certain column in your database table.
1515

1616
Any measure should have the following properties: `name`, `sql` and `type`.
1717

18-
## Naming
18+
## Parameters
1919

20-
When you give a name to a measure, there are certain rules to follow. Each
21-
measure should:
20+
### <--{"id" : "Parameters"}--> name
2221

23-
- Be unique within a cube
24-
- Start with a lowercase letter
25-
- Consist of numbers, letters and `_`
22+
The `name` parameter serves as the identifier of a measure. It must be unique
23+
among all measures, dimensions, and segments within a cube and follow the
24+
[naming conventions][ref-naming].
2625

2726
<CodeTabs>
2827

2928
```javascript
30-
cube(`Orders`, {
29+
cube(`orders`, {
3130
measures: {
3231
count: {
3332
sql: `id`,
@@ -44,20 +43,20 @@ cube(`Orders`, {
4443

4544
```yaml
4645
cubes:
47-
- name: Orders
46+
- name: orders
47+
4848
measures:
4949
- name: count
5050
sql: id
5151
type: count
52+
5253
- name: total_amount
5354
sql: amount
5455
type: sum
5556
```
5657
5758
</CodeTabs>
5859
59-
## Parameters
60-
6160
### <--{"id" : "Parameters"}--> description
6261
6362
You can add details to a measure’s definition via the `description` parameter:
@@ -459,7 +458,7 @@ cubes:
459458
- name: Orders
460459
measures:
461460
- name: purchases_to_created_account_ratio
462-
sql: "{purchases} / {Users.count} * 100.0"
461+
sql: '{purchases} / {Users.count} * 100.0'
463462
type: number
464463
format: percent
465464
```
@@ -474,3 +473,4 @@ join will be created automatically.
474473
[ref-schema-ref-types-formats-measures-formats]:
475474
/schema/reference/types-and-formats#measures-formats
476475
[ref-drilldowns]: /schema/fundamentals/additional-concepts#drilldowns
476+
[ref-naming]: /data-modeling/syntax#naming

0 commit comments

Comments
 (0)