From 1a1a0924c28098573302a68474c79e1d97d01fe0 Mon Sep 17 00:00:00 2001 From: congqixia Date: Tue, 20 Feb 2024 14:18:44 +0800 Subject: [PATCH] enhance: Remove varchar column cannot use auto ID constraint (#665) Signed-off-by: Congqi Xia --- client/collection.go | 3 --- client/collection_test.go | 7 ------- test/testcases/collection_test.go | 7 +++---- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/client/collection.go b/client/collection.go index 8f53d13f..4396eb02 100644 --- a/client/collection.go +++ b/client/collection.go @@ -204,9 +204,6 @@ func (c *GrpcClient) validateSchema(sch *entity.Schema) error { if autoID { return errors.New("only one auto id is available") } - if field.DataType != entity.FieldTypeInt64 { - return errors.New("only int64 column can be auto generated id") - } autoID = true } if field.DataType == entity.FieldTypeJSON { diff --git a/client/collection_test.go b/client/collection_test.go index fc144b35..6fb3dd1e 100644 --- a/client/collection_test.go +++ b/client/collection_test.go @@ -374,13 +374,6 @@ func (s *CollectionSuite) TestNewCollection() { err := c.NewCollection(ctx, testCollectionName, testVectorDim, WithPKFieldName("my_pk"), WithPKFieldType(entity.FieldTypeVarChar), WithVectorFieldName("embedding"), WithConsistencyLevel(entity.ClEventually)) s.NoError(err) }) - - s.Run("varchar_autoid", func() { - defer s.resetMock() - - err := c.NewCollection(ctx, testCollectionName, testVectorDim, WithPKFieldType(entity.FieldTypeVarChar), WithAutoID(true)) - s.Error(err) - }) } func (s *CollectionSuite) TestRenameCollection() { diff --git a/test/testcases/collection_test.go b/test/testcases/collection_test.go index 2ca15a53..8d18c8b9 100644 --- a/test/testcases/collection_test.go +++ b/test/testcases/collection_test.go @@ -220,20 +220,19 @@ func TestCreateCollectionNonInt64AutoField(t *testing.T) { entity.FieldTypeInt32, entity.FieldTypeFloat, entity.FieldTypeDouble, - entity.FieldTypeVarChar, + // entity.FieldTypeVarChar, entity.FieldTypeString, entity.FieldTypeNone, entity.FieldTypeJSON, } for _, fieldType := range invalidPkFields { fields := []*entity.Field{ - common.GenField("non-auto-id", fieldType, common.WithAutoID(true)), - common.GenField(common.DefaultIntFieldName, entity.FieldTypeInt64, common.WithIsPrimaryKey(true), common.WithAutoID(true)), + common.GenField(common.DefaultIntFieldName, fieldType, common.WithIsPrimaryKey(true), common.WithAutoID(true)), common.GenField(common.DefaultFloatVecFieldName, entity.FieldTypeFloatVector, common.WithDim(common.DefaultDim)), } schema := common.GenSchema(common.GenRandomString(6), true, fields) errNonInt64Field := mc.CreateCollection(ctx, schema, common.DefaultShards) - common.CheckErr(t, errNonInt64Field, false, "only int64 column can be auto generated id") + common.CheckErr(t, errNonInt64Field, false, "only int64 and varchar column can be primary key for now") } }