From 0feee53631917992119ebed32929fd2e7ff33e9e Mon Sep 17 00:00:00 2001 From: congqixia Date: Tue, 2 Apr 2024 20:35:14 +0800 Subject: [PATCH] enhance: Add back unit test for compactor and fix some TODOs (#31829) This PR adds back compactor "Unhandled" data type unit test and fixes some TODOs behvaior Signed-off-by: Congqi Xia --- internal/datanode/compactor.go | 5 +---- internal/datanode/compactor_test.go | 19 +++++++++---------- internal/querycoordv2/utils/meta.go | 4 +--- internal/querynodev2/segments/segment_l0.go | 12 +++++++----- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/internal/datanode/compactor.go b/internal/datanode/compactor.go index 787870d71c..5b11341b73 100644 --- a/internal/datanode/compactor.go +++ b/internal/datanode/compactor.go @@ -719,15 +719,12 @@ func interface2FieldData(schemaDataType schemapb.DataType, content []interface{} Data: make([]*schemapb.ScalarField, 0, len(content)), } - if len(content) > 0 { - data.ElementType = content[0].(*schemapb.ScalarField).GetArrayData().GetElementType() - } - for _, c := range content { r, ok := c.(*schemapb.ScalarField) if !ok { return nil, errTransferType } + data.ElementType = r.GetArrayData().GetElementType() data.Data = append(data.Data, r) } rst = data diff --git a/internal/datanode/compactor_test.go b/internal/datanode/compactor_test.go index 8d3b4305d7..2884ab8e8a 100644 --- a/internal/datanode/compactor_test.go +++ b/internal/datanode/compactor_test.go @@ -116,17 +116,16 @@ func TestCompactionTaskInnerMethods(t *testing.T) { } // make sure all new data types missed to handle would throw unexpected error - // todo(yah01): enable this after the BF16 vector type ready - // for typeName, typeValue := range schemapb.DataType_value { - // tests = append(tests, struct { - // isvalid bool + for typeName, typeValue := range schemapb.DataType_value { + tests = append(tests, struct { + isvalid bool - // tp schemapb.DataType - // content []interface{} + tp schemapb.DataType + content []interface{} - // description string - // }{false, schemapb.DataType(typeValue), []interface{}{nil, nil}, "invalid " + typeName}) - // } + description string + }{false, schemapb.DataType(typeValue), []interface{}{nil, nil}, "invalid " + typeName}) + } for _, test := range tests { t.Run(test.description, func(t *testing.T) { @@ -136,7 +135,7 @@ func TestCompactionTaskInnerMethods(t *testing.T) { assert.Equal(t, 2, fd.RowNum()) } else { fd, err := interface2FieldData(test.tp, test.content, 2) - assert.ErrorIs(t, err, errTransferType) + assert.True(t, errors.Is(err, errTransferType) || errors.Is(err, errUnknownDataType)) assert.Nil(t, fd) } }) diff --git a/internal/querycoordv2/utils/meta.go b/internal/querycoordv2/utils/meta.go index 31d72fb7d5..b6c568f393 100644 --- a/internal/querycoordv2/utils/meta.go +++ b/internal/querycoordv2/utils/meta.go @@ -17,7 +17,6 @@ package utils import ( - "fmt" "math/rand" "sort" @@ -62,8 +61,7 @@ func GetPartitions(collectionMgr *meta.CollectionManager, collectionID int64) ([ } } - // todo(yah01): replace this error with a defined error - return nil, fmt.Errorf("collection/partition not loaded") + return nil, merr.WrapErrCollectionNotLoaded(collectionID) } // GroupNodesByReplica groups nodes by replica, diff --git a/internal/querynodev2/segments/segment_l0.go b/internal/querynodev2/segments/segment_l0.go index 6bcd5913e8..6740ce457e 100644 --- a/internal/querynodev2/segments/segment_l0.go +++ b/internal/querynodev2/segments/segment_l0.go @@ -1,8 +1,10 @@ -// Copyright 2023 yah01 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// Licensed to the LF AI & Data foundation under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 //