From 8669153ff2edaa82e944ae5f4d891a1321d75a5d Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Fri, 18 Oct 2024 12:57:26 +0800 Subject: [PATCH] fix: not add isClusteringKey when describe collection (#36930) #36928 Signed-off-by: lixinguo Co-authored-by: lixinguo --- .../distributed/proxy/httpserver/constant.go | 1 + .../proxy/httpserver/handler_v1_test.go | 6 +- .../proxy/httpserver/handler_v2.go | 13 +- .../distributed/proxy/httpserver/utils.go | 11 +- .../proxy/httpserver/utils_test.go | 142 ++++++++++-------- 5 files changed, 93 insertions(+), 80 deletions(-) diff --git a/internal/distributed/proxy/httpserver/constant.go b/internal/distributed/proxy/httpserver/constant.go index a07bdbec65..b064c69e6a 100644 --- a/internal/distributed/proxy/httpserver/constant.go +++ b/internal/distributed/proxy/httpserver/constant.go @@ -100,6 +100,7 @@ const ( HTTPReturnFieldType = "type" HTTPReturnFieldPrimaryKey = "primaryKey" HTTPReturnFieldPartitionKey = "partitionKey" + HTTPReturnFieldClusteringKey = "clusteringKey" HTTPReturnFieldAutoID = "autoId" HTTPReturnFieldElementType = "elementType" HTTPReturnDescription = "description" diff --git a/internal/distributed/proxy/httpserver/handler_v1_test.go b/internal/distributed/proxy/httpserver/handler_v1_test.go index bd485108e3..185f5373d2 100644 --- a/internal/distributed/proxy/httpserver/handler_v1_test.go +++ b/internal/distributed/proxy/httpserver/handler_v1_test.go @@ -277,7 +277,7 @@ func TestVectorCollectionsDescribe(t *testing.T) { name: "get load status fail", mp: mp2, exceptCode: http.StatusOK, - expectedBody: "{\"code\":200,\"data\":{\"collectionName\":\"" + DefaultCollectionName + "\",\"description\":\"\",\"enableDynamicField\":true,\"fields\":[{\"autoId\":false,\"description\":\"\",\"name\":\"book_id\",\"partitionKey\":false,\"primaryKey\":true,\"type\":\"Int64\"},{\"autoId\":false,\"description\":\"\",\"name\":\"word_count\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"Int64\"},{\"autoId\":false,\"description\":\"\",\"name\":\"book_intro\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"FloatVector(2)\"}],\"indexes\":[{\"fieldName\":\"book_intro\",\"indexName\":\"" + DefaultIndexName + "\",\"metricType\":\"COSINE\"}],\"load\":\"\",\"shardsNum\":1}}", + expectedBody: "{\"code\":200,\"data\":{\"collectionName\":\"" + DefaultCollectionName + "\",\"description\":\"\",\"enableDynamicField\":true,\"fields\":[{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"book_id\",\"partitionKey\":false,\"primaryKey\":true,\"type\":\"Int64\"},{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"word_count\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"Int64\"},{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"book_intro\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"FloatVector(2)\"}],\"indexes\":[{\"fieldName\":\"book_intro\",\"indexName\":\"" + DefaultIndexName + "\",\"metricType\":\"COSINE\"}],\"load\":\"\",\"shardsNum\":1}}", }) mp3 := mocks.NewMockProxy(t) @@ -288,7 +288,7 @@ func TestVectorCollectionsDescribe(t *testing.T) { name: "get indexes fail", mp: mp3, exceptCode: http.StatusOK, - expectedBody: "{\"code\":200,\"data\":{\"collectionName\":\"" + DefaultCollectionName + "\",\"description\":\"\",\"enableDynamicField\":true,\"fields\":[{\"autoId\":false,\"description\":\"\",\"name\":\"book_id\",\"partitionKey\":false,\"primaryKey\":true,\"type\":\"Int64\"},{\"autoId\":false,\"description\":\"\",\"name\":\"word_count\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"Int64\"},{\"autoId\":false,\"description\":\"\",\"name\":\"book_intro\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"FloatVector(2)\"}],\"indexes\":[],\"load\":\"LoadStateLoaded\",\"shardsNum\":1}}", + expectedBody: "{\"code\":200,\"data\":{\"collectionName\":\"" + DefaultCollectionName + "\",\"description\":\"\",\"enableDynamicField\":true,\"fields\":[{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"book_id\",\"partitionKey\":false,\"primaryKey\":true,\"type\":\"Int64\"},{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"word_count\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"Int64\"},{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"book_intro\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"FloatVector(2)\"}],\"indexes\":[],\"load\":\"LoadStateLoaded\",\"shardsNum\":1}}", }) mp4 := mocks.NewMockProxy(t) @@ -299,7 +299,7 @@ func TestVectorCollectionsDescribe(t *testing.T) { name: "show collection details success", mp: mp4, exceptCode: http.StatusOK, - expectedBody: "{\"code\":200,\"data\":{\"collectionName\":\"" + DefaultCollectionName + "\",\"description\":\"\",\"enableDynamicField\":true,\"fields\":[{\"autoId\":false,\"description\":\"\",\"name\":\"book_id\",\"partitionKey\":false,\"primaryKey\":true,\"type\":\"Int64\"},{\"autoId\":false,\"description\":\"\",\"name\":\"word_count\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"Int64\"},{\"autoId\":false,\"description\":\"\",\"name\":\"book_intro\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"FloatVector(2)\"}],\"indexes\":[{\"fieldName\":\"book_intro\",\"indexName\":\"" + DefaultIndexName + "\",\"metricType\":\"COSINE\"}],\"load\":\"LoadStateLoaded\",\"shardsNum\":1}}", + expectedBody: "{\"code\":200,\"data\":{\"collectionName\":\"" + DefaultCollectionName + "\",\"description\":\"\",\"enableDynamicField\":true,\"fields\":[{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"book_id\",\"partitionKey\":false,\"primaryKey\":true,\"type\":\"Int64\"},{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"word_count\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"Int64\"},{\"autoId\":false,\"clusteringKey\":false,\"description\":\"\",\"name\":\"book_intro\",\"partitionKey\":false,\"primaryKey\":false,\"type\":\"FloatVector(2)\"}],\"indexes\":[{\"fieldName\":\"book_intro\",\"indexName\":\"" + DefaultIndexName + "\",\"metricType\":\"COSINE\"}],\"load\":\"LoadStateLoaded\",\"shardsNum\":1}}", }) for _, tt := range testCases { diff --git a/internal/distributed/proxy/httpserver/handler_v2.go b/internal/distributed/proxy/httpserver/handler_v2.go index 1cdc27c53f..a2a1d21a72 100644 --- a/internal/distributed/proxy/httpserver/handler_v2.go +++ b/internal/distributed/proxy/httpserver/handler_v2.go @@ -1254,12 +1254,13 @@ func (h *HandlersV2) createCollection(ctx context.Context, c *gin.Context, anyRe } dataType := schemapb.DataType(fieldDataType) fieldSchema := schemapb.FieldSchema{ - Name: field.FieldName, - IsPrimaryKey: field.IsPrimary, - IsPartitionKey: field.IsPartitionKey, - DataType: dataType, - TypeParams: []*commonpb.KeyValuePair{}, - Nullable: field.Nullable, + Name: field.FieldName, + IsPrimaryKey: field.IsPrimary, + IsPartitionKey: field.IsPartitionKey, + IsClusteringKey: field.IsClusteringKey, + DataType: dataType, + TypeParams: []*commonpb.KeyValuePair{}, + Nullable: field.Nullable, } fieldSchema.DefaultValue, err = convertDefaultValue(field.DefaultValue, dataType) diff --git a/internal/distributed/proxy/httpserver/utils.go b/internal/distributed/proxy/httpserver/utils.go index 36e807bafe..76ea4013db 100644 --- a/internal/distributed/proxy/httpserver/utils.go +++ b/internal/distributed/proxy/httpserver/utils.go @@ -166,11 +166,12 @@ func printFieldsV2(fields []*schemapb.FieldSchema) []gin.H { func printFieldDetail(field *schemapb.FieldSchema, oldVersion bool) gin.H { fieldDetail := gin.H{ - HTTPReturnFieldName: field.Name, - HTTPReturnFieldPrimaryKey: field.IsPrimaryKey, - HTTPReturnFieldPartitionKey: field.IsPartitionKey, - HTTPReturnFieldAutoID: field.AutoID, - HTTPReturnDescription: field.Description, + HTTPReturnFieldName: field.Name, + HTTPReturnFieldPrimaryKey: field.IsPrimaryKey, + HTTPReturnFieldPartitionKey: field.IsPartitionKey, + HTTPReturnFieldClusteringKey: field.IsClusteringKey, + HTTPReturnFieldAutoID: field.AutoID, + HTTPReturnDescription: field.Description, } if field.GetIsFunctionOutput() { fieldDetail[HTTPReturnFieldIsFunctionOutput] = true diff --git a/internal/distributed/proxy/httpserver/utils_test.go b/internal/distributed/proxy/httpserver/utils_test.go index e0d6f88be7..6d5281da83 100644 --- a/internal/distributed/proxy/httpserver/utils_test.go +++ b/internal/distributed/proxy/httpserver/utils_test.go @@ -386,57 +386,63 @@ func TestPrintCollectionDetails(t *testing.T) { indexes := generateIndexes() assert.Equal(t, []gin.H{ { - HTTPReturnFieldName: FieldBookID, - HTTPReturnFieldType: "Int64", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: true, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", + HTTPReturnFieldName: FieldBookID, + HTTPReturnFieldType: "Int64", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: true, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", }, { - HTTPReturnFieldName: FieldWordCount, - HTTPReturnFieldType: "Int64", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: false, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", + HTTPReturnFieldName: FieldWordCount, + HTTPReturnFieldType: "Int64", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: false, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", }, { - HTTPReturnFieldName: FieldBookIntro, - HTTPReturnFieldType: "FloatVector(2)", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: false, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", + HTTPReturnFieldName: FieldBookIntro, + HTTPReturnFieldType: "FloatVector(2)", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: false, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", }, }, printFields(coll.Fields)) assert.Equal(t, []gin.H{ { - HTTPReturnFieldName: FieldBookID, - HTTPReturnFieldType: "Int64", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: true, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", - HTTPReturnFieldID: int64(100), + HTTPReturnFieldName: FieldBookID, + HTTPReturnFieldType: "Int64", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: true, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", + HTTPReturnFieldID: int64(100), }, { - HTTPReturnFieldName: FieldWordCount, - HTTPReturnFieldType: "Int64", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: false, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", - HTTPReturnFieldID: int64(101), + HTTPReturnFieldName: FieldWordCount, + HTTPReturnFieldType: "Int64", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: false, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", + HTTPReturnFieldID: int64(101), }, { - HTTPReturnFieldName: FieldBookIntro, - HTTPReturnFieldType: "FloatVector", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: false, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", - HTTPReturnFieldID: int64(201), + HTTPReturnFieldName: FieldBookIntro, + HTTPReturnFieldType: "FloatVector", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: false, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", + HTTPReturnFieldID: int64(201), Params: []*commonpb.KeyValuePair{ {Key: Dim, Value: "2"}, }, @@ -461,44 +467,48 @@ func TestPrintCollectionDetails(t *testing.T) { } assert.Equal(t, []gin.H{ { - HTTPReturnFieldName: "field-varchar", - HTTPReturnFieldType: "VarChar(10)", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: false, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", + HTTPReturnFieldName: "field-varchar", + HTTPReturnFieldType: "VarChar(10)", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: false, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", }, { - HTTPReturnFieldName: "field-array", - HTTPReturnFieldType: "Array", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: false, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", + HTTPReturnFieldName: "field-array", + HTTPReturnFieldType: "Array", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: false, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", }, }, printFields(fields)) assert.Equal(t, []gin.H{ { - HTTPReturnFieldName: "field-varchar", - HTTPReturnFieldType: "VarChar", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: false, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", - HTTPReturnFieldID: int64(0), + HTTPReturnFieldName: "field-varchar", + HTTPReturnFieldType: "VarChar", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldPrimaryKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", + HTTPReturnFieldID: int64(0), Params: []*commonpb.KeyValuePair{ {Key: common.MaxLengthKey, Value: "10"}, }, }, { - HTTPReturnFieldName: "field-array", - HTTPReturnFieldType: "Array", - HTTPReturnFieldPartitionKey: false, - HTTPReturnFieldPrimaryKey: false, - HTTPReturnFieldAutoID: false, - HTTPReturnDescription: "", - HTTPReturnFieldID: int64(0), - HTTPReturnFieldElementType: "Bool", + HTTPReturnFieldName: "field-array", + HTTPReturnFieldType: "Array", + HTTPReturnFieldPartitionKey: false, + HTTPReturnFieldClusteringKey: false, + HTTPReturnFieldPrimaryKey: false, + HTTPReturnFieldAutoID: false, + HTTPReturnDescription: "", + HTTPReturnFieldID: int64(0), + HTTPReturnFieldElementType: "Bool", }, }, printFieldsV2(fields)) }