Skip to content

Commit 8a84920

Browse files
committed
docs: Join paths and join hints in the data model
1 parent 7dce11d commit 8a84920

File tree

8 files changed

+1194
-145
lines changed

8 files changed

+1194
-145
lines changed

docs/pages/product/apis-integrations/rest-api/query-format.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ format, e.g., `America/Los_Angeles`.
5454
> refresh loops and overall system instability.
5555
- `ungrouped`: If set to `true`, Cube will run an [ungrouped
5656
query][ref-ungrouped-query].
57+
- `joinHints`: Query-time [join hints][ref-join-hints], provided as an array of
58+
two-element arrays of cube names.
5759

5860
```json
5961
{
@@ -681,4 +683,5 @@ refer to its documentation for more examples.
681683
[ref-default-order]: /product/apis-integrations/queries#order
682684
[ref-default-granularities]: /product/data-modeling/concepts#time-dimensions
683685
[ref-custom-granularities]: /product/data-modeling/reference/dimensions#granularities
684-
[wiki-iso-8601]: https://en.wikipedia.org/wiki/ISO_8601
686+
[wiki-iso-8601]: https://en.wikipedia.org/wiki/ISO_8601
687+
[ref-join-hints]: /product/data-modeling/concepts/working-with-joins#join-hints

docs/pages/product/apis-integrations/sql-api/joins.mdx

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
# Joins in the SQL API
2+
13
## Views
24

3-
The best practice to query joins using SQL API is to use views. This is the preferred way of
4-
joining as it provides you control over the joining path for complex use cases.
5-
While BI tools would see the view as a table, in fact, no materialization is done until Cube is queried.
6-
Whenever Cube view is queried through SQL API, Cube tries to maximize member pushdown so only required parts of the view are materialized at query time.
7-
Cube also solves fan and chasm traps based on the dimensions selected in the query, so if measure aggregation types are properly set up, you will see correct results in BI tools even though cubes and views are seen just as tables.
5+
The best practice is to use [views][ref-views] to specify explicit [join
6+
paths][ref-join-paths] for SQL API queries.
7+
8+
While BI tools would see a view as a table, in fact, no materialization is performed
9+
until Cube is queried through the SQL API. At the query time, Cube will try to maximize
10+
member pushdown, so only required parts of the view are materialized at query time.
11+
12+
Cube also solves fan and chasm traps based on the dimensions selected in the query, so
13+
if measure aggregation types are properly set up, you will see correct results in BI tools
14+
even though cubes and views are seen just as tables.
15+
16+
Consider the following data model:
817

918
<CodeTabs>
1019

@@ -33,7 +42,8 @@ view(`orders_users`, {
3342
includes: ['status', 'count']
3443
},
3544
{
36-
join_path: orders,
45+
join_path: orders.users,
46+
prefix: true,
3747
includes: ['id', 'city', 'state']
3848
}
3949
]
@@ -42,11 +52,12 @@ view(`orders_users`, {
4252

4353
</CodeTabs>
4454

45-
Now, it is possible to get orders count by users city with the following query.
55+
With this data model, here's how you can get orders count by users' cities:
4656

4757
```sql
48-
cube=> SELECT count, city FROM orders_users;
49-
count | user_city
58+
cube=> SELECT MEASURE(count) AS count, users_city FROM orders_users GROUP BY 2;
59+
60+
count | users_city
5061
-------+---------------
5162
1416 | Los Angeles
5263
1412 | Seattle
@@ -59,17 +70,18 @@ cube=> SELECT count, city FROM orders_users;
5970
(8 rows)
6071
```
6172

62-
# Joins
73+
## `CROSS JOIN` and `__cubeJoinField`
6374

64-
The SQL API supports joins through `__cubeJoinField` virtual column, which allows end users to control how specific cubes are joined.
65-
This is considered advanced functionality, and views should be used where possible.
66-
Join can also be done through `CROSS JOIN`. Usage
67-
of `__cubeJoinField` in a join instructs Cube to perform join as it's defined in
68-
a data model. Cube generates the correct joining conditions for the underlying
69-
data source.
75+
The SQL API also supports joins through the `__cubeJoinField` virtual column, which
76+
allows to control how specific cubes are joined. This is considered an advanced
77+
functionality, and views should be used where possible. Join can also be done through
78+
`CROSS JOIN`.
79+
80+
Usage of `CROSS JOIN` or `__cubeJoinField` instructs Cube to perform join as it's defined
81+
in a data model while using provided cubes as [join hints][ref-join-hints].
7082

7183
For example, the following query joins the `orders` and `products` tables under
72-
the hood with `orders.product_id = products.id`, exactly the same way as the
84+
the hood on `orders.product_id = products.id`, exactly the same way as the
7385
REST API query does:
7486

7587
```sql
@@ -189,6 +201,10 @@ LIMIT 5;
189201
(2 rows)
190202
```
191203

192-
Please note even if `product_description` is in the inner selection, it isn't
204+
Please note that, even if `product_description` is in the inner selection, it isn't
193205
evaluated in the final query as it isn't used in any way.
194206

207+
208+
[ref-views]: /product/data-modeling/concepts#views
209+
[ref-join-paths]: /product/data-modeling/concepts/working-with-joins#join-paths
210+
[ref-join-hints]: /product/data-modeling/concepts/working-with-joins#join-hints

docs/pages/product/apis-integrations/sql-api/query-format.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ WHERE is_completed IS TRUE;
9797
Please [refer to this page](/product/apis-integrations/sql-api/joins) for details
9898
on joins.
9999

100+
100101
## Post-processing and pushdown
101102

102-
Since 1.0 by default, the SQL API executes, [regular queries][ref-regular-queries],
103-
[queries with post-processing][ref-queries-wpp] and [queries with
103+
Since 1.0 by default, the SQL API executes [regular queries][ref-regular-queries],
104+
[queries with post-processing][ref-queries-wpp], and [queries with
104105
pushdown][ref-queries-wpd].
105106

106107
### Query post-processing

docs/pages/product/data-modeling/concepts.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,9 @@ cubes:
702702
703703
</CodeTabs>
704704
705-
There are three [types of join relationships][ref-ref-join-types]
706-
(`one_to_one`, `one_to_many`, and `many_to_one`) and a few [other
707-
concepts][ref-working-with-joins] such as the direction of joins and trasitive
708-
joins pitfalls.
705+
There are three types of join relationships (`one_to_one`, `one_to_many`, and
706+
`many_to_one`) and a few [other concepts][ref-working-with-joins] such as the
707+
direction of joins and transitive joins pitfalls.
709708

710709
<ReferenceBox>
711710

@@ -812,7 +811,6 @@ See the reference documentaton for the full list of pre-aggregation
812811
/product/caching/using-pre-aggregations#partitioning
813812
[ref-ref-dimension-types]: /product/data-modeling/reference/types-and-formats#dimension-types
814813
[ref-ref-measure-types]: /product/data-modeling/reference/types-and-formats#measure-types
815-
[ref-ref-join-types]: /product/data-modeling/reference/joins#relationship
816814
[ref-schema-ref-sql]: /product/data-modeling/reference/cube#sql
817815
[ref-schema-ref-sql-table]: /product/data-modeling/reference/cube#sql_table
818816
[ref-tutorial-incremental-preagg]:
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = {
22
"calculated-members": "Calculated members",
33
"multi-stage-calculations": "Multi-stage calculations",
4+
"working-with-joins": "Joins between cubes",
45
"calendar-cubes": "Calendar cubes",
56
"code-reusability-extending-cubes": "Extension",
67
"polymorphic-cubes": "Polymorphic cubes",
7-
"data-blending": "Data blending",
8-
"working-with-joins": "Working with joins"
9-
}
8+
"data-blending": "Data blending"
9+
}

0 commit comments

Comments
 (0)