From beb6d8af1998aefdbe9a3e0ab22cdf8a08b1cb15 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 29 Feb 2024 14:52:24 +0000 Subject: [PATCH 1/3] add cache to sq --- website/docs/docs/build/saved-queries.md | 87 +++++++++++++++++++++--- 1 file changed, 76 insertions(+), 11 deletions(-) diff --git a/website/docs/docs/build/saved-queries.md b/website/docs/docs/build/saved-queries.md index 4083d2fb6b8..51efbb39da4 100644 --- a/website/docs/docs/build/saved-queries.md +++ b/website/docs/docs/build/saved-queries.md @@ -22,21 +22,33 @@ Saved queries are distinct from [exports](/docs/use-dbt-semantic-layer/exports), All metrics in a saved query need to use the same dimensions in the `group_by` or `where` clauses. The following is an example of a saved query: + + + ```yaml saved_queries: - - name: p0_booking - description: Booking-related metrics that are of the highest priority. + - name: test_saved_query + description: "{{ doc('saved_query_description') }}" + label: Test saved query + config: + cache: + enabled: True | False query_params: - metrics: - - bookings - - instant_bookings - group_by: - - TimeDimension('metric_time', 'day') - - Dimension('listing__capacity_latest') - where: - - "{{ Dimension('listing__capacity_latest') }} > 3" + metrics: + - simple_metric + group_by: + - "Dimension('user__ds')" + where: + - "{{ Dimension('user__ds', 'DAY') }} <= now()" + - "{{ Dimension('user__ds', 'DAY') }} >= '2023-01-01'" + exports: + - name: my_export + config: + alias: my_export_alias + export_as: table + schema: my_export_schema_name ``` @@ -48,6 +60,9 @@ To define a saved query, refer to the following parameters: |-------|---------|----------|----------------| | `name` | String | Required | Name of the saved query object. | | `description` | String | Required | A description of the saved query. | +| `label` | String | Required | The display name for your saved query. This value will be shown in downstream tools. | +| `config` | String | Required | A config section for any parameters specifying the saved query. | +| `config::cache` | String | Optional | A boolean to specify if a saved query should be used to populate the cache. Accepts `True` or `False`. Defaults to `False` | | `query_params` | Structure | Required | Contains the query parameters. | | `query_params::metrics` | List or String | Optional | A list of the metrics to be used in the query as specified in the command line interface. | | `query_params::group_by` | List or String | Optional | A list of the Entities and Dimensions to be used in the query, which include the `Dimension` or `TimeDimension`. | @@ -59,8 +74,58 @@ To define a saved query, refer to the following parameters: | `exports::config::schema` | String | Optional | The schema for creating the table or view. This option cannot be used for caching. | | `exports::config::alias` | String | Optional | The table alias to use to write the table or view. This option cannot be used for caching. | -All metrics in a saved query need to use the same dimensions in the `group_by` or `where` clauses. + + + + + + + +```yaml +saved_queries: + - name: test_saved_query + description: "{{ doc('saved_query_description') }}" + label: Test saved query + query_params: + metrics: + - simple_metric + group_by: + - "Dimension('user__ds')" + where: + - "{{ Dimension('user__ds', 'DAY') }} <= now()" + - "{{ Dimension('user__ds', 'DAY') }} >= '2023-01-01'" + exports: + - name: my_export + config: + alias: my_export_alias + export_as: table + schema: my_export_schema_name +``` + + +## Parameters + +To define a saved query, refer to the following parameters: + +| Parameter | Type | Required | Description | +|-------|---------|----------|----------------| +| `name` | String | Required | Name of the saved query object. | +| `description` | String | Required | A description of the saved query. | +| `label` | String | Required | The display name for your saved query. This value will be shown in downstream tools. | +| `query_params` | Structure | Required | Contains the query parameters. | +| `query_params::metrics` | List or String | Optional | A list of the metrics to be used in the query as specified in the command line interface. | +| `query_params::group_by` | List or String | Optional | A list of the Entities and Dimensions to be used in the query, which include the `Dimension` or `TimeDimension`. | +| `query_params::where` | List or String | Optional | A list of strings that may include the `Dimension` or `TimeDimension` objects. | +| `exports` | List or Structure | Optional | A list of exports to be specified within the exports structure. | +| `exports::name` | String | Required | Name of the export object. | +| `exports::config` | List or Structure | Required | A config section for any parameters specifying the export. | +| `exports::config::export_as` | String | Required | The type of export to run. Options include table or view currently and cache in the near future. | +| `exports::config::schema` | String | Optional | The schema for creating the table or view. This option cannot be used for caching. | +| `exports::config::alias` | String | Optional | The table alias to use to write the table or view. This option cannot be used for caching. | + + +All metrics in a saved query need to use the same dimensions in the `group_by` or `where` clauses. ## Related docs From 4c5cc31acb34af08f2779e4ad81db5ddaf720b98 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:24:16 +0000 Subject: [PATCH 2/3] Update saved-queries.md update yaml --- website/docs/docs/build/saved-queries.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/website/docs/docs/build/saved-queries.md b/website/docs/docs/build/saved-queries.md index 51efbb39da4..050aa242afc 100644 --- a/website/docs/docs/build/saved-queries.md +++ b/website/docs/docs/build/saved-queries.md @@ -16,7 +16,7 @@ Saved queries are distinct from [exports](/docs/use-dbt-semantic-layer/exports), | ----------- | ----------- | ---------------- | | **Availability** | Available on dbt Cloud [Team or Enterprise](https://www.getdbt.com/pricing/) plans on dbt versions 1.7 or newer.| Available in both dbt Core and dbt Cloud. | | **Purpose** | To materialize saved queries in your data platform and expose metrics and dimensions as a view or table. | To define and manage common Semantic Layer queries in YAML, which includes metrics and dimensions. | -| **Usage** | Automatically runs saved queries and materializes them within your data platform. Exports count towards [queried metrics](/docs/cloud/billing#what-counts-as-a-queried-metric) usage.

