github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/value_test.go (about)

     1  package parquet_test
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  	"unsafe"
     7  
     8  	"github.com/vc42/parquet-go"
     9  )
    10  
    11  func TestSizeOfValue(t *testing.T) {
    12  	t.Logf("sizeof(parquet.Value) = %d", unsafe.Sizeof(parquet.Value{}))
    13  }
    14  
    15  func BenchmarkValueAppend(b *testing.B) {
    16  	const N = 1024
    17  	row := make(parquet.Row, 0, N)
    18  	val := parquet.ValueOf(42)
    19  
    20  	for i := 0; i < b.N; i++ {
    21  		row = row[:0]
    22  		for j := 0; j < N; j++ {
    23  			row = append(row, val)
    24  		}
    25  	}
    26  
    27  	b.SetBytes(N * int64(unsafe.Sizeof(parquet.Value{})))
    28  }
    29  
    30  func TestValueClone(t *testing.T) {
    31  	tests := []struct {
    32  		scenario string
    33  		values   []interface{}
    34  	}{
    35  		{
    36  			scenario: "BOOLEAN",
    37  			values:   []interface{}{false, true},
    38  		},
    39  
    40  		{
    41  			scenario: "INT32",
    42  			values:   []interface{}{int32(0), int32(1), int32(math.MinInt32), int32(math.MaxInt32)},
    43  		},
    44  
    45  		{
    46  			scenario: "INT64",
    47  			values:   []interface{}{int64(0), int64(1), int64(math.MinInt64), int64(math.MaxInt64)},
    48  		},
    49  
    50  		{
    51  			scenario: "FLOAT",
    52  			values:   []interface{}{float32(0), float32(1), float32(-1)},
    53  		},
    54  
    55  		{
    56  			scenario: "DOUBLE",
    57  			values:   []interface{}{float64(0), float64(1), float64(-1)},
    58  		},
    59  
    60  		{
    61  			scenario: "BYTE_ARRAY",
    62  			values:   []interface{}{"", "A", "ABC", "Hello World!"},
    63  		},
    64  
    65  		{
    66  			scenario: "FIXED_LEN_BYTE_ARRAY",
    67  			values:   []interface{}{[1]byte{42}, [16]byte{0: 1}},
    68  		},
    69  	}
    70  
    71  	for _, test := range tests {
    72  		t.Run(test.scenario, func(t *testing.T) {
    73  			for _, value := range test.values {
    74  				v := parquet.ValueOf(value)
    75  				c := v.Clone()
    76  
    77  				if !parquet.DeepEqual(v, c) {
    78  					t.Errorf("cloned values are not equal: want=%#v got=%#v", v, c)
    79  				}
    80  				if v.RepetitionLevel() != c.RepetitionLevel() {
    81  					t.Error("cloned values do not have the same repetition level")
    82  				}
    83  				if v.DefinitionLevel() != c.DefinitionLevel() {
    84  					t.Error("cloned values do not have the same definition level")
    85  				}
    86  				if v.Column() != c.Column() {
    87  					t.Error("cloned values do not have the same column index")
    88  				}
    89  			}
    90  		})
    91  	}
    92  }