Skip to content

Commit 6f036bc

Browse files
authored
docs: Describe the error message on primary keys (#7096)
1 parent f357a5f commit 6f036bc

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

docs/docs-new/pages/product/data-modeling/reference/dimensions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ cubes:
255255
256256
</CodeTabs>
257257
258-
### primaryKey
258+
### primary_key
259259
260260
Specify which dimension is a primary key for a cube. The default value is
261261
`false`.

docs/docs-new/pages/reference/errors.mdx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,38 @@ on your cubes to hide them from end users.
2222

2323
If you’re building a custom data application, you might use the [`meta` endpoint](/reference/rest-api#v1meta)
2424
of the REST API. It groups cubes into `connectedComponents` to help select those ones
25-
that can be joined together.
25+
that can be joined together.
26+
27+
## `Primary key is required when join is defined`
28+
29+
```
30+
cube_a cube: primary key for 'cube_a' is required when join is defined
31+
in order to make aggregates work properly
32+
```
33+
34+
Error message above indicates that you have a [cube](/product/data-modeling/reference/cube)
35+
with [joins](/product/data-modeling/reference/joins) and
36+
[pre-aggregations](/product/data-modeling/reference/pre-aggregations). However, that cube
37+
doesn't have a primary key.
38+
39+
When generating SQL queries, Cube uses primary keys to avoid fanouts.
40+
A fanout happens when two tables are joined and a single value gets duplicated in the end result,
41+
meaning that some values can be double counted.
42+
43+
**Please define a [primary key](/product/data-modeling/reference/dimensions#primary_key) dimension in this cube to make joins and pre-aggregations work correctly.**
44+
45+
If your data doesn't have a natural primary key, e.g., `id`, you can define a composite
46+
primary key by concatenating most or all of the columns in the table, e.g.:
47+
48+
49+
```yml
50+
cubes:
51+
- name: cube_a
52+
# ...
53+
54+
dimensions:
55+
- name: composite_key
56+
sql: CONCAT(column_a, '-', column_b, '-', column_c)
57+
type: string
58+
primary_key: true
59+
```

0 commit comments

Comments
 (0)