**Example**: Creating a weekly aggregated table for active user metrics, automatically updated and stored in the data platform. | Used for organizing and reusing common MetricFlow queries within dbt projects.


**Example**: Group related metrics together for better organization, and include commonly uses dimensions and filters. | For materializing query results in the data platform. | +| **Usage** | Automatically runs saved queries and materializes them within your data platform. Exports count towards [queried metrics](/docs/cloud/billing#what-counts-as-a-queried-metric) usage.

**Example**: Creating a weekly aggregated table for active user metrics, automatically updated and stored in the data platform. | Used for organizing and reusing common MetricFlow queries within dbt projects.


**Example**: Group related metrics together for better organization, and include commonly used dimensions and filters. | For materializing query results in the data platform. | | **Integration** | Must have the dbt Semantic Layer configured in your dbt project.

Tightly integrated with the [MetricFlow Server](/docs/use-dbt-semantic-layer/sl-architecture#components) and dbt Cloud's job scheduler. | Integrated into the dbt and managed alongside other dbt nodes. | | **Configuration** | Defined within the `saved_queries` configuration. Set up within the dbt Cloud environment and job scheduler settings. | Defined in YAML format within dbt project files. | @@ -34,7 +34,7 @@ saved_queries: label: Test saved query config: cache: - enabled: True | False + enabled: true # Or false if you want it disabled by default query_params: metrics: - simple_metric @@ -62,7 +62,7 @@ To define a saved query, refer to the following parameters: | `description` | String | Required | A description of the saved query. | | `label` | String | Required | The display name for your saved query. This value will be shown in downstream tools. | | `config` | String | Required | A config section for any parameters specifying the saved query. | -| `config::cache` | String | Optional | A boolean to specify if a saved query should be used to populate the cache. Accepts `True` or `False`. Defaults to `False` | +| `config::cache` | String | Optional | A boolean to specify if a saved query should be used to populate the cache. Accepts `true` or `false`. Defaults to `false` | | `query_params` | Structure | Required | Contains the query parameters. | | `query_params::metrics` | List or String | Optional | A list of the metrics to be used in the query as specified in the command line interface. | | `query_params::group_by` | List or String | Optional | A list of the Entities and Dimensions to be used in the query, which include the `Dimension` or `TimeDimension`. | @@ -72,7 +72,7 @@ To define a saved query, refer to the following parameters: | `exports::config` | List or Structure | Required | A config section for any parameters specifying the export. | | `exports::config::export_as` | String | Required | The type of export to run. Options include table or view currently and cache in the near future. | | `exports::config::schema` | String | Optional | The schema for creating the table or view. This option cannot be used for caching. | -| `exports::config::alias` | String | Optional | The table alias to use to write the table or view. This option cannot be used for caching. | +| `exports::config::alias` | String | Optional | The table alias used to write to the table or view. This option cannot be used for caching. | @@ -121,7 +121,7 @@ To define a saved query, refer to the following parameters: | `exports::config` | List or Structure | Required | A config section for any parameters specifying the export. | | `exports::config::export_as` | String | Required | The type of export to run. Options include table or view currently and cache in the near future. | | `exports::config::schema` | String | Optional | The schema for creating the table or view. This option cannot be used for caching. | -| `exports::config::alias` | String | Optional | The table alias to use to write the table or view. This option cannot be used for caching. | +| `exports::config::alias` | String | Optional | The table alias used to write to the table or view. This option cannot be used for caching. | From 2ae257d3f83360d31259b5f385655e49b1f271b6 Mon Sep 17 00:00:00 2001 From: Matt Shaver <60105315+matthewshaver@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:33:14 -0400 Subject: [PATCH 3/3] Update website/docs/docs/build/saved-queries.md --- website/docs/docs/build/saved-queries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/saved-queries.md b/website/docs/docs/build/saved-queries.md index 050aa242afc..b4a31391c10 100644 --- a/website/docs/docs/build/saved-queries.md +++ b/website/docs/docs/build/saved-queries.md @@ -77,7 +77,7 @@ To define a saved query, refer to the following parameters: - +