Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Explicit default_count_measure parameter in the views reference #8954

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions docs/pages/reference/data-model/cube.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,68 @@ cubes:

</CodeTabs>

### `default_count_measure`

The `default_count_measure` parameter is used to explicitly specify the measure
that should be used to generate the query for the upstream data source for
`SELECT COUNT(*) FROM cube` queries via the [SQL API][ref-sql-api].

The specified measure should be of one of the following [types][ref-ref-measure-types]:
`count`, `count_distinct`, or `count_distinct_approx`.

<CodeTabs>

```javascript
cube(`users`, {
sql: `
SELECT 1 AS transaction_id, 1 AS user_id UNION ALL
SELECT 2 AS transaction_id, 1 AS user_id UNION ALL
SELECT 3 AS transaction_id, 1 AS user_id UNION ALL
SELECT 4 AS transaction_id, 2 AS user_id UNION ALL
SELECT 5 AS transaction_id, 2 AS user_id
`,

measures: {
transaction_count: {
type: `count`
},

user_count: {
sql: `user_id`,
type: `count_distinct`
}
},

default_count_measure: users.user_count
})
```

```yaml
cubes:
- name: users
sql: >
SELECT 1 AS transaction_id, 1 AS user_id UNION ALL
SELECT 2 AS transaction_id, 1 AS user_id UNION ALL
SELECT 3 AS transaction_id, 1 AS user_id UNION ALL
SELECT 4 AS transaction_id, 2 AS user_id UNION ALL
SELECT 5 AS transaction_id, 2 AS user_id

measures:
- name: transaction_count
type: count

- name: user_count
sql: user_id
type: count_distinct

default_count_measure: users.user_count
```

</CodeTabs>

If this parameter is not set, then the very first measure of type `count` from
this cube will be used.


[ref-config-driverfactory]: /reference/configuration/config#driverfactory
[ref-config-ext-ctx]: /reference/configuration/config#extend_context
Expand All @@ -602,3 +664,5 @@ cubes:
[ref-ref-segments]: /reference/data-model/segments
[ref-ref-joins]: /reference/data-model/joins
[ref-ref-pre-aggs]: /reference/data-model/pre-aggregations
[ref-sql-api]: /product/apis-integrations/sql-api
[ref-ref-measure-types]: /reference/data-model/types-and-formats
69 changes: 67 additions & 2 deletions docs/pages/reference/data-model/view.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ view(`orders`, {
},
{
join_path: base_orders.users,
prefix: true
prefix: true,
includes: `*`,
excludes: [
`company`
Expand Down Expand Up @@ -254,6 +254,69 @@ To learn more about using `public` to control visibility based on security
context, read the [Controlling access to cubes and views
recipe][ref-recipe-control-access-cubes-views].

### `default_count_measure`

The `default_count_measure` parameter is used to explicitly specify the measure
that should be used to generate the query for the upstream data source for
`SELECT COUNT(*) FROM view` queries via the [SQL API][ref-sql-api].

The specified measure should be of one of the following [types][ref-ref-measure-types]:
`count`, `count_distinct`, or `count_distinct_approx`. It should also be included
into the view in [`cubes`](#cubes).

<CodeTabs>

```javascript
view(`orders`, {
cubes: [
{
join_path: base_orders,
includes: [
`status`,
`created_date`,
`total_amount`,
`total_amount_shipped`,
`count`,
`average_order_value`
]
},
{
join_path: base_orders.users,
prefix: true,
includes: `*`
}
],

default_count_measure: base_orders.count
})
```

```yaml
views:
- name: orders

cubes:
- join_path: base_orders
includes:
- status
- created_date
- total_amount
- total_amount_shipped
- count
- average_order_value

- join_path: base_orders.users
prefix: true
includes: "*"

default_count_measure: base_orders.count
```

</CodeTabs>

If this parameter is not set, then the very first measure of type `count` from
the very first cube defined in [`cubes`](#cubes) will be used.

### `includes` (deprecated)

<WarningBox>
Expand Down Expand Up @@ -312,4 +375,6 @@ view query.
/product/data-modeling/concepts/working-with-joins#directions-of-joins
[ref-naming]: /product/data-modeling/syntax#naming
[ref-playground]: /product/workspace/playground
[ref-apis]: /product/apis-integrations
[ref-apis]: /product/apis-integrations
[ref-sql-api]: /product/apis-integrations/sql-api
[ref-ref-measure-types]: /reference/data-model/types-and-formats