From 353fd3937dd09d5b7e2282b695f24e8dd7638d4f Mon Sep 17 00:00:00 2001 From: Nia Weiss Date: Wed, 25 Nov 2020 11:37:18 -0500 Subject: [PATCH] report an error when an ID is used on a keyed field --- executor.go | 5 ++++- executor_test.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/executor.go b/executor.go index 641d8866a..d91f66d80 100644 --- a/executor.go +++ b/executor.go @@ -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: diff --git a/executor_test.go b/executor_test.go index 29e843d6e..11a774014 100644 --- a/executor_test.go +++ b/executor_test.go @@ -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 {