report an error when an ID is used on a keyed field

This commit is contained in:
Nia Weiss 2020-11-25 11:37:18 -05:00
parent 9e3e0a6be7
commit 353fd3937d
No known key found for this signature in database
GPG key ID: 895E83409BFDA1BB
2 changed files with 9 additions and 1 deletions

View file

@ -5593,7 +5593,7 @@ func fieldValidateValue(f *Field, val interface{}) error {
switch val := val.(type) {
case string:
if !f.Keys() {
return errors.Errorf("string value on an unkeyed field %q", f.Name())
return errors.Errorf("string value on unkeyed field %q", f.Name())
}
return nil
case *pql.Condition:
@ -5628,6 +5628,9 @@ func fieldValidateValue(f *Field, val interface{}) error {
default:
return errors.Errorf("invalid value %v for field %q of type %s", v, f.Name(), f.Type())
}
if f.Keys() {
return errors.Errorf("found integer ID %d on keyed field %q", val, f.Name())
}
case FieldTypeBool:
switch v := val.(type) {
case bool:

View file

@ -4933,6 +4933,7 @@ func TestExecutor_Execute_Query_Error(t *testing.T) {
c.CreateField(t, "i", pilosa.IndexOptions{}, "integer", pilosa.OptFieldTypeInt(-1000, 1000))
c.CreateField(t, "i", pilosa.IndexOptions{}, "decimal", pilosa.OptFieldTypeDecimal(2))
c.CreateField(t, "i", pilosa.IndexOptions{}, "bool", pilosa.OptFieldTypeBool())
c.CreateField(t, "i", pilosa.IndexOptions{}, "keys", pilosa.OptFieldKeys())
tests := []struct {
query string
@ -4978,6 +4979,10 @@ func TestExecutor_Execute_Query_Error(t *testing.T) {
query: "Rows(bool)",
error: "bool fields not supported by Rows() query",
},
{
query: `Row(keys=1)`,
error: `found integer ID 1 on keyed field "keys"`,
},
}
for i, test := range tests {