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 sl-jdbc.md #4604

Merged
merged 33 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e619ffa
Update sl-jdbc.md
rpourzand Dec 7, 2023
7dafb5f
Merge branch 'current' into rpourzand-patch-api-updates
mirnawong1 Dec 7, 2023
4844dd3
Merge branch 'current' into rpourzand-patch-api-updates
mirnawong1 Dec 7, 2023
dc49f19
Update sl-jdbc.md
rpourzand Dec 8, 2023
be5c52c
Update sl-graphql.md
rpourzand Dec 8, 2023
8c510b7
Update sl-jdbc.md
rpourzand Dec 8, 2023
436577f
Update sl-jdbc.md
rpourzand Dec 8, 2023
c250bb6
Update sl-graphql.md
rpourzand Dec 8, 2023
61af03e
Update sl-graphql.md
rpourzand Dec 8, 2023
c5afac9
Update sl-jdbc.md
rpourzand Dec 8, 2023
0b96df9
Merge branch 'current' into rpourzand-patch-api-updates
mirnawong1 Dec 19, 2023
384eba8
Update sl-graphql.md
rpourzand Dec 19, 2023
bc2239a
Update sl-jdbc.md
rpourzand Dec 21, 2023
a73e793
Update sl-graphql.md
mirnawong1 Dec 21, 2023
ceea7dc
Update website/docs/docs/dbt-cloud-apis/sl-graphql.md
mirnawong1 Dec 21, 2023
5f832e9
Update website/docs/docs/dbt-cloud-apis/sl-jdbc.md
mirnawong1 Dec 21, 2023
1b77419
Update website/docs/docs/dbt-cloud-apis/sl-jdbc.md
mirnawong1 Dec 21, 2023
e061521
Update website/docs/docs/dbt-cloud-apis/sl-jdbc.md
mirnawong1 Dec 21, 2023
7aa722d
Update website/docs/docs/dbt-cloud-apis/sl-jdbc.md
mirnawong1 Dec 21, 2023
7dc125e
Update website/docs/docs/dbt-cloud-apis/sl-jdbc.md
mirnawong1 Dec 21, 2023
ece5d3f
Update sl-jdbc.md
mirnawong1 Dec 21, 2023
b7cd78a
add toggles
mirnawong1 Dec 21, 2023
7b8cc9a
Apply suggestions from code review
matthewshaver Dec 22, 2023
871dabf
Merge branch 'current' into rpourzand-patch-api-updates
mirnawong1 Jan 9, 2024
6a32ba6
Update sl-graphql.md
rpourzand Jan 20, 2024
1d05363
Update sl-graphql.md
rpourzand Jan 20, 2024
d68dbf7
Merge branch 'current' into rpourzand-patch-api-updates
mirnawong1 Jan 23, 2024
357e5aa
Update website/docs/docs/dbt-cloud-apis/sl-jdbc.md
mirnawong1 Jan 23, 2024
192c2f0
Update website/docs/docs/dbt-cloud-apis/sl-jdbc.md
mirnawong1 Jan 23, 2024
250b3ba
Update website/docs/docs/dbt-cloud-apis/sl-jdbc.md
mirnawong1 Jan 23, 2024
fb3b8f6
Update website/docs/docs/dbt-cloud-apis/sl-graphql.md
mirnawong1 Jan 23, 2024
610da38
Update sl-graphql.md
mirnawong1 Jan 23, 2024
7f3cc44
Update sl-jdbc.md
mirnawong1 Jan 23, 2024
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
70 changes: 67 additions & 3 deletions website/docs/docs/dbt-cloud-apis/sl-graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ DimensionType = [CATEGORICAL, TIME]

### Querying

When querying for data, _either_ a `groupBy` _or_ a `metrics` selection is required.

**Create Dimension Values query**

```graphql
Expand Down Expand Up @@ -443,29 +445,91 @@ mutation {
}
```

**Query a categorical dimension on its own**

```graphql
mutation {
createQuery(
environmentId: 123456
groupBy: [{name: "customer__customer_type"}]
) {
queryId
}
}
```

**Query with a where filter**

The `where` filter takes a list argument (or a string for a single input). Depending on the object you are filtering, there are a couple of parameters:

- `Dimension()` — Used for any categorical or time dimensions. If used for a time dimension, granularity is required. For example, `Dimension('metric_time').grain('week')` or `Dimension('customer__country')`.
- `Dimension()` — Used for any categorical or time dimensions. For example, `Dimension('metric_time').grain('week')` or `Dimension('customer__country')`.

