Delete set default type param max_len for varchar field (#16794)

Signed-off-by: xige-16 <xi.ge@zilliz.com>
pull/16776/head^2
xige-16 2022-05-06 15:59:51 +08:00 committed by GitHub
parent 5022858894
commit 009b773b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 14 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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())