2021-12-28 09:43:26 +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-04-19 11:32:24 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-28 09:43:26 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 11:32:24 +08:00
|
|
|
//
|
2021-12-28 09:43:26 +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-04-19 11:32:24 +08:00
|
|
|
|
2020-12-07 15:22:20 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-12-08 14:41:04 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-05-10 11:37:52 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2020-12-07 15:22:20 +08:00
|
|
|
)
|
|
|
|
|
2022-05-10 11:37:52 +08:00
|
|
|
func TestPayload_ReaderAndWriter(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
t.Run("TestBool", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, false, false, false})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload([]bool{false, false, false, false})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 8, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Bool, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 8)
|
|
|
|
bools, err := r.GetBoolFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []bool{false, false, false, false, false, false, false, false}, bools)
|
|
|
|
ibools, _, err := r.GetDataFromPayload()
|
|
|
|
bools = ibools.([]bool)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []bool{false, false, false, false, false, false, false, false}, bools)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestInt8", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int8)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt8ToPayload([]int8{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload([]int8{4, 5, 6})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 6, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int8, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 6)
|
|
|
|
|
|
|
|
int8s, err := r.GetInt8FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []int8{1, 2, 3, 4, 5, 6}, int8s)
|
|
|
|
|
|
|
|
iint8s, _, err := r.GetDataFromPayload()
|
|
|
|
int8s = iint8s.([]int8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
assert.ElementsMatch(t, []int8{1, 2, 3, 4, 5, 6}, int8s)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestInt16", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int16)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt16ToPayload([]int16{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload([]int16{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 6, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int16, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 6)
|
|
|
|
int16s, err := r.GetInt16FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []int16{1, 2, 3, 1, 2, 3}, int16s)
|
|
|
|
|
|
|
|
iint16s, _, err := r.GetDataFromPayload()
|
|
|
|
int16s = iint16s.([]int16)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []int16{1, 2, 3, 1, 2, 3}, int16s)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestInt32", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int32)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt32ToPayload([]int32{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload([]int32{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 6, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int32, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 6)
|
|
|
|
|
|
|
|
int32s, err := r.GetInt32FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []int32{1, 2, 3, 1, 2, 3}, int32s)
|
|
|
|
|
|
|
|
iint32s, _, err := r.GetDataFromPayload()
|
|
|
|
int32s = iint32s.([]int32)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []int32{1, 2, 3, 1, 2, 3}, int32s)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestInt64", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int64)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt64ToPayload([]int64{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload([]int64{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 6, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int64, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 6)
|
|
|
|
|
|
|
|
int64s, err := r.GetInt64FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []int64{1, 2, 3, 1, 2, 3}, int64s)
|
|
|
|
|
|
|
|
iint64s, _, err := r.GetDataFromPayload()
|
|
|
|
int64s = iint64s.([]int64)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []int64{1, 2, 3, 1, 2, 3}, int64s)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestFloat32", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Float)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddFloatToPayload([]float32{1.0, 2.0, 3.0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload([]float32{1.0, 2.0, 3.0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 6, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Float, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 6)
|
|
|
|
|
|
|
|
float32s, err := r.GetFloatFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []float32{1.0, 2.0, 3.0, 1.0, 2.0, 3.0}, float32s)
|
|
|
|
|
|
|
|
ifloat32s, _, err := r.GetDataFromPayload()
|
|
|
|
float32s = ifloat32s.([]float32)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []float32{1.0, 2.0, 3.0, 1.0, 2.0, 3.0}, float32s)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestDouble", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Double)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddDoubleToPayload([]float64{1.0, 2.0, 3.0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload([]float64{1.0, 2.0, 3.0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 6, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Double, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 6)
|
|
|
|
|
|
|
|
float64s, err := r.GetDoubleFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []float64{1.0, 2.0, 3.0, 1.0, 2.0, 3.0}, float64s)
|
|
|
|
|
|
|
|
ifloat64s, _, err := r.GetDataFromPayload()
|
|
|
|
float64s = ifloat64s.([]float64)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.ElementsMatch(t, []float64{1.0, 2.0, 3.0, 1.0, 2.0, 3.0}, float64s)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
2022-03-30 15:21:28 +08:00
|
|
|
t.Run("TestAddString", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_String)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddOneStringToPayload("hello0")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddOneStringToPayload("hello1")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddOneStringToPayload("hello2")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload("hello3")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 4)
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_String, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 4)
|
|
|
|
|
2022-03-30 15:21:28 +08:00
|
|
|
str, err := r.GetStringFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2022-03-30 15:21:28 +08:00
|
|
|
assert.Equal(t, str[0], "hello0")
|
|
|
|
assert.Equal(t, str[1], "hello1")
|
|
|
|
assert.Equal(t, str[2], "hello2")
|
|
|
|
assert.Equal(t, str[3], "hello3")
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2022-03-30 15:21:28 +08:00
|
|
|
istr, _, err := r.GetDataFromPayload()
|
|
|
|
strArray := istr.([]string)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-03-30 15:21:28 +08:00
|
|
|
assert.Equal(t, strArray[0], "hello0")
|
|
|
|
assert.Equal(t, strArray[1], "hello1")
|
|
|
|
assert.Equal(t, strArray[2], "hello2")
|
|
|
|
assert.Equal(t, strArray[3], "hello3")
|
2021-12-08 21:11:39 +08:00
|
|
|
r.ReleasePayloadReader()
|
2021-12-09 12:37:06 +08:00
|
|
|
w.ReleasePayloadWriter()
|
2020-12-08 14:41:04 +08:00
|
|
|
})
|
|
|
|
|
2023-04-20 11:32:31 +08:00
|
|
|
t.Run("TestAddArray", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Array)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddOneArrayToPayload(&schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: []int32{1, 2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
err = w.AddOneArrayToPayload(&schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: []int32{3, 4},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
err = w.AddOneArrayToPayload(&schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: []int32{5, 6},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
err = w.AddDataToPayload(&schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: []int32{7, 8},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
assert.Equal(t, length, 4)
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Array, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
assert.Equal(t, length, 4)
|
|
|
|
|
|
|
|
arrayList, err := r.GetArrayFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
|
|
|
|
assert.EqualValues(t, []int32{1, 2}, arrayList[0].GetIntData().GetData())
|
|
|
|
assert.EqualValues(t, []int32{3, 4}, arrayList[1].GetIntData().GetData())
|
|
|
|
assert.EqualValues(t, []int32{5, 6}, arrayList[2].GetIntData().GetData())
|
|
|
|
assert.EqualValues(t, []int32{7, 8}, arrayList[3].GetIntData().GetData())
|
|
|
|
|
|
|
|
iArrayList, _, err := r.GetDataFromPayload()
|
|
|
|
arrayList = iArrayList.([]*schemapb.ScalarField)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
assert.EqualValues(t, []int32{1, 2}, arrayList[0].GetIntData().GetData())
|
|
|
|
assert.EqualValues(t, []int32{3, 4}, arrayList[1].GetIntData().GetData())
|
|
|
|
assert.EqualValues(t, []int32{5, 6}, arrayList[2].GetIntData().GetData())
|
|
|
|
assert.EqualValues(t, []int32{7, 8}, arrayList[3].GetIntData().GetData())
|
|
|
|
r.ReleasePayloadReader()
|
|
|
|
w.ReleasePayloadWriter()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestAddJSON", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_JSON)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddOneJSONToPayload([]byte(`{"1":"1"}`))
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
err = w.AddOneJSONToPayload([]byte(`{"2":"2"}`))
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
err = w.AddOneJSONToPayload([]byte(`{"3":"3"}`))
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
err = w.AddDataToPayload([]byte(`{"4":"4"}`))
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
assert.Equal(t, length, 4)
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_JSON, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
assert.Equal(t, length, 4)
|
|
|
|
|
|
|
|
json, err := r.GetJSONFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
|
|
|
|
assert.EqualValues(t, []byte(`{"1":"1"}`), json[0])
|
|
|
|
assert.EqualValues(t, []byte(`{"2":"2"}`), json[1])
|
|
|
|
assert.EqualValues(t, []byte(`{"3":"3"}`), json[2])
|
|
|
|
assert.EqualValues(t, []byte(`{"4":"4"}`), json[3])
|
|
|
|
|
|
|
|
iJSON, _, err := r.GetDataFromPayload()
|
|
|
|
json = iJSON.([][]byte)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-04-20 11:32:31 +08:00
|
|
|
assert.EqualValues(t, []byte(`{"1":"1"}`), json[0])
|
|
|
|
assert.EqualValues(t, []byte(`{"2":"2"}`), json[1])
|
|
|
|
assert.EqualValues(t, []byte(`{"3":"3"}`), json[2])
|
|
|
|
assert.EqualValues(t, []byte(`{"4":"4"}`), json[3])
|
|
|
|
r.ReleasePayloadReader()
|
|
|
|
w.ReleasePayloadWriter()
|
|
|
|
})
|
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
t.Run("TestBinaryVector", func(t *testing.T) {
|
2022-09-09 22:12:34 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_BinaryVector, 8)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
in := make([]byte, 16)
|
|
|
|
for i := 0; i < 16; i++ {
|
|
|
|
in[i] = 1
|
|
|
|
}
|
|
|
|
in2 := make([]byte, 8)
|
|
|
|
for i := 0; i < 8; i++ {
|
|
|
|
in2[i] = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
err = w.AddBinaryVectorToPayload(in, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload(in2, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 24, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_BinaryVector, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 24)
|
|
|
|
|
|
|
|
binVecs, dim, err := r.GetBinaryVectorFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 8, dim)
|
|
|
|
assert.Equal(t, 24, len(binVecs))
|
|
|
|
|
|
|
|
ibinVecs, dim, err := r.GetDataFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
binVecs = ibinVecs.([]byte)
|
|
|
|
assert.Equal(t, 8, dim)
|
|
|
|
assert.Equal(t, 24, len(binVecs))
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestFloatVector", func(t *testing.T) {
|
2022-09-09 22:12:34 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_FloatVector, 1)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddFloatVectorToPayload([]float32{1.0, 2.0}, 1)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.AddDataToPayload([]float32{3.0, 4.0}, 1)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 4, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
r, err := NewPayloadReader(schemapb.DataType_FloatVector, buffer)
|
2020-12-08 14:41:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, length, 4)
|
|
|
|
|
|
|
|
floatVecs, dim, err := r.GetFloatVectorFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, 1, dim)
|
|
|
|
assert.Equal(t, 4, len(floatVecs))
|
|
|
|
assert.ElementsMatch(t, []float32{1.0, 2.0, 3.0, 4.0}, floatVecs)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
ifloatVecs, dim, err := r.GetDataFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
floatVecs = ifloatVecs.([]float32)
|
|
|
|
assert.Equal(t, 1, dim)
|
|
|
|
assert.Equal(t, 4, len(floatVecs))
|
|
|
|
assert.ElementsMatch(t, []float32{1.0, 2.0, 3.0, 4.0}, floatVecs)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
|
2023-09-08 10:03:16 +08:00
|
|
|
t.Run("TestFloat16Vector", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Float16Vector, 1)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddFloat16VectorToPayload([]byte{1, 2}, 1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = w.AddDataToPayload([]byte{3, 4}, 1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 2, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Float16Vector, buffer)
|
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, length, 2)
|
|
|
|
|
|
|
|
float16Vecs, dim, err := r.GetFloat16VectorFromPayload()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, dim)
|
|
|
|
assert.Equal(t, 4, len(float16Vecs))
|
|
|
|
assert.ElementsMatch(t, []byte{1, 2, 3, 4}, float16Vecs)
|
2024-01-11 15:48:51 +08:00
|
|
|
|
|
|
|
ifloat16Vecs, dim, err := r.GetDataFromPayload()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
float16Vecs = ifloat16Vecs.([]byte)
|
|
|
|
assert.Equal(t, 1, dim)
|
|
|
|
assert.Equal(t, 4, len(float16Vecs))
|
|
|
|
assert.ElementsMatch(t, []byte{1, 2, 3, 4}, float16Vecs)
|
|
|
|
defer r.ReleasePayloadReader()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestBFloat16Vector", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_BFloat16Vector, 1)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBFloat16VectorToPayload([]byte{1, 2}, 1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = w.AddDataToPayload([]byte{3, 4}, 1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
length, err := w.GetPayloadLengthFromWriter()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 2, length)
|
|
|
|
defer w.ReleasePayloadWriter()
|
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_BFloat16Vector, buffer)
|
|
|
|
require.Nil(t, err)
|
|
|
|
length, err = r.GetPayloadLengthFromReader()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, length, 2)
|
|
|
|
|
|
|
|
bfloat16Vecs, dim, err := r.GetBFloat16VectorFromPayload()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, dim)
|
|
|
|
assert.Equal(t, 4, len(bfloat16Vecs))
|
|
|
|
assert.ElementsMatch(t, []byte{1, 2, 3, 4}, bfloat16Vecs)
|
|
|
|
|
|
|
|
ibfloat16Vecs, dim, err := r.GetDataFromPayload()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
bfloat16Vecs = ibfloat16Vecs.([]byte)
|
|
|
|
assert.Equal(t, 1, dim)
|
|
|
|
assert.Equal(t, 4, len(bfloat16Vecs))
|
|
|
|
assert.ElementsMatch(t, []byte{1, 2, 3, 4}, bfloat16Vecs)
|
|
|
|
defer r.ReleasePayloadReader()
|
2023-09-08 10:03:16 +08:00
|
|
|
})
|
|
|
|
|
2023-06-09 13:52:39 +08:00
|
|
|
// t.Run("TestAddDataToPayload", func(t *testing.T) {
|
|
|
|
// w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
// w.colType = 999
|
|
|
|
// require.Nil(t, err)
|
|
|
|
// require.NotNil(t, w)
|
|
|
|
|
|
|
|
// err = w.AddDataToPayload([]bool{false, false, false, false})
|
|
|
|
// assert.NotNil(t, err)
|
|
|
|
|
|
|
|
// err = w.AddDataToPayload([]bool{false, false, false, false}, 0)
|
|
|
|
// assert.NotNil(t, err)
|
|
|
|
|
|
|
|
// err = w.AddDataToPayload([]bool{false, false, false, false}, 0, 0)
|
|
|
|
// assert.NotNil(t, err)
|
|
|
|
|
|
|
|
// err = w.AddBoolToPayload([]bool{})
|
|
|
|
// assert.NotNil(t, err)
|
|
|
|
// err = w.FinishPayloadWriter()
|
|
|
|
// assert.Nil(t, err)
|
|
|
|
// err = w.AddBoolToPayload([]bool{false})
|
|
|
|
// assert.NotNil(t, err)
|
|
|
|
// })
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
t.Run("TestAddBoolAfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddBoolToPayload([]bool{false})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestAddInt8AfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int8)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddInt8ToPayload([]int8{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddInt8ToPayload([]int8{0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
t.Run("TestAddInt16AfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int16)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddInt16ToPayload([]int16{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddInt16ToPayload([]int16{0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
t.Run("TestAddInt32AfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int32)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddInt32ToPayload([]int32{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddInt32ToPayload([]int32{0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
t.Run("TestAddInt64AfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int64)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddInt64ToPayload([]int64{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddInt64ToPayload([]int64{0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
t.Run("TestAddFloatAfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Float)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddFloatToPayload([]float32{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddFloatToPayload([]float32{0.0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
t.Run("TestAddDoubleAfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Double)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddDoubleToPayload([]float64{})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddDoubleToPayload([]float64{0.0})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2021-07-07 19:10:07 +08:00
|
|
|
t.Run("TestAddOneStringAfterFinish", func(t *testing.T) {
|
2021-04-19 10:36:19 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_String)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddOneStringToPayload("")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddOneStringToPayload("c")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
t.Run("TestAddBinVectorAfterFinish", func(t *testing.T) {
|
2022-09-09 22:12:34 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_BinaryVector, 8)
|
2021-04-19 10:36:19 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddBinaryVectorToPayload([]byte{}, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddBinaryVectorToPayload([]byte{1}, 0)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddBinaryVectorToPayload([]byte{1, 0, 0, 0, 0, 0, 0, 0}, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddBinaryVectorToPayload([]byte{1, 0, 0, 0, 0, 0, 0, 0}, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
t.Run("TestAddFloatVectorAfterFinish", func(t *testing.T) {
|
2022-09-09 22:12:34 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_FloatVector, 8)
|
2021-04-19 10:36:19 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddFloatVectorToPayload([]float32{}, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddFloatVectorToPayload([]float32{1.0}, 0)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.AddFloatVectorToPayload([]float32{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
err = w.AddFloatVectorToPayload([]float32{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2024-01-11 15:48:51 +08:00
|
|
|
t.Run("TestAddFloat16VectorAfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Float16Vector, 8)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
err = w.AddFloat16VectorToPayload([]byte{}, 8)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = w.AddFloat16VectorToPayload([]byte{}, 8)
|
|
|
|
assert.Error(t, err)
|
|
|
|
err = w.AddFloat16VectorToPayload([]byte{1}, 0)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
err = w.AddFloat16VectorToPayload([]byte{1, 0, 0, 0, 0, 0, 0, 0}, 8)
|
|
|
|
assert.Error(t, err)
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
assert.Error(t, err)
|
|
|
|
err = w.AddFloat16VectorToPayload([]byte{1, 0, 0, 0, 0, 0, 0, 0}, 8)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
t.Run("TestAddBFloat16VectorAfterFinish", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_BFloat16Vector, 8)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
err = w.AddBFloat16VectorToPayload([]byte{}, 8)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
2024-01-11 15:48:51 +08:00
|
|
|
err = w.AddBFloat16VectorToPayload([]byte{}, 8)
|
|
|
|
assert.Error(t, err)
|
|
|
|
err = w.AddBFloat16VectorToPayload([]byte{1}, 0)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
err = w.AddBFloat16VectorToPayload([]byte{1, 0, 0, 0, 0, 0, 0, 0}, 8)
|
|
|
|
assert.Error(t, err)
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
assert.Error(t, err)
|
|
|
|
err = w.AddBFloat16VectorToPayload([]byte{1, 0, 0, 0, 0, 0, 0, 0}, 8)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestNewReadError", func(t *testing.T) {
|
|
|
|
buffer := []byte{0}
|
|
|
|
r, err := NewPayloadReader(999, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
assert.Nil(t, r)
|
|
|
|
})
|
|
|
|
t.Run("TestGetDataError", func(t *testing.T) {
|
|
|
|
r := PayloadReader{}
|
|
|
|
r.colType = 999
|
|
|
|
|
|
|
|
_, _, err := r.GetDataFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
|
|
|
t.Run("TestGetBoolError", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int8)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt8ToPayload([]int8{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Bool, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, err = r.GetBoolFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, err = r.GetBoolFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetBoolError2", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{true, false, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Bool, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, err = r.GetBoolFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestGetInt8Error", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int8, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, err = r.GetInt8FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, err = r.GetInt8FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetInt8Error2", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int8)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt8ToPayload([]int8{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int8, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, err = r.GetInt8FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestGetInt16Error", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int16, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, err = r.GetInt16FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, err = r.GetInt16FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetInt16Error2", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int16)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt16ToPayload([]int16{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int16, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, err = r.GetInt16FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestGetInt32Error", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int32, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, err = r.GetInt32FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, err = r.GetInt32FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetInt32Error2", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int32)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt32ToPayload([]int32{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int32, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, err = r.GetInt32FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestGetInt64Error", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int64, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, err = r.GetInt64FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, err = r.GetInt64FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetInt64Error2", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int64)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddInt64ToPayload([]int64{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Int64, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, err = r.GetInt64FromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestGetFloatError", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Float, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, err = r.GetFloatFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, err = r.GetFloatFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetFloatError2", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Float)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddFloatToPayload([]float32{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Float, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, err = r.GetFloatFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestGetDoubleError", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Double, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, err = r.GetDoubleFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, err = r.GetDoubleFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetDoubleError2", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Double)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddDoubleToPayload([]float64{1, 2, 3})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_Double, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, err = r.GetDoubleFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2022-03-30 15:21:28 +08:00
|
|
|
t.Run("TestGetStringError", func(t *testing.T) {
|
2021-04-19 10:36:19 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_String, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
2022-03-30 15:21:28 +08:00
|
|
|
_, err = r.GetStringFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
2022-03-30 15:21:28 +08:00
|
|
|
_, err = r.GetStringFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetStringError2", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_String)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddOneStringToPayload("hello0")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
err = w.AddOneStringToPayload("hello1")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
err = w.AddOneStringToPayload("hello2")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_String, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, err = r.GetStringFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestGetBinaryVectorError", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_BinaryVector, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, _, err = r.GetBinaryVectorFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, _, err = r.GetBinaryVectorFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetBinaryVectorError2", func(t *testing.T) {
|
2022-09-09 22:12:34 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_BinaryVector, 8)
|
2022-05-10 11:37:52 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBinaryVectorToPayload([]byte{1, 0, 0, 0, 0, 0, 0, 0}, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_BinaryVector, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, _, err = r.GetBinaryVectorFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-04-19 10:36:19 +08:00
|
|
|
t.Run("TestGetFloatVectorError", func(t *testing.T) {
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBoolToPayload([]bool{false, true, true})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_FloatVector, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
_, _, err = r.GetFloatVectorFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
|
|
|
|
r.colType = 999
|
|
|
|
_, _, err = r.GetFloatVectorFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-19 10:36:19 +08:00
|
|
|
})
|
2022-05-10 11:37:52 +08:00
|
|
|
t.Run("TestGetFloatVectorError2", func(t *testing.T) {
|
2022-09-09 22:12:34 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_FloatVector, 8)
|
2022-05-10 11:37:52 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddFloatVectorToPayload([]float32{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, 8)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
buffer, err := w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r, err := NewPayloadReader(schemapb.DataType_FloatVector, buffer)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
|
|
|
|
r.numRows = 99
|
|
|
|
_, _, err = r.GetFloatVectorFromPayload()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2022-05-10 11:37:52 +08:00
|
|
|
})
|
2021-11-22 10:05:14 +08:00
|
|
|
|
|
|
|
t.Run("TestWriteLargeSizeData", func(t *testing.T) {
|
2021-11-22 20:11:14 +08:00
|
|
|
t.Skip("Large data skip for online ut")
|
2021-11-22 10:05:14 +08:00
|
|
|
size := 1 << 29 // 512M
|
|
|
|
var vec []float32
|
|
|
|
for i := 0; i < size/4; i++ {
|
|
|
|
vec = append(vec, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_FloatVector)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-22 10:05:14 +08:00
|
|
|
|
|
|
|
err = w.AddFloatVectorToPayload(vec, 128)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-22 10:05:14 +08:00
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-22 10:05:14 +08:00
|
|
|
|
|
|
|
_, err = w.GetPayloadBufferFromWriter()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-22 10:05:14 +08:00
|
|
|
|
2021-12-09 12:37:06 +08:00
|
|
|
w.ReleasePayloadWriter()
|
2021-11-22 10:05:14 +08:00
|
|
|
})
|
2020-12-07 15:22:20 +08:00
|
|
|
}
|