@@ -19,6 +19,7 @@ import (
1919 "testing"
2020
2121 "github.com/dolthub/go-mysql-server/enginetest/scriptgen/setup"
22+ "github.com/jackc/pgx/v5/pgtype"
2223
2324 "github.com/dolthub/go-mysql-server/sql"
2425)
@@ -33,16 +34,28 @@ func makeTestBytes(size int, firstbyte byte) []byte {
3334 return bytes
3435}
3536
36- func makeTestVarbit (size int ) []byte {
37- bytes := make ([]byte , size )
38- for i := 0 ; i < size ; i ++ {
39- if i % 2 == 0 {
40- bytes [i ] = '1'
41- } else {
42- bytes [i ] = '0'
43- }
37+ func makeTestVarbit (sizeInBits int ) pgtype.Bits {
38+ numBytes := sizeInBits / 8
39+ leftoverBits := sizeInBits % 8
40+ bytes := make ([]byte , numBytes )
41+ for i := 0 ; i < numBytes ; i ++ {
42+ bytes [i ] = 0xaa
43+ }
44+
45+ // this is a little annoying, but if we have leftover bits, we need to pad out the remaining bits in the last byte with 0s
46+ endingByte := byte (0 )
47+ for i := 0 ; i < leftoverBits / 2 ; i ++ {
48+ endingByte |= 0b10 << (6 - i * 2 )
49+ }
50+ if leftoverBits > 0 {
51+ bytes = append (bytes , endingByte )
52+ }
53+
54+ return pgtype.Bits {
55+ Bytes : bytes ,
56+ Len : int32 (sizeInBits ),
57+ Valid : true ,
4458 }
45- return bytes
4659}
4760
4861// A 4000 byte file starting with 0x01 and then consisting of all zeros.
@@ -63,17 +76,17 @@ var tinyString = string(makeTestBytes(10, 3))
6376// A 4000 byte file starting with ascii byte 1 and then consisting of all zeros.
6477// This is larger than default target tuple size for outlining adaptive types.
6578// We expect a tuple to always store this value out-of-band
66- var fullSizeVarbit = string ( makeTestVarbit (4000 ) )
79+ var fullSizeVarbit = makeTestVarbit (4000 )
6780
6881// A 2000 byte file starting with ascii byte 1 and then consisting of all zeros.
6982// This is over half of the default target tuple size for outlining adaptive types.
7083// We expect a tuple to be able to store this value inline once, but not twice.
71- var halfSizeVarbit = string ( makeTestVarbit (2000 ) )
84+ var halfSizeVarbit = makeTestVarbit (2000 )
7285
7386// A 10 byte file starting with ascii byte 1 and then consisting of 10 zero bytes.
7487// This is file is smaller than an address hash.
7588// We expect a tuple to never store this value out-of-band.
76- var tinyVarbit = string ( makeTestVarbit (10 ) )
89+ var tinyVarbit = makeTestVarbit (10 )
7790
7891func TestAdaptiveEncodingText (t * testing.T ) {
7992 fullSizeOutOfLineRepr := fullSizeString
@@ -269,16 +282,16 @@ func TestAdaptiveEncodingVarbit(t *testing.T) {
269282 {
270283 // When a tuple with multiple adaptive columns is too large, columns are moved out-of-band from left to right.
271284 // However, strings smaller than the address size (20 bytes) are never stored out-of-band.
272- Query : "select i, b1, b2 from blobt2" ,
285+ Query : "select i, b1, b2 from blobt2 order by 1 " ,
273286 Expected : []sql.Row {
274287 {"FF" , fullSizeVarbit , fullSizeVarbit },
275- {"HF" , halfSizeVarbit , fullSizeVarbit },
276- {"TF" , tinyVarbit , fullSizeVarbit },
277288 {"FH" , fullSizeVarbit , halfSizeVarbit },
278- {"HH" , halfSizeVarbit , halfSizeVarbit },
279- {"TH" , tinyVarbit , halfSizeVarbit },
280289 {"FT" , fullSizeVarbit , tinyVarbit },
290+ {"HF" , halfSizeVarbit , fullSizeVarbit },
291+ {"HH" , halfSizeVarbit , halfSizeVarbit },
281292 {"HT" , halfSizeVarbit , tinyVarbit },
293+ {"TF" , tinyVarbit , fullSizeVarbit },
294+ {"TH" , tinyVarbit , halfSizeVarbit },
282295 {"TT" , tinyVarbit , tinyVarbit },
283296 },
284297 },
0 commit comments