未验证 提交 d78b17f4 编写于 作者: J Jiquan Long 提交者: GitHub

Forbid deleting entities by non-pk field (#21459) (#21472)

Signed-off-by: Nlongjiquan <jiquan.long@zilliz.com>
上级 109cda62
......@@ -122,6 +122,10 @@ func getPrimaryKeysFromExpr(schema *schemapb.CollectionSchema, expr string) (res
return res, 0, fmt.Errorf("invalid plan node type, only pk in [1, 2] supported")
}
if !termExpr.TermExpr.GetColumnInfo().GetIsPrimaryKey() {
return res, 0, fmt.Errorf("invalid expression, we only support to delete by pk, expr: %s", expr)
}
res = &schemapb.IDs{}
rowNum = int64(len(termExpr.TermExpr.Values))
switch termExpr.TermExpr.ColumnInfo.GetDataType() {
......
package proxy
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus-proto/go-api/schemapb"
"github.com/milvus-io/milvus/internal/common"
)
func Test_getPrimaryKeysFromExpr(t *testing.T) {
t.Run("delete on non-pk field", func(t *testing.T) {
schema := &schemapb.CollectionSchema{
Name: "test_delete",
Description: "",
AutoID: false,
Fields: []*schemapb.FieldSchema{
{
FieldID: common.StartOfUserFieldID,
Name: "pk",
IsPrimaryKey: true,
DataType: schemapb.DataType_Int64,
},
{
FieldID: common.StartOfUserFieldID + 1,
Name: "non_pk",
IsPrimaryKey: false,
DataType: schemapb.DataType_Int64,
},
},
}
expr := "non_pk in [1, 2, 3]"
_, _, err := getPrimaryKeysFromExpr(schema, expr)
assert.Error(t, err)
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册