- `Entity()` — Used for entities like primary and foreign keys, such as `Entity('order_id')`.

Note: If you prefer a more strongly typed `where` clause, you can optionally use `TimeDimension()` to separate out categorical dimensions from time ones. The `TimeDimension` input takes the time dimension name and also requires granularity. For example, `TimeDimension('metric_time', 'MONTH')`.
Note: If you prefer a `where` clause with a more explicit path, you can optionally use `TimeDimension()` to separate out categorical dimensions from time ones. The `TimeDimension` input takes the time dimension and optionally the granularity level. `TimeDimension('metric_time', 'month')`.

```graphql
mutation {
createQuery(
environmentId: BigInt!
metrics:[{name: "order_total"}]
groupBy:[{name: "customer__customer_type"}, {name: "metric_time", grain: MONTH}]
groupBy:[{name: "customer__customer_type"}, {name: "metric_time", grain: month}]
where:[{sql: "{{ Dimension('customer__customer_type') }} = 'new'"}, {sql:"{{ Dimension('metric_time').grain('month') }} > '2022-10-01'"}]
) {
queryId
}
}
```

For both `TimeDimension()`, the grain is only required in the WHERE filter if the aggregation time dimensions for the measures & metrics associated with the where filter have different grains.
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

For example, consider this Semantic model and Metric configuration, which contains two metrics that are aggregated across different time grains. This example shows a single semantic model, but the same goes for metrics across more than one semantic model.

```yaml
semantic_model:
name: my_model_source

defaults:
agg_time_dimension: created_month
measures:
- name: measure_0
agg: sum
- name: measure_1
agg: sum
agg_time_dimension: order_year
dimensions:
- name: created_month
type: time
type_params:
time_granularity: month
- name: order_year
type: time
type_params:
time_granularity: year

metrics:
- name: metric_0
description: A metric with a month grain.
type: simple
type_params:
measure: measure_0
- name: metric_1
description: A metric with a year grain.
type: simple
type_params:
measure: measure_1
```

Assuming the user is querying `metric_0` and `metric_1` together, a valid filter would be:

* `"{{ TimeDimension('metric_time', 'year') }} > '2020-01-01'"`

Invalid filters would be:

* ` "{{ TimeDimension('metric_time') }} > '2020-01-01'"` — metrics in the query are defined based on measures with different grains.

* `"{{ TimeDimension('metric_time', 'month') }} > '2020-01-01'"` — `metric_1` is not available at a month grain.

**Query with Order**

