diff --git a/docs/pages/reference/data-model/cube.mdx b/docs/pages/reference/data-model/cube.mdx index 17800085be3b0..07fede197555e 100644 --- a/docs/pages/reference/data-model/cube.mdx +++ b/docs/pages/reference/data-model/cube.mdx @@ -583,6 +583,68 @@ cubes: +### `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`. + + + +```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 +``` + + + +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 @@ -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 \ No newline at end of file diff --git a/docs/pages/reference/data-model/view.mdx b/docs/pages/reference/data-model/view.mdx index 8841740202a75..cef3c0cdc8e78 100644 --- a/docs/pages/reference/data-model/view.mdx +++ b/docs/pages/reference/data-model/view.mdx @@ -114,7 +114,7 @@ view(`orders`, { }, { join_path: base_orders.users, - prefix: true + prefix: true, includes: `*`, excludes: [ `company` @@ -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). + + + +```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 +``` + + + +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) @@ -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 \ No newline at end of file +[ref-apis]: /product/apis-integrations +[ref-sql-api]: /product/apis-integrations/sql-api +[ref-ref-measure-types]: /reference/data-model/types-and-formats \ No newline at end of file