Skip to content

Commit

Permalink
fix(vector): show error is invalid input is provided to vector predic…
Browse files Browse the repository at this point in the history
…ate (#9064)
  • Loading branch information
harshil-goel committed Apr 5, 2024
1 parent 2aeef65 commit 1777329
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
43 changes: 43 additions & 0 deletions query/vector_test.go
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions worker/mutation.go
Expand Up @@ -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
Expand Down

0 comments on commit 1777329

Please sign in to comment.