Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vector): Show error is invalid input is provided to vector predicate #9064

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions worker/mutation.go
Original file line number Diff line number Diff line change
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