From 4b46c9cf91928ec6cf3843aa7e836d16aa474b56 Mon Sep 17 00:00:00 2001 From: Igor Lukanin Date: Wed, 13 Nov 2024 15:59:32 +0100 Subject: [PATCH 1/2] docs: `count_measure` in the views reference --- docs/pages/reference/data-model/view.mdx | 69 +++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/docs/pages/reference/data-model/view.mdx b/docs/pages/reference/data-model/view.mdx index 8841740202a75..99be248188568 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]. +### `count_measure` + +The `count_measure` parameter is used to explicitly specify the measure that +should be used to generate the SQL 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-type-count]: +`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: `*` + } + ], + + 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: "*" + + count_measure: base_orders.count +``` + + + +If this parameter is not set, then the very first measure of [type `count`][ref-ref-measure-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-type-count]: /reference/data-model/types-and-formats#count \ No newline at end of file From 4a8df27917c3156ad9296d12a305f523ea05eadd Mon Sep 17 00:00:00 2001 From: Igor Lukanin Date: Wed, 13 Nov 2024 18:53:54 +0100 Subject: [PATCH 2/2] docs: Rename + document the same one in cubes --- docs/pages/reference/data-model/cube.mdx | 64 ++++++++++++++++++++++++ docs/pages/reference/data-model/view.mdx | 22 ++++---- 2 files changed, 75 insertions(+), 11 deletions(-) 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 99be248188568..cef3c0cdc8e78 100644 --- a/docs/pages/reference/data-model/view.mdx +++ b/docs/pages/reference/data-model/view.mdx @@ -254,13 +254,13 @@ 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]. -### `count_measure` +### `default_count_measure` -The `count_measure` parameter is used to explicitly specify the measure that -should be used to generate the SQL for `SELECT COUNT(*) FROM view` queries via -the [SQL API][ref-sql-api]. +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-type-count]: +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). @@ -287,8 +287,8 @@ view(`orders`, { } ], - count_measure: base_orders.count -}); + default_count_measure: base_orders.count +}) ``` ```yaml @@ -309,13 +309,13 @@ views: prefix: true includes: "*" - count_measure: base_orders.count + default_count_measure: base_orders.count ``` -If this parameter is not set, then the very first measure of [type `count`][ref-ref-measure-type-count] -from the very first cube defined in [`cubes`](#cubes) will be used. +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) @@ -377,4 +377,4 @@ view query. [ref-playground]: /product/workspace/playground [ref-apis]: /product/apis-integrations [ref-sql-api]: /product/apis-integrations/sql-api -[ref-ref-measure-type-count]: /reference/data-model/types-and-formats#count \ No newline at end of file +[ref-ref-measure-types]: /reference/data-model/types-and-formats \ No newline at end of file