fix: to add check in partition key field when set nullable==true (#36218)

#36213

Signed-off-by: lixinguo <xinguo.li@zilliz.com>
Co-authored-by: lixinguo <xinguo.li@zilliz.com>
pull/36251/head^2
smellthemoon 2024-09-14 10:53:08 +08:00 committed by GitHub
parent 3bc7d63be9
commit 2d05b7f219
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -219,6 +219,10 @@ func (t *createCollectionTask) validatePartitionKey() error {
return errors.New("the partition key field must not be primary field")
}
if field.GetNullable() {
return merr.WrapErrParameterInvalidMsg("partition key field not support nullable")
}
// The type of the partition key field can only be int64 and varchar
if field.DataType != schemapb.DataType_Int64 && field.DataType != schemapb.DataType_VarChar {
return errors.New("the data type of partition key should be Int64 or VarChar")

View File

@ -3216,6 +3216,16 @@ func TestCreateCollectionTaskWithPartitionKey(t *testing.T) {
assert.Error(t, err)
partitionKeyField.DataType = schemapb.DataType_Int64
// test partition key set nullable == true
partitionKeyField.Nullable = true
marshaledSchema, err = proto.Marshal(schema)
assert.NoError(t, err)
task.Schema = marshaledSchema
err = task.PreExecute(ctx)
assert.Error(t, err)
partitionKeyField.DataType = schemapb.DataType_Int64
partitionKeyField.Nullable = false
// test partition key field not primary key field
primaryField, _ := typeutil.GetPrimaryFieldSchema(schema)
primaryField.IsPartitionKey = true