2021-11-10 23:56:17 +08:00
|
|
|
// 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
|
2021-08-31 10:33:58 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-10 23:56:17 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-08-31 10:33:58 +08:00
|
|
|
//
|
2021-11-10 23:56:17 +08:00
|
|
|
// 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.
|
2021-08-31 10:33:58 +08:00
|
|
|
|
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-09-06 20:49:04 +08:00
|
|
|
"math/rand"
|
2021-09-09 10:06:29 +08:00
|
|
|
"sync"
|
2021-08-31 10:33:58 +08:00
|
|
|
"time"
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2022-10-09 10:06:58 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
2021-08-31 10:33:58 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream/mqwrapper"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/funcutil"
|
2023-09-20 10:57:23 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/uniquegenerator"
|
2021-08-31 10:33:58 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type mockTimestampAllocatorInterface struct {
|
2021-09-09 10:06:29 +08:00
|
|
|
lastTs Timestamp
|
|
|
|
mtx sync.Mutex
|
2021-08-31 10:33:58 +08:00
|
|
|
}
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
func (tso *mockTimestampAllocatorInterface) AllocTimestamp(ctx context.Context, req *rootcoordpb.AllocTimestampRequest, opts ...grpc.CallOption) (*rootcoordpb.AllocTimestampResponse, error) {
|
2021-09-09 10:06:29 +08:00
|
|
|
tso.mtx.Lock()
|
|
|
|
defer tso.mtx.Unlock()
|
|
|
|
|
|
|
|
ts := uint64(time.Now().UnixNano())
|
|
|
|
if ts < tso.lastTs+Timestamp(req.Count) {
|
|
|
|
ts = tso.lastTs + Timestamp(req.Count)
|
|
|
|
}
|
|
|
|
|
|
|
|
tso.lastTs = ts
|
2021-08-31 10:33:58 +08:00
|
|
|
return &rootcoordpb.AllocTimestampResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2021-09-09 10:06:29 +08:00
|
|
|
Timestamp: ts,
|
2021-08-31 10:33:58 +08:00
|
|
|
Count: req.Count,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockTimestampAllocatorInterface() timestampAllocatorInterface {
|
2021-09-09 10:06:29 +08:00
|
|
|
return &mockTimestampAllocatorInterface{
|
|
|
|
lastTs: Timestamp(time.Now().UnixNano()),
|
|
|
|
}
|
2021-08-31 10:33:58 +08:00
|
|
|
}
|
2021-09-06 20:49:04 +08:00
|
|
|
|
|
|
|
type mockTsoAllocator struct {
|
2023-03-15 11:17:55 +08:00
|
|
|
mu sync.Mutex
|
|
|
|
logicPart uint32
|
2021-09-06 20:49:04 +08:00
|
|
|
}
|
|
|
|
|
2023-03-09 18:51:52 +08:00
|
|
|
func (tso *mockTsoAllocator) AllocOne(ctx context.Context) (Timestamp, error) {
|
2023-03-15 11:17:55 +08:00
|
|
|
tso.mu.Lock()
|
|
|
|
defer tso.mu.Unlock()
|
|
|
|
tso.logicPart++
|
|
|
|
physical := uint64(time.Now().UnixMilli())
|
|
|
|
return (physical << 18) + uint64(tso.logicPart), nil
|
2021-09-06 20:49:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func newMockTsoAllocator() tsoAllocator {
|
|
|
|
return &mockTsoAllocator{}
|
|
|
|
}
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
type mockIDAllocatorInterface struct{}
|
2021-09-06 20:49:04 +08:00
|
|
|
|
|
|
|
func (m *mockIDAllocatorInterface) AllocOne() (UniqueID, error) {
|
2021-09-09 10:06:29 +08:00
|
|
|
return UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt()), nil
|
2021-09-06 20:49:04 +08:00
|
|
|
}
|
|
|
|
|
2022-10-09 10:06:58 +08:00
|
|
|
func (m *mockIDAllocatorInterface) Alloc(count uint32) (UniqueID, UniqueID, error) {
|
|
|
|
return UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt()), UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt() + int(count)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockIDAllocatorInterface() allocator.Interface {
|
2021-09-06 20:49:04 +08:00
|
|
|
return &mockIDAllocatorInterface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockTask struct {
|
|
|
|
*TaskCondition
|
|
|
|
id UniqueID
|
|
|
|
name string
|
|
|
|
tType commonpb.MsgType
|
|
|
|
ts Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) TraceCtx() context.Context {
|
|
|
|
return m.TaskCondition.ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) ID() UniqueID {
|
|
|
|
return m.id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) SetID(uid UniqueID) {
|
|
|
|
m.id = uid
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) Name() string {
|
|
|
|
return m.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) Type() commonpb.MsgType {
|
|
|
|
return m.tType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) BeginTs() Timestamp {
|
|
|
|
return m.ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) EndTs() Timestamp {
|
|
|
|
return m.ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) SetTs(ts Timestamp) {
|
|
|
|
m.ts = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) OnEnqueue() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) PreExecute(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) Execute(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTask) PostExecute(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockTask(ctx context.Context) *mockTask {
|
|
|
|
return &mockTask{
|
|
|
|
TaskCondition: NewTaskCondition(ctx),
|
2021-09-09 10:06:29 +08:00
|
|
|
id: UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt()),
|
|
|
|
name: funcutil.GenRandomStr(),
|
2021-09-06 20:49:04 +08:00
|
|
|
tType: commonpb.MsgType_Undefined,
|
|
|
|
ts: Timestamp(time.Now().Nanosecond()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDefaultMockTask() *mockTask {
|
|
|
|
return newMockTask(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockDdlTask struct {
|
|
|
|
*mockTask
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockDdlTask(ctx context.Context) *mockDdlTask {
|
|
|
|
return &mockDdlTask{
|
|
|
|
mockTask: newMockTask(ctx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDefaultMockDdlTask() *mockDdlTask {
|
|
|
|
return newMockDdlTask(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockDmlTask struct {
|
|
|
|
*mockTask
|
|
|
|
vchans []vChan
|
|
|
|
pchans []pChan
|
|
|
|
}
|
|
|
|
|
2023-06-16 16:36:40 +08:00
|
|
|
func (m *mockDmlTask) setChannels() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockDmlTask) getChannels() []vChan {
|
|
|
|
return m.vchans
|
2021-09-06 20:49:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func newMockDmlTask(ctx context.Context) *mockDmlTask {
|
|
|
|
shardNum := 2
|
|
|
|
|
|
|
|
vchans := make([]vChan, 0, shardNum)
|
|
|
|
pchans := make([]pChan, 0, shardNum)
|
|
|
|
|
|
|
|
for i := 0; i < shardNum; i++ {
|
2021-09-09 10:06:29 +08:00
|
|
|
vchans = append(vchans, funcutil.GenRandomStr())
|
|
|
|
pchans = append(pchans, funcutil.GenRandomStr())
|
2021-09-06 20:49:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return &mockDmlTask{
|
|
|
|
mockTask: newMockTask(ctx),
|
2023-09-19 10:05:22 +08:00
|
|
|
vchans: vchans,
|
|
|
|
pchans: pchans,
|
2021-09-06 20:49:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDefaultMockDmlTask() *mockDmlTask {
|
|
|
|
return newMockDmlTask(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockDqlTask struct {
|
|
|
|
*mockTask
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockDqlTask(ctx context.Context) *mockDqlTask {
|
|
|
|
return &mockDqlTask{
|
|
|
|
mockTask: newMockTask(ctx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDefaultMockDqlTask() *mockDqlTask {
|
|
|
|
return newMockDqlTask(context.Background())
|
|
|
|
}
|
2021-09-09 19:02:08 +08:00
|
|
|
|
|
|
|
type simpleMockMsgStream struct {
|
|
|
|
msgChan chan *msgstream.MsgPack
|
|
|
|
|
|
|
|
msgCount int
|
|
|
|
msgCountMtx sync.RWMutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *simpleMockMsgStream) Close() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *simpleMockMsgStream) Chan() <-chan *msgstream.MsgPack {
|
2022-03-11 20:09:59 +08:00
|
|
|
if ms.getMsgCount() <= 0 {
|
|
|
|
ms.msgChan <- nil
|
|
|
|
return ms.msgChan
|
|
|
|
}
|
|
|
|
|
|
|
|
defer ms.decreaseMsgCount(1)
|
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
return ms.msgChan
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *simpleMockMsgStream) AsProducer(channels []string) {
|
|
|
|
}
|
|
|
|
|
2023-09-08 09:51:17 +08:00
|
|
|
func (ms *simpleMockMsgStream) AsConsumer(ctx context.Context, channels []string, subName string, position mqwrapper.SubscriptionInitialPosition) error {
|
|
|
|
return nil
|
2021-10-15 11:46:33 +08:00
|
|
|
}
|
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
func (ms *simpleMockMsgStream) SetRepackFunc(repackFunc msgstream.RepackFunc) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *simpleMockMsgStream) getMsgCount() int {
|
|
|
|
ms.msgCountMtx.RLock()
|
|
|
|
defer ms.msgCountMtx.RUnlock()
|
|
|
|
|
|
|
|
return ms.msgCount
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *simpleMockMsgStream) increaseMsgCount(delta int) {
|
|
|
|
ms.msgCountMtx.Lock()
|
|
|
|
defer ms.msgCountMtx.Unlock()
|
|
|
|
|
|
|
|
ms.msgCount += delta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *simpleMockMsgStream) decreaseMsgCount(delta int) {
|
|
|
|
ms.increaseMsgCount(-delta)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *simpleMockMsgStream) Produce(pack *msgstream.MsgPack) error {
|
|
|
|
defer ms.increaseMsgCount(1)
|
|
|
|
|
|
|
|
ms.msgChan <- pack
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-12-05 20:55:17 +08:00
|
|
|
func (ms *simpleMockMsgStream) Broadcast(pack *msgstream.MsgPack) (map[string][]msgstream.MessageID, error) {
|
2021-09-27 14:10:09 +08:00
|
|
|
return map[string][]msgstream.MessageID{}, nil
|
|
|
|
}
|
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
func (ms *simpleMockMsgStream) GetProduceChannels() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-08 09:51:17 +08:00
|
|
|
func (ms *simpleMockMsgStream) Seek(ctx context.Context, offset []*msgstream.MsgPosition) error {
|
2021-09-09 19:02:08 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-15 14:45:22 +08:00
|
|
|
func (ms *simpleMockMsgStream) GetLatestMsgID(channel string) (msgstream.MessageID, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2023-04-03 16:44:23 +08:00
|
|
|
func (ms *simpleMockMsgStream) CheckTopicValid(topic string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-20 14:26:09 +08:00
|
|
|
func (ms *simpleMockMsgStream) EnableProduce(enabled bool) {
|
|
|
|
}
|
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
func newSimpleMockMsgStream() *simpleMockMsgStream {
|
|
|
|
return &simpleMockMsgStream{
|
|
|
|
msgChan: make(chan *msgstream.MsgPack, 1024),
|
|
|
|
msgCount: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
type simpleMockMsgStreamFactory struct{}
|
2021-09-09 19:02:08 +08:00
|
|
|
|
2022-03-24 10:15:25 +08:00
|
|
|
func (factory *simpleMockMsgStreamFactory) Init(param *paramtable.ComponentParam) error {
|
2021-09-09 19:02:08 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (factory *simpleMockMsgStreamFactory) NewMsgStream(ctx context.Context) (msgstream.MsgStream, error) {
|
|
|
|
return newSimpleMockMsgStream(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (factory *simpleMockMsgStreamFactory) NewTtMsgStream(ctx context.Context) (msgstream.MsgStream, error) {
|
|
|
|
return newSimpleMockMsgStream(), nil
|
|
|
|
}
|
|
|
|
|
2022-06-16 17:28:11 +08:00
|
|
|
func (factory *simpleMockMsgStreamFactory) NewMsgStreamDisposer(ctx context.Context) func([]string, string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
func newSimpleMockMsgStreamFactory() *simpleMockMsgStreamFactory {
|
|
|
|
return &simpleMockMsgStreamFactory{}
|
|
|
|
}
|
2021-09-11 11:36:22 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
func generateFieldData(dataType schemapb.DataType, fieldName string, numRows int) *schemapb.FieldData {
|
2022-03-25 14:27:25 +08:00
|
|
|
fieldData := &schemapb.FieldData{
|
|
|
|
Type: dataType,
|
|
|
|
FieldName: fieldName,
|
|
|
|
}
|
|
|
|
switch dataType {
|
|
|
|
case schemapb.DataType_Bool:
|
2023-06-06 10:24:34 +08:00
|
|
|
fieldData.FieldName = fieldName
|
2022-03-25 14:27:25 +08:00
|
|
|
fieldData.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_BoolData{
|
|
|
|
BoolData: &schemapb.BoolArray{
|
|
|
|
Data: generateBoolArray(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Int32:
|
2023-06-06 10:24:34 +08:00
|
|
|
fieldData.FieldName = fieldName
|
2022-03-25 14:27:25 +08:00
|
|
|
fieldData.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: generateInt32Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Int64:
|
2023-06-06 10:24:34 +08:00
|
|
|
fieldData.FieldName = fieldName
|
2022-03-25 14:27:25 +08:00
|
|
|
fieldData.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_LongData{
|
|
|
|
LongData: &schemapb.LongArray{
|
|
|
|
Data: generateInt64Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Float:
|
2023-06-06 10:24:34 +08:00
|
|
|
fieldData.FieldName = fieldName
|
2022-03-25 14:27:25 +08:00
|
|
|
fieldData.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_FloatData{
|
|
|
|
FloatData: &schemapb.FloatArray{
|
|
|
|
Data: generateFloat32Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Double:
|
2023-06-06 10:24:34 +08:00
|
|
|
fieldData.FieldName = fieldName
|
2022-03-25 14:27:25 +08:00
|
|
|
fieldData.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_DoubleData{
|
|
|
|
DoubleData: &schemapb.DoubleArray{
|
|
|
|
Data: generateFloat64Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_VarChar:
|
2023-06-06 10:24:34 +08:00
|
|
|
fieldData.FieldName = fieldName
|
2022-04-02 17:43:29 +08:00
|
|
|
fieldData.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_StringData{
|
|
|
|
StringData: &schemapb.StringArray{
|
|
|
|
Data: generateVarCharArray(numRows, maxTestStringLen),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-03-25 14:27:25 +08:00
|
|
|
case schemapb.DataType_FloatVector:
|
2023-06-06 10:24:34 +08:00
|
|
|
fieldData.FieldName = fieldName
|
2022-03-25 14:27:25 +08:00
|
|
|
fieldData.Field = &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(testVecDim),
|
|
|
|
Data: &schemapb.VectorField_FloatVector{
|
|
|
|
FloatVector: &schemapb.FloatArray{
|
|
|
|
Data: generateFloatVectors(numRows, testVecDim),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_BinaryVector:
|
2023-06-06 10:24:34 +08:00
|
|
|
fieldData.FieldName = fieldName
|
2022-03-25 14:27:25 +08:00
|
|
|
fieldData.Field = &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(testVecDim),
|
|
|
|
Data: &schemapb.VectorField_BinaryVector{
|
|
|
|
BinaryVector: generateBinaryVectors(numRows, testVecDim),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
default:
|
2023-09-21 09:45:27 +08:00
|
|
|
// TODO::
|
2022-03-25 14:27:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return fieldData
|
|
|
|
}
|
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
func generateBoolArray(numRows int) []bool {
|
|
|
|
ret := make([]bool, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, rand.Int()%2 == 0)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateInt8Array(numRows int) []int8 {
|
|
|
|
ret := make([]int8, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, int8(rand.Int()))
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateInt16Array(numRows int) []int16 {
|
|
|
|
ret := make([]int16, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, int16(rand.Int()))
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateInt32Array(numRows int) []int32 {
|
|
|
|
ret := make([]int32, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, int32(rand.Int()))
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateInt64Array(numRows int) []int64 {
|
|
|
|
ret := make([]int64, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, int64(rand.Int()))
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
func generateUint64Array(numRows int) []uint64 {
|
|
|
|
ret := make([]uint64, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, rand.Uint64())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
func generateFloat32Array(numRows int) []float32 {
|
|
|
|
ret := make([]float32, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, rand.Float32())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateFloat64Array(numRows int) []float64 {
|
|
|
|
ret := make([]float64, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, rand.Float64())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateFloatVectors(numRows, dim int) []float32 {
|
|
|
|
total := numRows * dim
|
|
|
|
ret := make([]float32, 0, total)
|
|
|
|
for i := 0; i < total; i++ {
|
|
|
|
ret = append(ret, rand.Float32())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateBinaryVectors(numRows, dim int) []byte {
|
|
|
|
total := (numRows * dim) / 8
|
|
|
|
ret := make([]byte, total)
|
|
|
|
_, err := rand.Read(ret)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2024-01-11 15:48:51 +08:00
|
|
|
func generateFloat16Vectors(numRows, dim int) []byte {
|
|
|
|
total := numRows * dim * 2
|
|
|
|
ret := make([]byte, total)
|
|
|
|
_, err := rand.Read(ret)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateBFloat16Vectors(numRows, dim int) []byte {
|
|
|
|
total := numRows * dim * 2
|
|
|
|
ret := make([]byte, total)
|
|
|
|
_, err := rand.Read(ret)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
func generateVarCharArray(numRows int, maxLen int) []string {
|
|
|
|
ret := make([]string, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret[i] = funcutil.RandomString(rand.Intn(maxLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func newScalarFieldData(fieldSchema *schemapb.FieldSchema, fieldName string, numRows int) *schemapb.FieldData {
|
2021-09-11 11:36:22 +08:00
|
|
|
ret := &schemapb.FieldData{
|
2022-03-25 14:27:25 +08:00
|
|
|
Type: fieldSchema.DataType,
|
2021-09-11 11:36:22 +08:00
|
|
|
FieldName: fieldName,
|
|
|
|
Field: nil,
|
|
|
|
}
|
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
switch fieldSchema.DataType {
|
2021-09-11 11:36:22 +08:00
|
|
|
case schemapb.DataType_Bool:
|
|
|
|
ret.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_BoolData{
|
|
|
|
BoolData: &schemapb.BoolArray{
|
|
|
|
Data: generateBoolArray(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Int8:
|
|
|
|
ret.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: generateInt32Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Int16:
|
|
|
|
ret.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: generateInt32Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Int32:
|
|
|
|
ret.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: generateInt32Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Int64:
|
|
|
|
ret.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_LongData{
|
|
|
|
LongData: &schemapb.LongArray{
|
|
|
|
Data: generateInt64Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Float:
|
|
|
|
ret.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_FloatData{
|
|
|
|
FloatData: &schemapb.FloatArray{
|
|
|
|
Data: generateFloat32Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case schemapb.DataType_Double:
|
|
|
|
ret.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_DoubleData{
|
|
|
|
DoubleData: &schemapb.DoubleArray{
|
|
|
|
Data: generateFloat64Array(numRows),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-03-25 14:27:25 +08:00
|
|
|
case schemapb.DataType_VarChar:
|
|
|
|
ret.Field = &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_StringData{
|
|
|
|
StringData: &schemapb.StringArray{
|
|
|
|
Data: generateVarCharArray(numRows, testMaxVarCharLength),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-09-11 11:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFloatVectorFieldData(fieldName string, numRows, dim int) *schemapb.FieldData {
|
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_FloatVector,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(dim),
|
|
|
|
Data: &schemapb.VectorField_FloatVector{
|
|
|
|
FloatVector: &schemapb.FloatArray{
|
|
|
|
Data: generateFloatVectors(numRows, dim),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newBinaryVectorFieldData(fieldName string, numRows, dim int) *schemapb.FieldData {
|
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_BinaryVector,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(dim),
|
|
|
|
Data: &schemapb.VectorField_BinaryVector{
|
|
|
|
BinaryVector: generateBinaryVectors(numRows, dim),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-11 15:48:51 +08:00
|
|
|
func newFloat16VectorFieldData(fieldName string, numRows, dim int) *schemapb.FieldData {
|
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_Float16Vector,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(dim),
|
|
|
|
Data: &schemapb.VectorField_Float16Vector{
|
|
|
|
Float16Vector: generateFloat16Vectors(numRows, dim),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newBFloat16VectorFieldData(fieldName string, numRows, dim int) *schemapb.FieldData {
|
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_BFloat16Vector,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(dim),
|
|
|
|
Data: &schemapb.VectorField_Bfloat16Vector{
|
|
|
|
Bfloat16Vector: generateBFloat16Vectors(numRows, dim),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
func generateHashKeys(numRows int) []uint32 {
|
|
|
|
ret := make([]uint32, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, rand.Uint32())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|