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

chore: format nrql clauses #19685

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ Consider a query that filters results based on a `countryCode` variable. If you

Original query:

```sql
FROM PageAction
SELECT count(*) AS 'views'
WHERE countryCode IN ({{countryCode}}) and appName = 'Test App' FACET countryCode
```
```sql
FROM PageAction
SELECT count(*) AS 'views'
WHERE countryCode IN ({{countryCode}}) AND appName = 'Test App' FACET countryCode
```

Query with an excluded variable:

```sql
FROM PageAction
SELECT count(*) AS 'views'
WHERE true and appName = 'Test App' FACET countryCode
FROM PageAction
SELECT count(*) AS 'views'
WHERE true AND appName = 'Test App' FACET countryCode
```

This feature is particularly useful when:
Expand All @@ -77,7 +77,7 @@ Limitations on include variable:

* When used in FACET cases, the condition is replaced with true and converts it to an always-true condition.

* When used in other contexts like functions or with the SELECT statement, you'll get the following error: `"Unknown function Disable_variable()"`. This is because the disable variable function isn't implemented for these specific cases yet.
* When used in other contexts like functions or with the `SELECT` statement, you'll get the following error: `"Unknown function Disable_variable()"`. This is because the disable variable function isn't implemented for these specific cases yet.

## Requirements and limitations [#requirements]

Expand All @@ -92,7 +92,7 @@ Important points to note about adding a query:
* The variable generates a string value.

* To help you when you're creating a query, there's a color code:
* Clauses, `from`, `select`, `facet`, and `where`, are in pink.
* Clauses, `FROM`, `SELECT`, `FACET`, and `WHERE`, are in pink.
* Identifiers are in black.
* Functions are in blue.
* Strings are in green.
Expand Down Expand Up @@ -203,7 +203,7 @@ First, you'll define a template variable. This is the variable that you'll use i
</td>

<td>
Write here your query using `uniques (attribute)`.
Write here your query using `uniques(attribute)`.
</td>
</tr>

Expand Down Expand Up @@ -306,7 +306,7 @@ First, you'll define a template variable. This is the variable that you'll use i

Notice that these are the NRQL clauses that will accept template variables as values: `SELECT`, `FROM`, `FACET`, `ORDER BY` and `WHERE`.

Instead, the following list of NRQL clauses will not accept template variables as arguments: `AS`, `COMPARE WITH`, `LIMIT`, `OFFSET`, `SINCE`, `SLIDE BY`, `TIMESERIES`, `UNTIL` and `WITH...`.
Instead, the following list of NRQL clauses will not accept template variables as arguments: `AS`, `COMPARE WITH`, `LIMIT`, `OFFSET`, `SINCE`, `SLIDE BY`, `TIMESERIES`, `UNTIL` and `WITH`....

5. Click <DNT>**Save**</DNT>

