Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-985356 Do not start chunk downloader when first batch causes error #993

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions arrow_chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func (arc *arrowResultChunk) decodeArrowBatch(scd *snowflakeChunkDownloader) (*[
}

// Build arrow chunk based on RowSet of base64
func buildFirstArrowChunk(rowsetBase64 string, loc *time.Location, alloc memory.Allocator) arrowResultChunk {
func buildFirstArrowChunk(rowsetBase64 string, loc *time.Location, alloc memory.Allocator) (arrowResultChunk, error) {
rowSetBytes, err := base64.StdEncoding.DecodeString(rowsetBase64)
if err != nil {
return arrowResultChunk{}
return arrowResultChunk{}, err
}
rr, err := ipc.NewReader(bytes.NewReader(rowSetBytes), ipc.WithAllocator(alloc))
if err != nil {
return arrowResultChunk{}
return arrowResultChunk{}, err
}

return arrowResultChunk{rr, 0, loc, alloc}
return arrowResultChunk{rr, 0, loc, alloc}, nil
}
10 changes: 8 additions & 2 deletions chunk_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@
if scd.sc != nil && scd.sc.cfg != nil {
loc = getCurrentLocation(scd.sc.cfg.Params)
}
firstArrowChunk := buildFirstArrowChunk(scd.RowSet.RowSetBase64, loc, scd.pool)
firstArrowChunk, err := buildFirstArrowChunk(scd.RowSet.RowSetBase64, loc, scd.pool)
if err != nil {
return err
}
higherPrecision := higherPrecisionEnabled(scd.ctx)
scd.CurrentChunk, err = firstArrowChunk.decodeArrowChunk(scd.RowSet.RowType, higherPrecision)
scd.CurrentChunkSize = firstArrowChunk.rowCount
Expand Down Expand Up @@ -274,7 +277,10 @@
if scd.sc != nil && scd.sc.cfg != nil {
loc = getCurrentLocation(scd.sc.cfg.Params)
}
firstArrowChunk := buildFirstArrowChunk(scd.RowSet.RowSetBase64, loc, scd.pool)
firstArrowChunk, err := buildFirstArrowChunk(scd.RowSet.RowSetBase64, loc, scd.pool)
if err != nil {
return err
}

Check warning on line 283 in chunk_downloader.go

View check run for this annotation

Codecov / codecov/patch

chunk_downloader.go#L282-L283

Added lines #L282 - L283 were not covered by tests
scd.FirstBatch = &ArrowBatch{
idx: 0,
scd: scd,
Expand Down
28 changes: 28 additions & 0 deletions chunk_downloader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package gosnowflake

import (
"context"
"testing"
)

func TestChunkDownloaderDoesNotStartWhenArrowParsingCausesError(t *testing.T) {
tcs := []string{
"invalid base64",
"aW52YWxpZCBhcnJvdw==", // valid base64, but invalid arrow
}
for _, tc := range tcs {
t.Run(tc, func(t *testing.T) {
scd := snowflakeChunkDownloader{
ctx: context.Background(),
QueryResultFormat: "arrow",
RowSet: rowSetType{
RowSetBase64: tc,
},
}

err := scd.start()

assertNotNilF(t, err)
})
}
}
Loading