Skip to content

Commit 00be309

Browse files
authored
Bugfix/fix decode issues (#88)
* issue-87: Fix nil on querying map * issue-86: Fix Nullable base types with prefix * format * try * try * fix tests * fix tests
1 parent 84dbead commit 00be309

34 files changed

+109
-58
lines changed

.github/workflows/run-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ jobs:
5252

5353
- name: Run tests
5454
run: |
55+
sudo rm -rf /usr/share/dotnet
56+
sudo rm -rf /usr/local/lib/android
57+
sudo rm -rf /opt/ghc
58+
df -h
5559
go test -v .
5660
go test -v ./tests
5761
go test -v ./lib/...

lib/column/map.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,14 @@ func (col *Map) Decode(decoder *binary.Decoder, rows int) error {
145145
if err := col.offsets.Decode(decoder, rows); err != nil {
146146
return err
147147
}
148-
size := int(col.offsets.col[len(col.offsets.col)-1])
149-
if err := col.keys.Decode(decoder, size); err != nil {
150-
return err
148+
if i := len(col.offsets.col); i != 0 {
149+
size := int(col.offsets.col[i-1])
150+
if err := col.keys.Decode(decoder, size); err != nil {
151+
return err
152+
}
153+
return col.values.Decode(decoder, size)
151154
}
152-
return col.values.Decode(decoder, size)
155+
return nil
153156
}
154157

155158
func (col *Map) Encode(encoder *binary.Encoder) error {

lib/column/nullable.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package column
1919

2020
import (
21+
"fmt"
2122
"reflect"
2223
"time"
2324

@@ -131,4 +132,24 @@ func (col *Nullable) Encode(encoder *binary.Encoder) error {
131132
return nil
132133
}
133134

135+
func (col *Nullable) ReadStatePrefix(decoder *binary.Decoder) error {
136+
if serialize, ok := col.base.(CustomSerialization); ok {
137+
if err := serialize.ReadStatePrefix(decoder); err != nil {
138+
return fmt.Errorf("failed to read prefix for Nullable base type %s: %w", col.base.Type(), err)
139+
}
140+
}
141+
142+
return nil
143+
}
144+
145+
func (col *Nullable) WriteStatePrefix(encoder *binary.Encoder) error {
146+
if serialize, ok := col.base.(CustomSerialization); ok {
147+
if err := serialize.WriteStatePrefix(encoder); err != nil {
148+
return fmt.Errorf("failed to write prefix for Nullable base type %s: %w", col.base.Type(), err)
149+
}
150+
}
151+
152+
return nil
153+
}
154+
134155
var _ Interface = (*Nullable)(nil)

tests/abort_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ func TestAbort(t *testing.T) {
5353
conn.Exec(ctx, "DROP STREAM test_abort")
5454
}()
5555
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
56-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_abort (* except _tp_time)"); assert.NoError(t, err) {
56+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_abort (Col1)"); assert.NoError(t, err) {
5757
if assert.NoError(t, batch.Abort()) {
5858
if err := batch.Abort(); assert.Error(t, err) {
5959
assert.Equal(t, proton.ErrBatchAlreadySent, err)
6060
}
6161
}
6262
}
63-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_abort (* except _tp_time)"); assert.NoError(t, err) {
63+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_abort (Col1)"); assert.NoError(t, err) {
6464
if assert.NoError(t, batch.Append(uint8(1))) && assert.NoError(t, batch.Send()) {
6565
var col1 uint8
6666
if err := conn.QueryRow(ctx, "SELECT (* except _tp_time) FROM test_abort WHERE _tp_time > earliest_ts() LIMIT 1").Scan(&col1); assert.NoError(t, err) {

tests/array_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestColumnarArray(t *testing.T) {
183183
col3DataColArr = append(col3DataColArr, col3Data)
184184
}
185185

186-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_array (* except _tp_time)"); assert.NoError(t, err) {
186+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_array (Col1, Col2, Col3)"); assert.NoError(t, err) {
187187
if err := batch.Column(0).Append(col1DataColArr); !assert.NoError(t, err) {
188188
return
189189
}

tests/base_types_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestUInt8(t *testing.T) {
6262
Col4 []*uint8
6363
}
6464
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
65-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_uint8 (* except _tp_time)"); assert.NoError(t, err) {
65+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_uint8 (ID, Col1, Col2, Col3, Col4)"); assert.NoError(t, err) {
6666
data := uint8(42)
6767
if !assert.NoError(t, err) {
6868
return
@@ -129,7 +129,7 @@ func TestColumnarUInt8(t *testing.T) {
129129
conn.Exec(ctx, "DROP STREAM test_uint8")
130130
}()
131131
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
132-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_uint8 (* except _tp_time)"); assert.NoError(t, err) {
132+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_uint8 (ID, Col1, Col2, Col3, Col4)"); assert.NoError(t, err) {
133133
var (
134134
id []uint64
135135
col1Data []uint8

tests/bigint_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestBigInt(t *testing.T) {
6161
conn.Exec(ctx, "DROP STREAM test_bigint")
6262
}()
6363
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
64-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_bigint (* except _tp_time)"); assert.NoError(t, err) {
64+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_bigint (Col1, Col2, Col3, Col4, Col5, Col6)"); assert.NoError(t, err) {
6565
var (
6666
col1Data = big.NewInt(128)
6767
col2Data = []*big.Int{
@@ -138,7 +138,7 @@ func TestNullableBigInt(t *testing.T) {
138138
conn.Exec(ctx, "DROP STREAM test_nullable_bigint")
139139
}()
140140
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
141-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_nullable_bigint (* except _tp_time)"); assert.NoError(t, err) {
141+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_nullable_bigint (Col1, Col2, Col3, Col4, Col5, Col6)"); assert.NoError(t, err) {
142142
var (
143143
col1Data = big.NewInt(128)
144144
col2Data = []*big.Int{

tests/bool_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestBool(t *testing.T) {
5959
conn.Exec(ctx, "DROP STREAM test_bool")
6060
}()
6161
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
62-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_bool (* except _tp_time)"); assert.NoError(t, err) {
62+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_bool (Col1, Col2, Col3, Col4, Col5)"); assert.NoError(t, err) {
6363
var val bool
6464
if err := batch.Append(true, false, []bool{true, false, true}, nil, []*bool{&val, nil, &val}); assert.NoError(t, err) {
6565
if err := batch.Send(); assert.NoError(t, err) {
@@ -121,7 +121,7 @@ func TestColumnarBool(t *testing.T) {
121121
}()
122122
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
123123
val := true
124-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_bool (* except _tp_time)"); assert.NoError(t, err) {
124+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_bool (ID, Col1, Col2, Col3, Col4, Col5)"); assert.NoError(t, err) {
125125
var (
126126
id []uint64
127127
col1 []bool

tests/columnar_batch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestColumnarInterface(t *testing.T) {
5555
conn.Exec(ctx, "DROP STREAM test_column_interface")
5656
}()
5757
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
58-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_column_interface (* except _tp_time)"); assert.NoError(t, err) {
58+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_column_interface (Col1, Col2, Col3)"); assert.NoError(t, err) {
5959
var (
6060
col1Data []uint8
6161
col2Data []string

tests/date32_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestDate32(t *testing.T) {
6969
Col4 []*types.Date
7070
}
7171
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
72-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_date32 (* except _tp_time)"); assert.NoError(t, err) {
72+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_date32 (ID, Col1, Col2, Col3, Col4)"); assert.NoError(t, err) {
7373
var (
7474
time1, _ = time.Parse("2006-01-02 15:04:05", "2100-01-01 00:00:00")
7575
time2, _ = time.Parse("2006-01-02 15:04:05", "1925-01-01 00:00:00")
@@ -245,7 +245,7 @@ func TestColumnarDate32(t *testing.T) {
245245
conn.Exec(ctx, "DROP STREAM test_date32")
246246
}()
247247
if err := conn.Exec(ctx, ddl); assert.NoError(t, err) {
248-
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_date32 (* except _tp_time)"); assert.NoError(t, err) {
248+
if batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_date32 (ID, Col1, Col2, Col3, Col4)"); assert.NoError(t, err) {
249249
var (
250250
id []uint64
251251
col1Data []types.Date

0 commit comments

Comments
 (0)