The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/expr/sql/parser_test.go

58 lines
1.1 KiB

package sql
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParse(t *testing.T) {
sql := "select * from foo"
tables, err := parseTables((sql))
assert.Nil(t, err)
assert.Equal(t, "FOO", tables[0])
}
func TestParseWithComma(t *testing.T) {
sql := "select * from foo,bar"
tables, err := parseTables((sql))
assert.Nil(t, err)
assert.Equal(t, "FOO", tables[0])
assert.Equal(t, "BAR", tables[1])
}
func TestParseWithCommas(t *testing.T) {
sql := "select * from foo,bar,baz"
tables, err := parseTables((sql))
assert.Nil(t, err)
assert.Equal(t, "FOO", tables[0])
assert.Equal(t, "BAR", tables[1])
assert.Equal(t, "BAZ", tables[2])
}
func TestArray(t *testing.T) {
sql := "SELECT array_value(1, 2, 3)"
tables, err := TablesList((sql))
assert.Nil(t, err)
assert.Equal(t, 0, len(tables))
}
func TestArray2(t *testing.T) {
sql := "SELECT array_value(1, 2, 3)[2]"
tables, err := TablesList((sql))
assert.Nil(t, err)
assert.Equal(t, 0, len(tables))
}
func TestXxx(t *testing.T) {
sql := "SELECT [3, 2, 1]::INT[3];"
tables, err := TablesList((sql))
assert.Nil(t, err)
assert.Equal(t, 0, len(tables))
}