mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
FB-1387: Grafana Empty Variable Select (#2032)
Fixed the issue where deselecting variables didn't work on quries like groupby and extract. The empty variables list returns All() when the variables are empty.
This commit is contained in:
parent
0e37e04f47
commit
eba7927b56
2 changed files with 20 additions and 9 deletions
|
|
@ -1014,7 +1014,6 @@ func (c *Call) ExpandVars(vars map[string]interface{}) ([]*Call, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch len(newArg) {
|
||||
case 0:
|
||||
if call.Name == "Row" {
|
||||
|
|
@ -1051,7 +1050,8 @@ func (c *Call) expandVars(name string, values []interface{}) []*Call {
|
|||
switch c.Name {
|
||||
case "Row":
|
||||
if len(values) == 0 {
|
||||
return []*Call{}
|
||||
cc := &Call{Name: "All"}
|
||||
return []*Call{cc}
|
||||
}
|
||||
union := &Call{Name: "Union"}
|
||||
for i := range values {
|
||||
|
|
|
|||
|
|
@ -81,11 +81,10 @@ func TestQuery_ExpandVars(t *testing.T) {
|
|||
vars: map[string]interface{}{"var1": []interface{}{"cat"}},
|
||||
},
|
||||
{
|
||||
name: "ExpandRowEQExterior-NoValues",
|
||||
input: `row(animal=$var1)`,
|
||||
output: ``,
|
||||
vars: map[string]interface{}{"var1": []interface{}{}},
|
||||
wantErr: true,
|
||||
name: "ExpandRowEQExterior-NoValues",
|
||||
input: `row(animal=$var1)`,
|
||||
output: `All()`,
|
||||
vars: map[string]interface{}{"var1": []interface{}{}},
|
||||
},
|
||||
{
|
||||
name: "ExpandRowGT",
|
||||
|
|
@ -184,7 +183,7 @@ func TestQuery_ExpandVars(t *testing.T) {
|
|||
{
|
||||
name: "ExpandAsCSV-NoValues",
|
||||
input: `Intersect(ConstRow(columns=$var2), Row(animal=$var1))`,
|
||||
output: `Intersect(ConstRow(columns=[]))`,
|
||||
output: `Intersect(ConstRow(columns=[]), All())`,
|
||||
vars: map[string]interface{}{"var1": []interface{}{}, "var2": []interface{}{}},
|
||||
},
|
||||
{
|
||||
|
|
@ -202,7 +201,7 @@ func TestQuery_ExpandVars(t *testing.T) {
|
|||
{
|
||||
name: "Union-NoValues-1",
|
||||
input: `Count(Union(row(x=$var1), row(y=$var2)), limit=5)`,
|
||||
output: `Count(Union(Union(Row(y="cat"), Row(y="dog"))), limit=5)`,
|
||||
output: `Count(Union(All(), Union(Row(y="cat"), Row(y="dog"))), limit=5)`,
|
||||
vars: map[string]interface{}{"var1": []interface{}{}, "var2": []interface{}{"cat", "dog"}},
|
||||
},
|
||||
{
|
||||
|
|
@ -230,6 +229,18 @@ func TestQuery_ExpandVars(t *testing.T) {
|
|||
output: `Extract(Limit(All(), limit=1000), Rows(_field="a"), Rows(_field="b"))`,
|
||||
vars: map[string]interface{}{"var1": []interface{}{}, "var2": []interface{}{"a", "b"}},
|
||||
},
|
||||
{
|
||||
name: "Extract-SomeValues-1",
|
||||
input: `Extract(Union(Row(x=$var1), Row(y=$var2)), Rows(a), Rows(b))`,
|
||||
output: `Extract(Union(Union(Row(x="cat"), Row(x="dog")), All()), Rows(_field="a"), Rows(_field="b"))`,
|
||||
vars: map[string]interface{}{"var1": []interface{}{"cat", "dog"}, "var2": []interface{}{}},
|
||||
},
|
||||
{
|
||||
name: "GroupBy-SomeValues-1",
|
||||
input: `GroupBy(Rows(a), Rows(b), filter=Union(Row(x=$var1), Row(y=$var2)), limit=10)`,
|
||||
output: `GroupBy(Rows(_field="a"), Rows(_field="b"), filter=Union(All(), Union(Row(y="cat"), Row(y="dog"))), limit=10)`,
|
||||
vars: map[string]interface{}{"var1": []interface{}{}, "var2": []interface{}{"cat", "dog"}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue