Check result before return

This commit is contained in:
Kuba Podgórski 2020-06-08 13:53:05 +02:00
parent a519907822
commit 9c3b080bf0
2 changed files with 28 additions and 1 deletions

View file

@ -3107,7 +3107,15 @@ func (e *executor) executeSetRow(ctx context.Context, indexName string, c *pql.C
}
result, err := e.mapReduce(ctx, indexName, shards, c, opt, mapFn, reduceFn)
return result.(bool), err
if err != nil {
return false, err
}
b, ok := result.(bool)
if !ok {
return false, errors.New("unsupported result type")
}
return b, nil
}
// executeSetRowShard executes a SetRow() call for a single shard.

View file

@ -4018,6 +4018,25 @@ func TestExecutor_Execute_SetRow(t *testing.T) {
t.Fatalf("unexpected columns: %+v", bits)
}
})
t.Run("Err_Store(Distinct)", func(t *testing.T) {
c := test.MustRunCluster(t, 1)
defer c.Close()
hldr := test.Holder{Holder: c[0].Server.Holder()}
index := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{TrackExistence: true})
f1, err := index.CreateField("f1", pilosa.OptFieldTypeDefault())
if err != nil {
t.Fatal(err)
}
f2, err := index.CreateField("f2", pilosa.OptFieldTypeDefault())
if err != nil {
t.Fatal(err)
}
q := fmt.Sprintf(`Store(Distinct(field=%s), %s=2)`, f1.Name(), f2.Name())
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: index.Name(), Query: q}); err == nil {
t.Fatalf("expected 'unsupported result type' error, got: %+v", res)
}
})
}
func benchmarkExistence(nn bool, b *testing.B) {