Skip to content

Commit

Permalink
docs: Tiny updates (#8912)
Browse files Browse the repository at this point in the history
* Add a link to Atlas BI Connector deprecation

* Fix join relationships. Closes #8758

* Add an example of multiple primary keys
  • Loading branch information
igorlukanin authored Nov 5, 2024
1 parent 4153e4d commit befb2f8
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 17 deletions.
13 changes: 13 additions & 0 deletions docs/pages/product/configuration/data-sources/mongodb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ redirect_from:

# MongoDB

[MongoDB](https://www.mongodb.com) is a popular document database. It can be
accessed using SQL via the [MongoDB Connector for BI][link-bi-connector], also
known as _BI Connector_.

<CommunitySupportedDriver dataSource="MongoDB" />

<WarningBox>

BI Connector for MongoDB Atlas, cloud-based MongoDB service, is approaching
[end-of-life](https://www.mongodb.com/docs/atlas/bi-connection/#std-label-bi-connection).
It will be deprecated and no longer supported in June 2025.

</WarningBox>

## Prerequisites

<InfoBox>
Expand Down Expand Up @@ -113,3 +125,4 @@ Database][ref-recipe-enable-ssl].
/guides/recipes/data-sources/using-ssl-connections-to-data-source
[ref-schema-ref-types-formats-countdistinctapprox]: /reference/data-model/types-and-formats#count_distinct_approx
[self-preaggs-batching]: #batching
[link-bi-connector]: https://www.mongodb.com/docs/bi-connector/current/
5 changes: 5 additions & 0 deletions docs/pages/product/data-modeling/concepts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ cubes:
</CodeTabs>
Note that the `id` dimension is defined as a [primary key][ref-ref-primary-key].
It is also possible to have more than one primary key dimension in a cube if
you'd like them all to be parts of a composite key.

[The `line_items` table](#top) also has a couple of dimensions which can be
represented as follows:

Expand Down Expand Up @@ -729,5 +733,6 @@ Pre-Aggregations][ref-caching-preaggs-intro].
[ref-pmc]: /product/deployment/cloud/deployment-types#production-multi-cluster
[ref-ref-time-dimensions]: /reference/data-model/types-and-formats#time-1
[ref-ref-dimension-granularities]: /reference/data-model/dimensions#granularities
[ref-ref-primary-key]: /reference/data-model/dimensions#primary_key
[ref-custom-granularity-recipe]: /guides/recipes/data-modeling/custom-granularity
[ref-proxy-granularity]: /product/data-modeling/concepts/calculated-members#time-dimension-granularity
24 changes: 12 additions & 12 deletions docs/pages/product/data-modeling/concepts/working-with-joins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,6 @@ association in the database, we need to create an associative cube
`post_topics`, and declare the relationships from it to `topics` cube and from
`posts` to `post_topics`.

<InfoBox>

The following example uses the `one_to_many` relationship on the `post_topics`
cube; this causes the direction of joins to be `posts → post_topics → topics`.
[Read more about direction of joins here][self-join-direction].

</InfoBox>

<CodeTabs>

```javascript
Expand All @@ -263,7 +255,7 @@ cube(`posts`, {

joins: {
post_topics: {
relationship: `many_to_one`,
relationship: `one_to_many`,
sql: `${CUBE}.id = ${post_topics.post_id}`,
},
},
Expand All @@ -286,7 +278,7 @@ cube(`post_topics`, {

joins: {
topic: {
relationship: `one_to_many`,
relationship: `many_to_one`,
sql: `${CUBE}.topic_id = ${topics.id}`,
},
},
Expand All @@ -307,7 +299,7 @@ cubes:

joins:
- name: post_topics
relationship: many_to_one
relationship: one_to_many
sql: "{CUBE}.id = {post_topics.post_id}"

- name: topics
Expand All @@ -324,7 +316,7 @@ cubes:

joins:
- name: topic
relationship: one_to_many
relationship: many_to_one
sql: "{CUBE}.topic_id = {topics.id}"

dimensions:
Expand All @@ -335,6 +327,14 @@ cubes:
</CodeTabs>
<InfoBox>
The following example uses the `many_to_one` relationship on the `post_topics`
cube; this causes the direction of joins to be `posts → post_topics → topics`.
[Read more about direction of joins here][self-join-direction].

</InfoBox>

In scenarios where a table doesn't define a primary key, one can be generated
using SQL:

Expand Down
90 changes: 85 additions & 5 deletions docs/pages/reference/data-model/dimensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,18 @@ cubes:
### `primary_key`

Specify which dimension is a primary key for a cube. The default value is
Specify if a dimension is a primary key for a cube. The default value is
`false`.

A primary key is used to make [joins][ref-schema-ref-joins] work properly.

<WarningBox>
<InfoBox>

Setting `primary_key` to `true` will change the default value of `public`
parameter to `false`. If you still want `public` to be `true`, set it manually.
Setting `primary_key` to `true` will change the default value of the [`public`
parameter](#public) to `false`. If you still want `public` to be `true`, set it
explicitly.

</WarningBox>
</InfoBox>

<CodeTabs>

Expand Down Expand Up @@ -306,6 +307,85 @@ cubes:
</CodeTabs>
It is possible to have more than one primary key dimension in a cube if you'd
like them all to be parts of a composite key:
<CodeTabs>
```javascript
cube(`products`, {
sql: `
SELECT 1 AS column_a, 1 AS column_b UNION ALL
SELECT 2 AS column_a, 1 AS column_b UNION ALL
SELECT 1 AS column_a, 2 AS column_b UNION ALL
SELECT 2 AS column_a, 2 AS column_b
`,

dimensions: {
composite_key_a: {
sql: `column_a`,
type: `number`,
primary_key: true
},

composite_key_b: {
sql: `column_b`,
type: `number`,
primary_key: true
}
},

measures: {
count: {
type: `count`
}
}
})
```

```yaml
cubes:
- name: products
sql: >
SELECT 1 AS column_a, 1 AS column_b UNION ALL
SELECT 2 AS column_a, 1 AS column_b UNION ALL
SELECT 1 AS column_a, 2 AS column_b UNION ALL
SELECT 2 AS column_a, 2 AS column_b
dimensions:
- name: composite_key_a
sql: column_a
type: number
primary_key: true

- name: composite_key_b
sql: column_b
type: number
primary_key: true

measures:
- name: count
type: count
```
</CodeTabs>
Querying the `count` measure of the cube shown above will generate the following
SQL to the upstream data source:

```sql
SELECT
count(
CAST("product".column_a as TEXT) || CAST("product".column_b as TEXT)
) "product__count"
FROM (
SELECT 1 AS column_a, 1 AS column_b UNION ALL
SELECT 2 AS column_a, 1 AS column_b UNION ALL
SELECT 1 AS column_a, 2 AS column_b UNION ALL
SELECT 2 AS column_a, 2 AS column_b
) AS "product"
```

### `propagate_filters_to_sub_query`

When this statement is set to `true`, the filters applied to the query will be
Expand Down

0 comments on commit befb2f8

Please sign in to comment.