Skip to content

Commit d3956f9

Browse files
committed
Revert custom implementation for variable format interpolation
1 parent d22d7d1 commit d3956f9

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.7.1
4+
5+
### 🐞 Bug Fixes
6+
- Use default variable format interpolation for query variables (see documentation).
7+
38
## 1.7.0
49

510
### ⭐ Added

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,39 @@ For Time series query:
104104

105105
##### Query Variables
106106

107-
You can use query variable in your query.<br/>
108-
Query variables are used to filter the data displayed in the dashboard.
107+
You can use query variable in your Snowflake queries by using [variable syntax](https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/).<br/>
108+
You can also set the [interpolation format](https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/#general-syntax) in the variable.<br/>
109109

110-
Sample query variable usage:
110+
Single-value variables usage:
111111
```sql
112-
SELECT column FROM table WHERE column in ($variable)
112+
-- $variable = 'xxxxxxx'
113+
SELECT column FROM table WHERE column = ${variable:sqlstring}
114+
-- Interpolation result
115+
SELECT column FROM table WHERE column = 'xxxxxxx'
116+
```
117+
118+
Single-value variables with format usage:
119+
```sql
120+
-- $variable = 'xxxxxxx'
121+
SELECT column FROM table WHERE column = ${variable:raw}
122+
-- nterpolation result
123+
SELECT column FROM table WHERE column = xxxxxxx
124+
```
125+
126+
Multiple-value variables usage:
127+
```sql
128+
-- $variable = ['xxxxxxx','yyyyyy']
129+
SELECT column FROM table WHERE column in (${variable:sqlstring})
130+
-- Interpolation result
131+
SELECT column FROM table WHERE column in ('xxxxxxx','yyyyyy')
132+
```
133+
134+
Multiple-value variables with format usage:
135+
```sql
136+
-- $variable = ['xxxxxxx','yyyyyy']
137+
SELECT column FROM table WHERE column in ${variable:regex}
138+
-- Interpolation result
139+
SELECT column FROM table WHERE column in (test1|test2)
113140
```
114141

115142
##### Layout of a query

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "michelin-snowflake-datasource",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"description": "Data source for Snowflake",
55
"scripts": {
66
"build": "webpack -c ./webpack.config.ts --env production",

src/datasource.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@ export class DataSource extends DataSourceWithBackend<SnowflakeQuery, SnowflakeO
1010
this.annotations = {};
1111
}
1212

13-
private format(value: any) {
14-
if (Array.isArray(value)) {
15-
return `'${value.join("','")}'`;
16-
}
17-
return value;
18-
}
19-
2013
applyTemplateVariables(query: SnowflakeQuery, scopedVars: ScopedVars): SnowflakeQuery {
21-
query.queryText = getTemplateSrv().replace(query.queryText, scopedVars, this.format);
14+
query.queryText = getTemplateSrv().replace(query.queryText, scopedVars);
2215
return query;
2316
}
2417

0 commit comments

Comments
 (0)