Skip to content

Commit

Permalink
Revert custom implementation for variable format interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
devnied committed Sep 19, 2024
1 parent d22d7d1 commit d3956f9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.7.1

### 🐞 Bug Fixes
- Use default variable format interpolation for query variables (see documentation).

## 1.7.0

### ⭐ Added
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,39 @@ For Time series query:

##### Query Variables

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

Sample query variable usage:
Single-value variables usage:
```sql
SELECT column FROM table WHERE column in ($variable)
-- $variable = 'xxxxxxx'
SELECT column FROM table WHERE column = ${variable:sqlstring}
-- Interpolation result
SELECT column FROM table WHERE column = 'xxxxxxx'
```

Single-value variables with format usage:
```sql
-- $variable = 'xxxxxxx'
SELECT column FROM table WHERE column = ${variable:raw}
-- nterpolation result
SELECT column FROM table WHERE column = xxxxxxx
```

Multiple-value variables usage:
```sql
-- $variable = ['xxxxxxx','yyyyyy']
SELECT column FROM table WHERE column in (${variable:sqlstring})
-- Interpolation result
SELECT column FROM table WHERE column in ('xxxxxxx','yyyyyy')
```

Multiple-value variables with format usage:
```sql
-- $variable = ['xxxxxxx','yyyyyy']
SELECT column FROM table WHERE column in ${variable:regex}
-- Interpolation result
SELECT column FROM table WHERE column in (test1|test2)
```

##### Layout of a query
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "michelin-snowflake-datasource",
"version": "1.7.0",
"version": "1.7.1",
"description": "Data source for Snowflake",
"scripts": {
"build": "webpack -c ./webpack.config.ts --env production",
Expand Down
9 changes: 1 addition & 8 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ export class DataSource extends DataSourceWithBackend<SnowflakeQuery, SnowflakeO
this.annotations = {};
}

private format(value: any) {
if (Array.isArray(value)) {
return `'${value.join("','")}'`;
}
return value;
}

applyTemplateVariables(query: SnowflakeQuery, scopedVars: ScopedVars): SnowflakeQuery {
query.queryText = getTemplateSrv().replace(query.queryText, scopedVars, this.format);
query.queryText = getTemplateSrv().replace(query.queryText, scopedVars);
return query;
}

Expand Down

0 comments on commit d3956f9

Please sign in to comment.