diff --git a/query/vector_test.go b/query/vector_test.go index b48a72e5e34..a387b4d8479 100644 --- a/query/vector_test.go +++ b/query/vector_test.go @@ -487,6 +487,49 @@ func TestVectorUpdate(t *testing.T) { } } +func TestVectorWithoutQuote(t *testing.T) { + pred := "test-ve" + dropPredicate(pred) + setSchema(fmt.Sprintf(vectorSchemaWithIndex, pred, "4", "euclidian")) + + setJson := ` +{ + "set": [ + { + "test-ve": [1,0], + "v-name":"ve1" + }, + { + "test-ve": [0.866025,0.5], + "v-name":"ve2" + }, + { + "test-ve": [0.5,0.866025], + "v-name":"ve3" + }, + { + "test-ve": [0,1], + "v-name":"ve4" + }, + { + "test-ve": [-0.5,0.866025], + "v-name":"ve5" + }, + { + "test-ve": [-0.866025,0.5], + "v-name":"ve6" + } + ] + } + ` + txn1 := client.NewTxn() + _, err := txn1.Mutate(context.Background(), &api.Mutation{ + SetJson: []byte(setJson), + }) + require.Error(t, err) + require.Contains(t, err.Error(), "Input for predicate \"test-ve\" of type vector is not vector") +} + func TestVectorTwoTxnWithoutCommit(t *testing.T) { pred := "vtest" dropPredicate(pred) diff --git a/worker/mutation.go b/worker/mutation.go index 2c3d80792a4..abae1515dde 100644 --- a/worker/mutation.go +++ b/worker/mutation.go @@ -542,6 +542,13 @@ func ValidateAndConvert(edge *pb.DirectedEdge, su *pb.SchemaUpdate) error { return errors.Errorf("Input for predicate %q of type scalar is uid. Edge: %v", x.ParseAttr(edge.Attr), edge) + case schemaType == types.TypeID(pb.Posting_VFLOAT): + if !(storageType == types.TypeID(pb.Posting_VFLOAT) || storageType == types.TypeID(pb.Posting_STRING) || + storageType == types.TypeID(pb.Posting_DEFAULT)) { + return errors.Errorf("Input for predicate %q of type vector is not vector."+ + " Did you forget to add quotes before []?. Edge: %v", x.ParseAttr(edge.Attr), edge) + } + // The suggested storage type matches the schema, OK! (Nothing to do ...) case storageType == schemaType && schemaType != types.DefaultID: return nil