fix Rows bug where Pilosa would crash without 'field' argument.

This commit is contained in:
Matt Jaffee 2018-12-21 11:55:25 -06:00
parent 03983255ba
commit 97eb94397f
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 37 additions and 1 deletions

View file

@ -2761,7 +2761,10 @@ func newGroupByIterator(rowIDs []RowIDs, children []*pql.Call, filter *Row, inde
ignorePrev := false
for i, call := range children {
fieldName := call.Args["field"].(string) // this has already been validated by this point
fieldName, ok := call.Args["field"].(string)
if !ok {
return nil, errors.Errorf("%s call must have 'field' argument", call.Name)
}
gbi.fields[i].Field = fieldName
// Fetch fragment.
frag := holder.fragment(index, fieldName, viewStandard, shard)

View file

@ -2672,6 +2672,39 @@ func TestExecutor_Execute_Rows(t *testing.T) {
if !reflect.DeepEqual(rows, pilosa.RowIdentifiers{Rows: []uint64{11, 12}}) {
t.Fatalf("unexpected rows: %+v", rows)
}
}
func TestExecutor_Execute_Rows_Error(t *testing.T) {
c := test.MustRunCluster(t, 3)
defer c.Close()
c.CreateField(t, "i", pilosa.IndexOptions{}, "general")
tests := []struct {
query string
error string
}{
{
query: "GroupBy(Rows())",
error: "Rows call must have 'field' argument",
},
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
r, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{
Index: "i",
Query: test.query,
})
if err == nil {
t.Fatalf("should have gotten an error on invalid rows query, but got %#v", r)
}
if !strings.Contains(err.Error(), test.error) {
t.Fatalf("unexpected error message: %s", err.Error())
}
})
}
}
func TestExecutor_Execute_Rows_Keys(t *testing.T) {