From 009b773b6eb25cb147ec28d727fba27a9b93608a Mon Sep 17 00:00:00 2001 From: xige-16 Date: Fri, 6 May 2022 15:59:51 +0800 Subject: [PATCH] Delete set default type param max_len for varchar field (#16794) Signed-off-by: xige-16 --- internal/proxy/task.go | 2 +- internal/proxy/task_test.go | 21 +++++++++++++++++-- internal/proxy/util.go | 11 ++-------- tests/python_client/requirements.txt | 2 +- .../testcases/test_collection.py | 2 +- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/internal/proxy/task.go b/internal/proxy/task.go index 162b215f36..c9c5b9770c 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -664,7 +664,7 @@ func (cct *createCollectionTask) PreExecute(ctx context.Context) error { } } // valid max length per row parameters - // if max_length_per_row not specified, set default value + // if max_length_per_row not specified, return error if field.DataType == schemapb.DataType_VarChar { err = validateMaxLengthPerRow(cct.schema.Name, field) if err != nil { diff --git a/internal/proxy/task_test.go b/internal/proxy/task_test.go index fd7ca0f423..813eda76d1 100644 --- a/internal/proxy/task_test.go +++ b/internal/proxy/task_test.go @@ -817,9 +817,13 @@ func TestCreateCollectionTask(t *testing.T) { collectionName := prefix + funcutil.GenRandomStr() int64Field := "int64" floatVecField := "fvec" - dim := 128 + varCharField := "varChar" - schema := constructCollectionSchema(int64Field, floatVecField, dim, collectionName) + fieldName2Type := make(map[string]schemapb.DataType) + fieldName2Type[int64Field] = schemapb.DataType_Int64 + fieldName2Type[varCharField] = schemapb.DataType_VarChar + fieldName2Type[floatVecField] = schemapb.DataType_FloatVector + schema := constructCollectionSchemaByDataType(collectionName, fieldName2Type, int64Field, false) var marshaledSchema []byte marshaledSchema, err := proto.Marshal(schema) assert.NoError(t, err) @@ -976,6 +980,19 @@ func TestCreateCollectionTask(t *testing.T) { err = task.PreExecute(ctx) assert.Error(t, err) + // validateMaxLengthPerRow + schema = proto.Clone(schemaBackup).(*schemapb.CollectionSchema) + for idx := range schema.Fields { + if schema.Fields[idx].DataType == schemapb.DataType_VarChar { + schema.Fields[idx].TypeParams = nil + } + } + noTypeParamsSchema, err := proto.Marshal(schema) + assert.NoError(t, err) + task.CreateCollectionRequest.Schema = noTypeParamsSchema + err = task.PreExecute(ctx) + assert.Error(t, err) + // ValidateVectorField schema = proto.Clone(schemaBackup).(*schemapb.CollectionSchema) for idx := range schema.Fields { diff --git a/internal/proxy/util.go b/internal/proxy/util.go index 78c5d19b29..c266d1c828 100644 --- a/internal/proxy/util.go +++ b/internal/proxy/util.go @@ -22,9 +22,6 @@ import ( "strconv" "strings" - "go.uber.org/zap" - - "github.com/milvus-io/milvus/internal/log" "github.com/milvus-io/milvus/internal/proto/commonpb" "github.com/milvus-io/milvus/internal/proto/schemapb" ) @@ -200,13 +197,9 @@ func validateMaxLengthPerRow(collectionName string, field *schemapb.FieldSchema) } exist = true } - // if not exist, set default max length + // if not exist type params max_length_per_row, return error if !exist { - log.Info("append default maxLengthPerRow for varChar field", zap.String("collection name", collectionName)) - field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{ - Key: maxVarCharLengthKey, - Value: strconv.Itoa(defaultMaxVarCharLength), - }) + return fmt.Errorf("type param(max_length_per_row) should be specified for varChar field of collection %s", collectionName) } return nil diff --git a/tests/python_client/requirements.txt b/tests/python_client/requirements.txt index c27dc94718..d4abc0b03c 100644 --- a/tests/python_client/requirements.txt +++ b/tests/python_client/requirements.txt @@ -9,7 +9,7 @@ allure-pytest==2.7.0 pytest-print==0.2.1 pytest-level==0.1.1 pytest-xdist==2.2.1 -pymilvus==2.1.0.dev36 +pymilvus==2.1.0.dev44 pytest-rerunfailures==9.1.1 git+https://github.com/Projectplace/pytest-tags ndg-httpsclient diff --git a/tests/python_client/testcases/test_collection.py b/tests/python_client/testcases/test_collection.py index 91b827a9e8..819bba0cdb 100644 --- a/tests/python_client/testcases/test_collection.py +++ b/tests/python_client/testcases/test_collection.py @@ -1064,7 +1064,7 @@ class TestCollectionOperation(TestcaseBase): self._connect() fields = [] for k, v in DataType.__members__.items(): - if v and v != DataType.UNKNOWN and v != DataType.STRING and v != DataType.FLOAT_VECTOR and v != DataType.BINARY_VECTOR: + if v and v != DataType.UNKNOWN and v != DataType.STRING and v != DataType.VARCHAR and v != DataType.FLOAT_VECTOR and v != DataType.BINARY_VECTOR: field, _ = self.field_schema_wrap.init_field_schema(name=k.lower(), dtype=v) fields.append(field) fields.append(cf.gen_float_vec_field())