Skip to content

Commit

Permalink
fix(vector): Show error is invalid input is provided to vector predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Apr 5, 2024
1 parent 2aeef65 commit 2472a47
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
43 changes: 43 additions & 0 deletions query/vector_test.go
Original file line number Diff line number Diff line change
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
6 changes: 6 additions & 0 deletions worker/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ 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_DEFAULT) || storageType == types.TypeID(pb.Posting_STRING) || storageType == types.TypeID(pb.Posting_VFLOAT)) {

Check failure on line 546 in worker/mutation.go

View workflow job for this annotation

GitHub Actions / lint

line is 157 characters (lll)
return errors.Errorf("Input for predicate %q of type vector is not vector. Did you forget to add quotes before []?. Edge: %v",

Check failure on line 547 in worker/mutation.go

View workflow job for this annotation

GitHub Actions / lint

line is 129 characters (lll)
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 2472a47

Please sign in to comment.