2024-05-07 14:45:29 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-05-07 14:45:29 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPayloadWriter_Failed(t *testing.T) {
|
2024-06-19 17:08:00 +08:00
|
|
|
t.Run("wrong input", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
_, err := NewPayloadWriter(schemapb.DataType_FloatVector)
|
2024-06-19 17:08:00 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
2024-05-07 14:45:29 +08:00
|
|
|
t.Run("Test Bool", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Bool)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddBoolToPayload([]bool{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddBoolToPayload([]bool{false}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Float)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddBoolToPayload([]bool{false}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Byte", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int8, WithNullable(Params.CommonCfg.MaxBloomFalsePositive.PanicIfEmpty))
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddByteToPayload([]byte{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddByteToPayload([]byte{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Float)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddByteToPayload([]byte{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Int8", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int8)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt8ToPayload([]int8{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt8ToPayload([]int8{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Float)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt8ToPayload([]int8{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Int16", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int16)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt16ToPayload([]int16{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt16ToPayload([]int16{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Float)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt16ToPayload([]int16{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Int32", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int32)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt32ToPayload([]int32{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt32ToPayload([]int32{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Float)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt32ToPayload([]int32{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Int64", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int64, WithNullable(Params.CommonCfg.MaxBloomFalsePositive.PanicIfEmpty))
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt64ToPayload([]int64{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt64ToPayload([]int64{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Float)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddInt64ToPayload([]int64{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Float", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Float)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddFloatToPayload([]float32{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddFloatToPayload([]float32{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Int64)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddFloatToPayload([]float32{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Double", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Double)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddDoubleToPayload([]float64{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddDoubleToPayload([]float64{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Int64)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddDoubleToPayload([]float64{0}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test String", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_String)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddOneStringToPayload("test", false)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Int64)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddOneStringToPayload("test", false)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Array", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Array)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddOneArrayToPayload(&schemapb.ScalarField{}, false)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Int64)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddOneArrayToPayload(&schemapb.ScalarField{}, false)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Json", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_JSON)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddOneJSONToPayload([]byte{0, 1}, false)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Int64)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddOneJSONToPayload([]byte{0, 1}, false)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test BinaryVector", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_BinaryVector, WithDim(8))
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
data := make([]byte, 8)
|
|
|
|
for i := 0; i < 8; i++ {
|
|
|
|
data[i] = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = w.AddBinaryVectorToPayload(data, 8)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Int64)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
err = w.AddBinaryVectorToPayload(data, 8)
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test FloatVector", func(t *testing.T) {
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_FloatVector, WithDim(8))
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
|
|
|
data := make([]float32, 8)
|
|
|
|
for i := 0; i < 8; i++ {
|
|
|
|
data[i] = 1
|
|
|
|
}
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddFloatToPayload([]float32{}, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddFloatToPayload(data, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2024-07-17 17:47:44 +08:00
|
|
|
w, err = NewPayloadWriter(schemapb.DataType_Int64)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, w)
|
|
|
|
|
2024-06-19 17:08:00 +08:00
|
|
|
err = w.AddFloatToPayload(data, nil)
|
2024-05-07 14:45:29 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
2024-07-17 17:47:44 +08:00
|
|
|
|
|
|
|
func TestParquetEncoding(t *testing.T) {
|
|
|
|
t.Run("test int64 pk", func(t *testing.T) {
|
|
|
|
field := &schemapb.FieldSchema{IsPrimaryKey: true, DataType: schemapb.DataType_Int64}
|
|
|
|
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_Int64, WithWriterProps(getFieldWriterProps(field)))
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = w.AddDataToPayload([]int64{1, 2, 3}, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
assert.True(t, !w.(*NativePayloadWriter).writerProps.DictionaryEnabled())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test string pk", func(t *testing.T) {
|
|
|
|
field := &schemapb.FieldSchema{IsPrimaryKey: true, DataType: schemapb.DataType_String}
|
|
|
|
|
|
|
|
w, err := NewPayloadWriter(schemapb.DataType_String, WithWriterProps(getFieldWriterProps(field)))
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = w.AddOneStringToPayload("1", true)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = w.FinishPayloadWriter()
|
|
|
|
assert.True(t, !w.(*NativePayloadWriter).writerProps.DictionaryEnabled())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|