generated from grafana/grafana-starter-datasource-backend
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set format onRunQuery new button (#59)
* set format onRunQuery new button * always interpolate
- Loading branch information
Scott Lepper
authored
Feb 1, 2022
1 parent
a99f813
commit 24e264c
Showing
6 changed files
with
49 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Changelog | ||
|
||
## 0.9.10 | ||
|
||
Fix - Set format when using the new Run Query button. | ||
|
||
## 0.9.9 | ||
|
||
Feature - Query Builder. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sqlToAST from 'data/ast'; | ||
import { Format } from 'types'; | ||
import { isString } from 'lodash'; | ||
|
||
export const getFormat = (sql: string): Format => { | ||
// convention to format as time series | ||
// first field as "time" alias and requires at least 2 fields (time and metric) | ||
const ast = sqlToAST(sql); | ||
const select = ast.get('SELECT'); | ||
if (isString(select)) { | ||
// remove function parms that may contain commas | ||
const cleanSelect = select.replace(/\((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\)/, ''); | ||
const fields = cleanSelect.split(','); | ||
if (fields.length > 1) { | ||
return fields[0].toLowerCase().endsWith('as time') ? Format.TIMESERIES : Format.TABLE; | ||
} | ||
} | ||
return Format.TABLE; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters