Skip to content

Commit a4c3557

Browse files
authored
SNOW-985356 Do not start chunk downloader when first batch causes error (snowflakedb#993)
1 parent cf94c15 commit a4c3557

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

arrow_chunk.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ func (arc *arrowResultChunk) decodeArrowBatch(scd *snowflakeChunkDownloader) (*[
6868
}
6969

7070
// Build arrow chunk based on RowSet of base64
71-
func buildFirstArrowChunk(rowsetBase64 string, loc *time.Location, alloc memory.Allocator) arrowResultChunk {
71+
func buildFirstArrowChunk(rowsetBase64 string, loc *time.Location, alloc memory.Allocator) (arrowResultChunk, error) {
7272
rowSetBytes, err := base64.StdEncoding.DecodeString(rowsetBase64)
7373
if err != nil {
74-
return arrowResultChunk{}
74+
return arrowResultChunk{}, err
7575
}
7676
rr, err := ipc.NewReader(bytes.NewReader(rowSetBytes), ipc.WithAllocator(alloc))
7777
if err != nil {
78-
return arrowResultChunk{}
78+
return arrowResultChunk{}, err
7979
}
8080

81-
return arrowResultChunk{rr, 0, loc, alloc}
81+
return arrowResultChunk{rr, 0, loc, alloc}, nil
8282
}

chunk_downloader.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ func (scd *snowflakeChunkDownloader) start() error {
109109
if scd.sc != nil && scd.sc.cfg != nil {
110110
loc = getCurrentLocation(scd.sc.cfg.Params)
111111
}
112-
firstArrowChunk := buildFirstArrowChunk(scd.RowSet.RowSetBase64, loc, scd.pool)
112+
firstArrowChunk, err := buildFirstArrowChunk(scd.RowSet.RowSetBase64, loc, scd.pool)
113+
if err != nil {
114+
return err
115+
}
113116
higherPrecision := higherPrecisionEnabled(scd.ctx)
114117
scd.CurrentChunk, err = firstArrowChunk.decodeArrowChunk(scd.RowSet.RowType, higherPrecision)
115118
scd.CurrentChunkSize = firstArrowChunk.rowCount
@@ -274,7 +277,10 @@ func (scd *snowflakeChunkDownloader) startArrowBatches() error {
274277
if scd.sc != nil && scd.sc.cfg != nil {
275278
loc = getCurrentLocation(scd.sc.cfg.Params)
276279
}
277-
firstArrowChunk := buildFirstArrowChunk(scd.RowSet.RowSetBase64, loc, scd.pool)
280+
firstArrowChunk, err := buildFirstArrowChunk(scd.RowSet.RowSetBase64, loc, scd.pool)
281+
if err != nil {
282+
return err
283+
}
278284
scd.FirstBatch = &ArrowBatch{
279285
idx: 0,
280286
scd: scd,

chunk_downloader_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package gosnowflake
2+
3+
import (
4+
"context"
5+
"testing"
6+
)
7+
8+
func TestChunkDownloaderDoesNotStartWhenArrowParsingCausesError(t *testing.T) {
9+
tcs := []string{
10+
"invalid base64",
11+
"aW52YWxpZCBhcnJvdw==", // valid base64, but invalid arrow
12+
}
13+
for _, tc := range tcs {
14+
t.Run(tc, func(t *testing.T) {
15+
scd := snowflakeChunkDownloader{
16+
ctx: context.Background(),
17+
QueryResultFormat: "arrow",
18+
RowSet: rowSetType{
19+
RowSetBase64: tc,
20+
},
21+
}
22+
23+
err := scd.start()
24+
25+
assertNotNilF(t, err)
26+
})
27+
}
28+
}

0 commit comments

Comments
 (0)