Expand All @@ -332,7 +332,7 @@ You can use almost any NRQL query as long as it returns a list of values. For th
With [`uniques`](/docs/nrql/nrql-syntax-clauses-functions/#func-uniques):

```sql
From PageAction select uniques(countryCode)
FROM PageAction SELECT uniques(countryCode)
```

```sql
Expand All @@ -343,8 +343,8 @@ With [`uniques`](/docs/nrql/nrql-syntax-clauses-functions/#func-uniques):
With [`keyset`](/docs/nrql/nrql-syntax-clauses-functions/#keyset):

```sql
-- with `keyset`, you'll get a list with all of the attributes from the table you're querying from
From PageAction select keyset() SINCE 1 day ago
-- with `keyset`, you'll get a list with all of the attributes from the table you're querying from
FROM PageAction SELECT keyset() SINCE 1 day ago
```

Keep in mind that nested variables are not supported as there can't be variables within variables.
Expand Down Expand Up @@ -396,7 +396,8 @@ Here are some different types of template variable implementations.
Here's an example of a query that uses two template variables. Note that this assumes the `countryCode` and `city` template variables would have already been created and that they have a single value.

```sql
SELECT countryCode, city FROM PageAction WHERE countryCode = {{countryCode}} and city = {{city}}
SELECT countryCode, city FROM PageAction
WHERE countryCode = {{countryCode}} AND city = {{city}}
```

<img
Expand All @@ -408,7 +409,8 @@ Here are some different types of template variable implementations.
If you have multiple values for your variables, such as `Chicago`, `New York`, `Paris` for your `city` variable, you need to use `IN`:

```sql
SELECT countryCode, city FROM PageAction WHERE countryCode IN ({{countryCode}}) and city IN ({{city}})
SELECT countryCode, city FROM PageAction
WHERE countryCode IN ({{countryCode}}) AND city IN ({{city}})
```
</Collapser>

Expand All @@ -418,14 +420,14 @@ Here are some different types of template variable implementations.
>
Using variables and [regex](/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/#func-capture), you can create a filter, provided you're sure that a part of the filter is fixed.

You need to use this partial match if you want to use `like`.
You need to use this partial match if you want to use `LIKE`.

Let's say you want to filter by release version. The query returns something like: `release-1234`.

You can create a variable using [`aparse`](/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/#func-aparse) to parse the version number:

```sql
SELECT uniques(aparse(platformVersion , 'release-*')) FROM PageView
SELECT uniques(aparse(platformVersion, 'release-*')) FROM PageView
```

<img
Expand All @@ -438,7 +440,8 @@ Here are some different types of template variable implementations.
Then create a widget with the following query:

```sql
SELECT count(*) FROM PageAction WHERE aparse(platformVersion, 'release-*') IN ({{releaseversion}}) facet platformVersion
SELECT count(*) FROM PageAction
WHERE aparse(platformVersion, 'release-*') IN ({{releaseversion}}) FACET platformVersion
```

<img
Expand All @@ -450,7 +453,8 @@ Here are some different types of template variable implementations.
Or if you prefer, you could use the [`capture`](/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/#func-capture) command:

```sql
SELECT count(*) FROM PageAction WHERE capture(platformVersion, r'release-(?P<platformVersion>\d+)') IN ({{releaseversion}}) Facet platformVersion
SELECT count(*) FROM PageAction
WHERE capture(platformVersion, r'release-(?P<platformVersion>\d+)') IN ({{releaseversion}}) FACET platformVersion
```

<img
Expand Down Expand Up @@ -498,7 +502,7 @@ Here are some different types of template variable implementations.
id="variables-dynamic-grouping"
title={<>Use variable <InlineCode>facet</InlineCode> with a NRQL query</>}
>
You can create a variable of type NRQL with a string output format and use it after a `facet` clause to group by different values.
You can create a variable of type NRQL with a string output format and use it after a `FACET` clause to group by different values.

For example, you might create a variable named `{{userAgentName}}` that would look like:

Expand All @@ -516,7 +520,8 @@ Here are some different types of template variable implementations.
Then you'd create a widget with the following query:

```sql
SELECT count(*) FROM PageAction WHERE userAgentName={{userAgentName}} FACET userAgentName
SELECT count(*) FROM PageAction
WHERE userAgentName={{userAgentName}} FACET userAgentName
```

<img
Expand Down Expand Up @@ -603,7 +608,7 @@ Here are some different types of template variable implementations.
id="ignore-time-picker"
title="Use ignore time picker option"
>
By default the “ignore time picker” option is enabled, meaning that the query is always run using the default 1 `HOUR` time range value, even if the time picker in the dashboard has a different value selected (ex. 5 minutes, 3 hours, etc). The exception for that case is when the query has an explicit time range set with a `SINCE` clause, like for example:
By default the “ignore time picker” option is enabled, meaning that the query is always run using the default `1 hour` time range value, even if the time picker in the dashboard has a different value selected (ex. `5 minutes`, `3 hours`, etc). The exception for that case is when the query has an explicit time range set with a `SINCE` clause, like for example:

```sql
SELECT uniques(eventId)
Expand All @@ -613,7 +618,7 @@ Here are some different types of template variable implementations.

The results will be in the range of the last 5 minutes.

When the ignore time picker option is turned off, the query will run with the value selected in the time picker. For example, if you set the time picker to 30 minutes, such as in the screenshot below, in the form for editing the variables, the "ignore time picker" field will set to off.
When the "ignore time picker" option is turned off, the query will run with the value selected in the time picker. For example, if you set the time picker to 30 minutes, such as in the screenshot below, in the form for editing the variables, the "ignore time picker" field will set to off.

<img
title="Example time picker"
Expand Down
Loading