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

Update metricflow-cli.md #3966

Merged
merged 8 commits into from
Aug 23, 2023
Merged
Changes from 1 commit
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
45 changes: 31 additions & 14 deletions website/docs/docs/build/metricflow-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,44 +140,60 @@ Create a new query with MetricFlow, execute that query against the user's data p

```bash
mf query --metrics <metric_name> --group-by <dimension_name>

Options:

--metrics SEQUENCE Metrics to query for: syntax is --metrics bookings
or for multiple metrics --metrics bookings,messages
or for multiple metrics --metrics bookings, messages.

--group-by SEQUENCE Dimensions and/or entities to group by: syntax is
--group-by ds or for multiple group bys --group-by
ds,org
ds, org.

--end-time TEXT Optional iso8601 timestamp to constraint the end
time of the data (inclusive)

--start-time TEXT Optional iso8601 timestamp to constraint the start
time of the data (inclusive)

--where TEXT SQL-like where statement provided as a string. For
example: --where "revenue > 100"
To add a dimension filter to a where filter, you have to indicate that the filter item is part of your model. Reference the dimension using the following template wrapper: {{ Dimension(‘model_name1__model_name2’) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To add a dimension filter to a where filter, you have to indicate that the filter item is part of your model. Reference the dimension using the following template wrapper: {{ Dimension(‘model_name1__model_name2’) }}
To add a dimension filter to a where filter, you have to indicate that the filter item is part of your model. Reference the dimension using the following template wrapper: {{ Dimension(‘primary_entity__dimension_name’) }}


--limit TEXT Limit the number of rows out using an int or leave
blank for no limit. For example: --limit 100

--order SEQUENCE Metrics or group bys to order by ("-" prefix for
DESC). For example: --order -ds or --order
ds,-revenue

--csv FILENAME Provide filepath for data frame output to csv

--explain In the query output, show the query that was
executed against the data warehouse

--show-dataflow-plan Display dataflow plan in explain output
--display-plans Display plans (e.g. metric dataflow) in the browser

--display-plans Display plans (such as metric dataflow) in the browser

--decimals INTEGER Choose the number of decimal places to round for
the numerical values

--show-sql-descriptions Shows inline descriptions of nodes in displayed SQL

--help Show this message and exit.
```


## Query examples

The following tabs presents various different types of query examples that you can use to query metrics and dimensions. Select the tab that best suits your needs:
The following tabs present various different types of query examples that you can use to query metrics and dimensions. Select the tab that best suits your needs:

<Tabs>

<TabItem value="eg1" label="Metrics">

**Example 1** &mdash; Use the example to query metrics by dimension and return the `order_amount` metric by `metric_time.`
Use the example to query metrics by dimension and return the `order_amount` metric by `metric_time.`

**Query**
```bash
Expand All @@ -200,7 +216,7 @@ mf query --metrics order_amount --group-by metric_time

<TabItem value="eg2" label="Dimensions">

**Example 2** &mdash; You can include multiple dimensions in a query. For example, you can group by the `is_food_order` dimension to confirm if orders were for food or not.
You can include multiple dimensions in a query. For example, you can group by the `is_food_order` dimension to confirm if orders were for food or not.

**Query**
```bash
Expand All @@ -227,7 +243,7 @@ mf query --metrics order_amount --group-by metric_time, is_food_order

<TabItem value="eg3" label="Order/limit">

**Example 3** &mdash; You can add order and limit functions to filter and present the data in a readable format. The following query limits the data set to 10 records and orders them by `metric_time`, descending.
You can add order and limit functions to filter and present the data in a readable format. The following query limits the data set to 10 records and orders them by `metric_time`, descending.

**Query**
```bash
Expand All @@ -251,7 +267,7 @@ mf query --metrics order_amount --group-by metric_time,is_food_order --limit 10

<TabItem value="eg4" label="where clause">

**Example 4** &mdash; You can further filter the data set by adding a `where` clause to your query.
You can further filter the data set by adding a `where` clause to your query.

**Query**
```bash
Expand Down Expand Up @@ -279,7 +295,7 @@ mf query --metrics order_amount --group-by metric_time,is_food_order --limit 10

<TabItem value="eg5" label=" Filter by time">

**Example 5** &mdash; To filter by time, there are dedicated start and end time options. Using these options to filter by time allows MetricFlow to further optimize query performance by pushing down the where filter when appropriate.
To filter by time, there are dedicated start and end time options. Using these options to filter by time allows MetricFlow to further optimize query performance by pushing down the where filter when appropriate.

**Query**
```bash
Expand Down Expand Up @@ -307,15 +323,15 @@ mf query --metrics order_amount --group-by metric_time,is_food_order --limit 10

### Additional query examples

The following tabs presents additional query examples, like exporting to a CSV. Select the tab that best suits your needs:
The following tabs present additional query examples, like exporting to a CSV. Select the tab that best suits your needs:

<Tabs>



<TabItem value="eg6" label="--explain flag">

**Example 6** &mdash; Add `--explain` to your query to view the SQL generated by MetricFlow.
Add `--explain` to your query to view the SQL generated by MetricFlow.

**Query**

Expand Down Expand Up @@ -351,7 +367,7 @@ LIMIT 10

<TabItem value="eg7" label=" Export to CSV">

**Example 7** &mdash; Add the `--csv file_name.csv` flag to export the results of your query to a csv.
Add the `--csv file_name.csv` flag to export the results of your query to a csv.

**Query**

Expand All @@ -369,9 +385,10 @@ mf query --metrics order_amount --group-by metric_time,is_food_order --limit 10
</Tabs>

## Time granularity
Optionally, you can specify the time granularity you want your data to be aggregated at by appending two underscores and the unit of granularity you want to `metric_time`, the global time dimension . You can group the granularity by: `day`, `week`, `month`, `quarter`, and `year`.
Optionally, you can specify the time granularity you want your data to be aggregated at by appending two underscores and the unit of granularity you want to `metric_time`, the global time dimension. You can group the granularity by: `day`, `week`, `month`, `quarter`, and `year`.

Below is an example for querying metric data at a monthly grain:

```bash
mf query --metrics revenue --group-by metric_time__month
```
```