```graphql
Expand Down
91 changes: 76 additions & 15 deletions website/docs/docs/dbt-cloud-apis/sl-jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ To query metric values, here are the following parameters that are available. Yo
|`order` | Order the data returned by a particular field | `order_by=['order_gross_profit']`, use `-` for descending, or full object notation if the object is operated on: `order_by=[Metric('order_gross_profit').descending(True)`] |
| `compile` | If true, returns generated SQL for the data platform but does not execute | `compile=True` |



## Note on time dimensions and `metric_time`

You will notice that in the list of dimensions for all metrics, there is a dimension called `metric_time`. `Metric_time` is a reserved keyword for the measure-specific aggregation time dimensions. For any time-series metric, the `metric_time` keyword should always be available for use in queries. This is a common dimension across *all* metrics in a semantic graph.
Expand Down Expand Up @@ -266,11 +264,62 @@ Where filters in API allow for a filter list or string. We recommend using the f

Where Filters have a few objects that you can use:

- `Dimension()` - Used for any categorical or time dimensions. If used for a time dimension, granularity is required - `Dimension('metric_time').grain('week')` or `Dimension('customer__country')`
- `Dimension()` — Used for any categorical or time dimensions. `Dimension('metric_time').grain('week')` or `Dimension('customer__country')`.

- `TimeDimension()` — Used as a more explicit definition for time dimensions, optionally takes in a granularity `TimeDimension('metric_time', 'month')`.

- `Entity()` — Used for entities like primary and foreign keys - `Entity('order_id')`.


For `TimeDimension()`, the grain is only required in the `WHERE` filter if the aggregation time dimensions for the measures and metrics associated with the where filter have different grains.

For example, consider this Semantic model and Metric config, which contains two metrics that are aggregated across different time grains. This example shows a single semantic model, but the same goes for metrics across more than one semantic model.

```yaml
semantic_model:
name: my_model_source

defaults:
agg_time_dimension: created_month
measures:
- name: measure_0
agg: sum
- name: measure_1
agg: sum
agg_time_dimension: order_year
dimensions:
- name: created_month
type: time
type_params:
time_granularity: month
- name: order_year
type: time
type_params:
time_granularity: year

metrics:
- name: metric_0
description: A metric with a month grain.
type: simple
type_params:
measure: measure_0
- name: metric_1
description: A metric with a year grain.
type: simple
type_params:
measure: measure_1

```

Assuming the user is querying `metric_0` and `metric_1` together in a single request, a valid `WHERE` filter would be:

- `Entity()` - Used for entities like primary and foreign keys - `Entity('order_id')`
* `"{{ TimeDimension('metric_time', 'year') }} > '2020-01-01'"`

Note: If you prefer a more explicit path to create the `where` clause, you can optionally use the `TimeDimension` feature. This helps separate out categorical dimensions from time-related ones. The `TimeDimesion` input takes the time dimension name and also requires granularity, like this: `TimeDimension('metric_time', 'MONTH')`.
Invalid Filters would be:
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

* `"{{ TimeDimension('metric_time') }} > '2020-01-01'"` — metrics in the query are defined based on measures with different grains.

* `"{{ TimeDimension('metric_time', 'month') }} > '2020-01-01'"` — `metric_1` is not available at a month grain.


- Use the following example to query using a `where` filter with the string format:
Expand Down Expand Up @@ -303,7 +352,8 @@ semantic_layer.query(metrics=['food_order_amount', 'order_gross_profit'],
group_by=[Dimension('metric_time')],
limit=10)
}}
```
```

### Query with Order By Examples

Order By can take a basic string that's a Dimension, Metric, or Entity and this will default to ascending order
Expand All @@ -326,8 +376,9 @@ semantic_layer.query(metrics=['food_order_amount', 'order_gross_profit'],
limit=10,
order_by=[-'order_gross_profit']
}}
```
If you are ordering by an object that's been operated on (e.g., change granularity), or you are using the full object notation, descending order must look like:
```

If you are ordering by an object that's been operated on (for example, you changed the the granularity of the time dimension), or you are using the full object notation, descending order must look like:

```bash
select * from {{
Expand Down Expand Up @@ -364,16 +415,26 @@ semantic_layer.query(metrics=['food_order_amount', 'order_gross_profit'],

## FAQs

<FAQ path="Troubleshooting/sl-alpn-error" />
<FAQ path="Troubleshooting/sl-alpn-error" /><br />
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

<detailsToggle alt_header="Why do some dimensions use different syntax, like `metric_time` versus `Dimension('metric_time')`?">
When you select a dimension on its own, such as `metric_time` you can use the shorthand method which doesn't need the “Dimension” syntax.

However, when you perform operations on the dimension, such as adding granularity, the object syntax `[Dimension('metric_time')` is required.
</detailsToggle>

<detailsToggle alt_header="What does the double underscore `'__'` syntax in dimensions mean?">

The double underscore `"__"` syntax indicates a mapping from an entity to a dimension, as well as where the dimension is located. For example, `user__country` means someone is looking at the `country` dimension from the `user` table.
</detailsToggle>

<detailsToggle alt_header="What is the default output when adding granularity?">

- **Why do some dimensions use different syntax, like `metric_time` versus `[Dimension('metric_time')`?**<br />
When you select a dimension on its own, such as `metric_time` you can use the shorthand method which doesn't need the “Dimension” syntax. However, when you perform operations on the dimension, such as adding granularity, the object syntax `[Dimension('metric_time')` is required.
The default output follows the format `{{time_dimension_name}__{granularity_level}}`.

- **What does the double underscore `"__"` syntax in dimensions mean?**<br />
The double underscore `"__"` syntax indicates a mapping from an entity to a dimension, as well as where the dimension is located. For example, `user__country` means someone is looking at the `country` dimension from the `user` table.
So for example, if the `time_dimension_name` is `ds` and the granularity level is yearly, the output is `ds__year`.

- **What is the default output when adding granularity?**<br />
The default output follows the format `{time_dimension_name}__{granularity_level}`. So for example, if the time dimension name is `ds` and the granularity level is yearly, the output is `ds__year`.
</detailsToggle>

## Related docs

Expand Down
Loading