Merge pull request #1848 from travisturner/clearrow-translate

ensure ClearRow() arguments get translated
This commit is contained in:
Travis Turner 2019-01-29 13:21:32 -06:00 committed by GitHub
commit 71c2053016
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -1693,6 +1693,9 @@ func (e *executor) executeClearRow(ctx context.Context, index string, c *pql.Cal
}
result, err := e.mapReduce(ctx, index, shards, c, opt, mapFn, reduceFn)
if err != nil {
return false, errors.Wrap(err, "mapreducing clearrow")
}
return result.(bool), err
}
@ -2368,7 +2371,7 @@ func (e *executor) translateCalls(ctx context.Context, index string, idx *Index,
func (e *executor) translateCall(index string, idx *Index, c *pql.Call) error {
var colKey, rowKey, fieldName string
switch c.Name {
case "Set", "Clear", "Row", "Range", "SetColumnAttrs":
case "Set", "Clear", "Row", "Range", "SetColumnAttrs", "ClearRow":
// Positional args in new PQL syntax require special handling here.
colKey = "_" + columnLabel
fieldName, _ = c.FieldArg()

View file

@ -2887,6 +2887,19 @@ func TestExecutor_Execute_ClearRow(t *testing.T) {
t.Fatalf("topn wrong results: %v", res.Results)
}
})
// Ensure that ClearRow returns false when the row to clear needs translation.
t.Run("WithKeys", func(t *testing.T) {
wq := ""
rq := []string{
`ClearRow(f="bar")`,
}
responses := runCallTest(t, wq, rq, &pilosa.IndexOptions{}, pilosa.OptFieldKeys())
if res := responses[0].Results[0].(bool); res {
t.Fatalf("unexpected result: %+v", res)
}
})
}
// Ensure a row can be set.