2021-04-19 11:32:24 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2020-12-09 20:07:27 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2020-12-23 11:34:35 +08:00
|
|
|
"fmt"
|
2020-12-09 20:07:27 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-09-29 09:52:12 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/funcutil"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/uniquegenerator"
|
|
|
|
|
2021-06-16 12:03:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/etcdpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2020-12-09 20:07:27 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-06-16 12:03:57 +08:00
|
|
|
"go.uber.org/zap"
|
2020-12-09 20:07:27 +08:00
|
|
|
)
|
|
|
|
|
2021-07-16 17:19:55 +08:00
|
|
|
const (
|
|
|
|
CollectionID = 1
|
|
|
|
PartitionID = 1
|
|
|
|
SegmentID = 1
|
|
|
|
RowIDField = 0
|
|
|
|
TimestampField = 1
|
|
|
|
BoolField = 100
|
|
|
|
Int8Field = 101
|
|
|
|
Int16Field = 102
|
|
|
|
Int32Field = 103
|
|
|
|
Int64Field = 104
|
|
|
|
FloatField = 105
|
|
|
|
DoubleField = 106
|
|
|
|
StringField = 107
|
|
|
|
BinaryVectorField = 108
|
|
|
|
FloatVectorField = 109
|
|
|
|
)
|
|
|
|
|
2020-12-11 11:29:07 +08:00
|
|
|
func TestInsertCodec(t *testing.T) {
|
2021-04-19 10:36:19 +08:00
|
|
|
schema := &etcdpb.CollectionMeta{
|
2021-07-16 17:19:55 +08:00
|
|
|
ID: CollectionID,
|
2020-12-23 18:06:04 +08:00
|
|
|
CreateTime: 1,
|
2021-07-16 17:19:55 +08:00
|
|
|
SegmentIDs: []int64{SegmentID},
|
2020-12-23 18:06:04 +08:00
|
|
|
PartitionTags: []string{"partition_0", "partition_1"},
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Name: "schema",
|
|
|
|
Description: "schema",
|
|
|
|
AutoID: true,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: RowIDField,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "row_id",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "row_id",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Int64,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: TimestampField,
|
|
|
|
Name: "Timestamp",
|
2020-12-23 18:06:04 +08:00
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "Timestamp",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Int64,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: BoolField,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_bool",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "bool",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Bool,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: Int8Field,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_int8",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "int8",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Int8,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: Int16Field,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_int16",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "int16",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Int16,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: Int32Field,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_int32",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "int32",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Int32,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: Int64Field,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_int64",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "int64",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Int64,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: FloatField,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_float",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "float",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Float,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: DoubleField,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_double",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "double",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_Double,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: StringField,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_string",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "string",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_String,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: BinaryVectorField,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_binary_vector",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "binary_vector",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_BinaryVector,
|
2020-12-23 18:06:04 +08:00
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: FloatVectorField,
|
2020-12-23 18:06:04 +08:00
|
|
|
Name: "field_float_vector",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "float_vector",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_FloatVector,
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-04-19 10:36:19 +08:00
|
|
|
insertCodec := NewInsertCodec(schema)
|
2021-07-16 17:19:55 +08:00
|
|
|
insertData1 := &InsertData{
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: map[int64]FieldData{
|
2021-07-16 17:19:55 +08:00
|
|
|
RowIDField: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []int64{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
TimestampField: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []int64{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
BoolField: &BoolFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []bool{true, false},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
Int8Field: &Int8FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []int8{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
Int16Field: &Int16FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []int16{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
Int32Field: &Int32FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []int32{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
Int64Field: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []int64{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
FloatField: &FloatFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []float32{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
DoubleField: &DoubleFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []float64{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
StringField: &StringFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []string{"3", "4"},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
BinaryVectorField: &BinaryVectorFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []byte{0, 255},
|
|
|
|
Dim: 8,
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
FloatVectorField: &FloatVectorFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-07-16 17:19:55 +08:00
|
|
|
Data: []float32{4, 5, 6, 7, 4, 5, 6, 7},
|
|
|
|
Dim: 4,
|
2020-12-23 11:34:35 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-07-16 17:19:55 +08:00
|
|
|
insertData2 := &InsertData{
|
2020-12-11 11:29:07 +08:00
|
|
|
Data: map[int64]FieldData{
|
2021-07-16 17:19:55 +08:00
|
|
|
RowIDField: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []int64{1, 2},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
TimestampField: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []int64{1, 2},
|
2020-12-11 11:29:07 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
BoolField: &BoolFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []bool{true, false},
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
Int8Field: &Int8FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []int8{1, 2},
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
Int16Field: &Int16FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []int16{1, 2},
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
Int32Field: &Int32FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []int32{1, 2},
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
Int64Field: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []int64{1, 2},
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
FloatField: &FloatFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []float32{1, 2},
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
DoubleField: &DoubleFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []float64{1, 2},
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
StringField: &StringFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-21 16:27:03 +08:00
|
|
|
Data: []string{"1", "2"},
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
BinaryVectorField: &BinaryVectorFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2020-12-23 11:34:35 +08:00
|
|
|
Data: []byte{0, 255},
|
2020-12-21 16:27:03 +08:00
|
|
|
Dim: 8,
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
FloatVectorField: &FloatVectorFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-07-16 17:19:55 +08:00
|
|
|
Data: []float32{0, 1, 2, 3, 0, 1, 2, 3},
|
|
|
|
Dim: 4,
|
2020-12-09 20:07:27 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-07-16 17:19:55 +08:00
|
|
|
Blobs1, _, err := insertCodec.Serialize(PartitionID, SegmentID, insertData1)
|
2020-12-09 20:07:27 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-16 17:19:55 +08:00
|
|
|
for _, blob := range Blobs1 {
|
2020-12-23 11:34:35 +08:00
|
|
|
blob.Key = fmt.Sprintf("1/insert_log/2/3/4/5/%d", 100)
|
2021-04-19 10:36:19 +08:00
|
|
|
assert.Equal(t, blob.GetKey(), blob.Key)
|
2020-12-23 11:34:35 +08:00
|
|
|
}
|
2021-07-16 17:19:55 +08:00
|
|
|
Blobs2, _, err := insertCodec.Serialize(PartitionID, SegmentID, insertData2)
|
2020-12-09 20:07:27 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-16 17:19:55 +08:00
|
|
|
for _, blob := range Blobs2 {
|
2020-12-23 11:34:35 +08:00
|
|
|
blob.Key = fmt.Sprintf("1/insert_log/2/3/4/5/%d", 99)
|
2021-04-19 10:36:19 +08:00
|
|
|
assert.Equal(t, blob.GetKey(), blob.Key)
|
2020-12-23 11:34:35 +08:00
|
|
|
}
|
2021-07-16 17:19:55 +08:00
|
|
|
resultBlobs := append(Blobs1, Blobs2...)
|
2021-09-29 09:52:12 +08:00
|
|
|
collID, partID, segID, resultData, err := insertCodec.DeserializeAll(resultBlobs)
|
2020-12-23 11:34:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-09-29 09:52:12 +08:00
|
|
|
assert.Equal(t, UniqueID(CollectionID), collID)
|
2021-07-16 17:19:55 +08:00
|
|
|
assert.Equal(t, UniqueID(PartitionID), partID)
|
|
|
|
assert.Equal(t, UniqueID(SegmentID), segID)
|
2021-07-24 09:25:22 +08:00
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[RowIDField].(*Int64FieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[TimestampField].(*Int64FieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[BoolField].(*BoolFieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[Int8Field].(*Int8FieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[Int16Field].(*Int16FieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[Int32Field].(*Int32FieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[Int64Field].(*Int64FieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[FloatField].(*FloatFieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[DoubleField].(*DoubleFieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[StringField].(*StringFieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[BinaryVectorField].(*BinaryVectorFieldData).NumRows)
|
|
|
|
assert.Equal(t, []int64{2, 2}, resultData.Data[FloatVectorField].(*FloatVectorFieldData).NumRows)
|
2021-07-16 17:19:55 +08:00
|
|
|
assert.Equal(t, []int64{1, 2, 3, 4}, resultData.Data[RowIDField].(*Int64FieldData).Data)
|
|
|
|
assert.Equal(t, []int64{1, 2, 3, 4}, resultData.Data[TimestampField].(*Int64FieldData).Data)
|
|
|
|
assert.Equal(t, []bool{true, false, true, false}, resultData.Data[BoolField].(*BoolFieldData).Data)
|
|
|
|
assert.Equal(t, []int8{1, 2, 3, 4}, resultData.Data[Int8Field].(*Int8FieldData).Data)
|
|
|
|
assert.Equal(t, []int16{1, 2, 3, 4}, resultData.Data[Int16Field].(*Int16FieldData).Data)
|
|
|
|
assert.Equal(t, []int32{1, 2, 3, 4}, resultData.Data[Int32Field].(*Int32FieldData).Data)
|
|
|
|
assert.Equal(t, []int64{1, 2, 3, 4}, resultData.Data[Int64Field].(*Int64FieldData).Data)
|
|
|
|
assert.Equal(t, []float32{1, 2, 3, 4}, resultData.Data[FloatField].(*FloatFieldData).Data)
|
|
|
|
assert.Equal(t, []float64{1, 2, 3, 4}, resultData.Data[DoubleField].(*DoubleFieldData).Data)
|
|
|
|
assert.Equal(t, []string{"1", "2", "3", "4"}, resultData.Data[StringField].(*StringFieldData).Data)
|
|
|
|
assert.Equal(t, []byte{0, 255, 0, 255}, resultData.Data[BinaryVectorField].(*BinaryVectorFieldData).Data)
|
|
|
|
assert.Equal(t, []float32{0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7}, resultData.Data[FloatVectorField].(*FloatVectorFieldData).Data)
|
2020-12-09 20:07:27 +08:00
|
|
|
assert.Nil(t, insertCodec.Close())
|
2021-06-16 12:03:57 +08:00
|
|
|
log.Debug("Data", zap.Any("Data", resultData.Data))
|
|
|
|
log.Debug("Infos", zap.Any("Infos", resultData.Infos))
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
blobs := []*Blob{}
|
|
|
|
_, _, _, err = insertCodec.Deserialize(blobs)
|
|
|
|
assert.NotNil(t, err)
|
2021-09-29 09:52:12 +08:00
|
|
|
_, _, _, _, err = insertCodec.DeserializeAll(blobs)
|
|
|
|
assert.NotNil(t, err)
|
2020-12-09 20:07:27 +08:00
|
|
|
}
|
2021-09-28 14:30:02 +08:00
|
|
|
|
|
|
|
func TestDeleteCodec(t *testing.T) {
|
|
|
|
schema := &etcdpb.CollectionMeta{
|
|
|
|
ID: CollectionID,
|
|
|
|
}
|
|
|
|
deleteCodec := NewDeleteCodec(schema)
|
|
|
|
deleteData := &DeleteData{
|
|
|
|
Data: map[string]int64{"1": 43757345, "2": 23578294723},
|
|
|
|
}
|
|
|
|
blob, err := deleteCodec.Serialize(1, 1, deleteData)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
pid, sid, data, err := deleteCodec.Deserialize(blob)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, pid, int64(1))
|
|
|
|
assert.Equal(t, sid, int64(1))
|
|
|
|
assert.Equal(t, data, deleteData)
|
|
|
|
}
|
|
|
|
|
2020-12-11 11:29:07 +08:00
|
|
|
func TestDDCodec(t *testing.T) {
|
2020-12-23 18:06:04 +08:00
|
|
|
dataDefinitionCodec := NewDataDefinitionCodec(int64(1))
|
2021-07-16 17:19:55 +08:00
|
|
|
ts := []Timestamp{1, 2, 3, 4}
|
2020-12-09 20:07:27 +08:00
|
|
|
ddRequests := []string{
|
|
|
|
"CreateCollection",
|
|
|
|
"DropCollection",
|
|
|
|
"CreatePartition",
|
|
|
|
"DropPartition",
|
|
|
|
}
|
|
|
|
eventTypeCodes := []EventTypeCode{
|
|
|
|
CreateCollectionEventType,
|
|
|
|
DropCollectionEventType,
|
|
|
|
CreatePartitionEventType,
|
|
|
|
DropPartitionEventType,
|
|
|
|
}
|
2020-12-11 11:29:07 +08:00
|
|
|
blobs, err := dataDefinitionCodec.Serialize(ts, ddRequests, eventTypeCodes)
|
2020-12-09 20:07:27 +08:00
|
|
|
assert.Nil(t, err)
|
2020-12-23 11:34:35 +08:00
|
|
|
for _, blob := range blobs {
|
|
|
|
blob.Key = fmt.Sprintf("1/data_definition/3/4/5/%d", 99)
|
|
|
|
}
|
2020-12-09 20:07:27 +08:00
|
|
|
resultTs, resultRequests, err := dataDefinitionCodec.Deserialize(blobs)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, resultTs, ts)
|
|
|
|
assert.Equal(t, resultRequests, ddRequests)
|
|
|
|
assert.Nil(t, dataDefinitionCodec.Close())
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
blobs = []*Blob{}
|
|
|
|
_, _, err = dataDefinitionCodec.Deserialize(blobs)
|
|
|
|
assert.NotNil(t, err)
|
2020-12-09 20:07:27 +08:00
|
|
|
}
|
2020-12-11 11:29:07 +08:00
|
|
|
|
2021-09-29 09:52:12 +08:00
|
|
|
func TestIndexFileBinlogCodec(t *testing.T) {
|
|
|
|
indexBuildID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
version := int64(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
collectionID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
partitionID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
segmentID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
fieldID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
indexName := funcutil.GenRandomStr()
|
|
|
|
indexID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
indexParams := make(map[string]string)
|
|
|
|
indexParams["index_type"] = "IVF_FLAT"
|
|
|
|
datas := []*Blob{
|
|
|
|
{
|
|
|
|
Key: "ivf1",
|
|
|
|
Value: []byte{1, 2, 3},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "ivf2",
|
|
|
|
Value: []byte{4, 5, 6},
|
|
|
|
},
|
2021-09-30 17:57:01 +08:00
|
|
|
{
|
|
|
|
Key: "large",
|
|
|
|
Value: []byte(funcutil.RandomString(maxLengthPerRowOfIndexFile + 1)),
|
|
|
|
},
|
2021-09-29 09:52:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
codec := NewIndexFileBinlogCodec()
|
|
|
|
|
|
|
|
serializedBlobs, err := codec.Serialize(indexBuildID, version, collectionID, partitionID, segmentID, fieldID, indexParams, indexName, indexID, datas)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
idxBuildID, v, collID, parID, segID, fID, params, idxName, idxID, blobs, err := codec.DeserializeImpl(serializedBlobs)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, indexBuildID, idxBuildID)
|
|
|
|
assert.Equal(t, version, v)
|
|
|
|
assert.Equal(t, collectionID, collID)
|
|
|
|
assert.Equal(t, partitionID, parID)
|
|
|
|
assert.Equal(t, segmentID, segID)
|
|
|
|
assert.Equal(t, fieldID, fID)
|
|
|
|
assert.Equal(t, len(indexParams), len(params))
|
|
|
|
for key, value := range indexParams {
|
|
|
|
assert.Equal(t, value, params[key])
|
|
|
|
}
|
|
|
|
assert.Equal(t, indexName, idxName)
|
|
|
|
assert.Equal(t, indexID, idxID)
|
|
|
|
assert.ElementsMatch(t, datas, blobs)
|
|
|
|
|
|
|
|
blobs, indexParams, indexName, indexID, err = codec.Deserialize(serializedBlobs)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.ElementsMatch(t, datas, blobs)
|
|
|
|
for key, value := range indexParams {
|
|
|
|
assert.Equal(t, value, params[key])
|
|
|
|
}
|
|
|
|
assert.Equal(t, indexName, idxName)
|
|
|
|
assert.Equal(t, indexID, idxID)
|
|
|
|
|
|
|
|
err = codec.Close()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
// empty
|
|
|
|
_, _, _, _, _, _, _, _, _, _, err = codec.DeserializeImpl(nil)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexFileBinlogCodecError(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// failed to read binlog
|
|
|
|
codec := NewIndexFileBinlogCodec()
|
|
|
|
_, _, _, _, err = codec.Deserialize([]*Blob{{Key: "key", Value: []byte("not in binlog format")}})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
indexBuildID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
version := int64(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
collectionID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
partitionID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
segmentID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
fieldID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
indexName := funcutil.GenRandomStr()
|
|
|
|
indexID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
|
|
|
indexParams := make(map[string]string)
|
|
|
|
indexParams["index_type"] = "IVF_FLAT"
|
|
|
|
datas := []*Blob{
|
|
|
|
{
|
|
|
|
Key: "ivf1",
|
|
|
|
Value: []byte{1, 2, 3},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = codec.Serialize(indexBuildID, version, collectionID, partitionID, segmentID, fieldID, indexParams, indexName, indexID, datas)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
2020-12-11 11:29:07 +08:00
|
|
|
func TestIndexCodec(t *testing.T) {
|
2020-12-23 18:06:04 +08:00
|
|
|
indexCodec := NewIndexCodec()
|
2020-12-11 11:29:07 +08:00
|
|
|
blobs := []*Blob{
|
|
|
|
{
|
|
|
|
"12345",
|
|
|
|
[]byte{1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"6666",
|
|
|
|
[]byte{6, 6, 6, 6, 6, 1, 2, 3, 4, 5, 6, 7},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"8885",
|
|
|
|
[]byte{8, 8, 8, 8, 8, 8, 8, 8, 2, 3, 4, 5, 6, 7},
|
|
|
|
},
|
|
|
|
}
|
2021-01-28 17:25:43 +08:00
|
|
|
indexParams := map[string]string{
|
|
|
|
"k1": "v1", "k2": "v2",
|
|
|
|
}
|
2021-02-03 11:52:19 +08:00
|
|
|
blobsInput, err := indexCodec.Serialize(blobs, indexParams, "index_test_name", 1234)
|
2020-12-11 11:29:07 +08:00
|
|
|
assert.Nil(t, err)
|
2021-01-28 17:25:43 +08:00
|
|
|
assert.EqualValues(t, 4, len(blobsInput))
|
2021-10-09 19:27:02 +08:00
|
|
|
assert.EqualValues(t, IndexParamsKey, blobsInput[3].Key)
|
2021-02-03 11:52:19 +08:00
|
|
|
blobsOutput, indexParamsOutput, indexName, indexID, err := indexCodec.Deserialize(blobsInput)
|
2020-12-11 11:29:07 +08:00
|
|
|
assert.Nil(t, err)
|
2021-01-28 17:25:43 +08:00
|
|
|
assert.EqualValues(t, 3, len(blobsOutput))
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
assert.EqualValues(t, blobs[i], blobsOutput[i])
|
|
|
|
}
|
|
|
|
assert.EqualValues(t, indexParams, indexParamsOutput)
|
2021-02-03 11:52:19 +08:00
|
|
|
assert.EqualValues(t, "index_test_name", indexName)
|
|
|
|
assert.EqualValues(t, 1234, indexID)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
blobs = []*Blob{}
|
|
|
|
_, _, _, _, err = indexCodec.Deserialize(blobs)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTsError(t *testing.T) {
|
|
|
|
insertData := &InsertData{}
|
|
|
|
insertCodec := NewInsertCodec(nil)
|
2021-05-20 18:38:45 +08:00
|
|
|
blobs, _, err := insertCodec.Serialize(1, 1, insertData)
|
2021-04-19 10:36:19 +08:00
|
|
|
assert.Nil(t, blobs)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSchemaError(t *testing.T) {
|
|
|
|
schema := &etcdpb.CollectionMeta{
|
2021-07-16 17:19:55 +08:00
|
|
|
ID: CollectionID,
|
2021-04-19 10:36:19 +08:00
|
|
|
CreateTime: 1,
|
2021-07-16 17:19:55 +08:00
|
|
|
SegmentIDs: []int64{SegmentID},
|
2021-04-19 10:36:19 +08:00
|
|
|
PartitionTags: []string{"partition_0", "partition_1"},
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Name: "schema",
|
|
|
|
Description: "schema",
|
|
|
|
AutoID: true,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: RowIDField,
|
2021-04-19 10:36:19 +08:00
|
|
|
Name: "row_id",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "row_id",
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: TimestampField,
|
|
|
|
Name: "Timestamp",
|
2021-04-19 10:36:19 +08:00
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "Timestamp",
|
2021-04-19 10:36:19 +08:00
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
2021-07-16 17:19:55 +08:00
|
|
|
FieldID: BoolField,
|
2021-04-19 10:36:19 +08:00
|
|
|
Name: "field_bool",
|
|
|
|
IsPrimaryKey: false,
|
2021-07-16 17:19:55 +08:00
|
|
|
Description: "bool",
|
2021-04-19 10:36:19 +08:00
|
|
|
DataType: 999,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
insertData := &InsertData{
|
|
|
|
Data: map[int64]FieldData{
|
2021-07-16 17:19:55 +08:00
|
|
|
RowIDField: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-04-19 10:36:19 +08:00
|
|
|
Data: []int64{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
TimestampField: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-04-19 10:36:19 +08:00
|
|
|
Data: []int64{3, 4},
|
|
|
|
},
|
2021-07-16 17:19:55 +08:00
|
|
|
BoolField: &BoolFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-04-19 10:36:19 +08:00
|
|
|
Data: []bool{true, false},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
insertCodec := NewInsertCodec(schema)
|
2021-07-16 17:19:55 +08:00
|
|
|
blobs, _, err := insertCodec.Serialize(PartitionID, SegmentID, insertData)
|
2021-04-19 10:36:19 +08:00
|
|
|
assert.Nil(t, blobs)
|
|
|
|
assert.NotNil(t, err)
|
2020-12-11 11:29:07 +08:00
|
|
|
}
|