Skip to content

Commit

Permalink
SNOW-988793 Do not read arrow chunk when it is empty for arrow batches
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pfus committed Dec 11, 2023
1 parent a4c3557 commit f645123
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func assertTrueF(t *testing.T, actual bool, descriptions ...string) {
fatalOnNonEmpty(t, validateEqual(actual, true, descriptions...))
}

func assertFalseF(t *testing.T, actual bool, descriptions ...string) {
fatalOnNonEmpty(t, validateEqual(actual, false, descriptions...))
}

func assertStringContainsE(t *testing.T, actual string, expectedToContain string, descriptions ...string) {
errorOnNonEmpty(t, validateStringContains(actual, expectedToContain, descriptions...))
}
Expand Down
3 changes: 3 additions & 0 deletions chunk_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ func getChunk(
}

func (scd *snowflakeChunkDownloader) startArrowBatches() error {
if scd.RowSet.RowSetBase64 == "" {
return nil
}
var err error
chunkMetaLen := len(scd.ChunkMetas)
var loc *time.Location
Expand Down
96 changes: 96 additions & 0 deletions chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -462,6 +463,101 @@ func TestWithArrowBatches(t *testing.T) {
})
}

func TestWithArrowBatchesWhenQueryReturnsNoRowsWhenUsingNativeGoSQLInterface(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
ctx := context.Background()

var rows driver.Rows
var err error
err = dbt.conn.Raw(func(x interface{}) error {
queryer, implementsQueryContext := x.(driver.QueryerContext)
if !implementsQueryContext {
return errors.New("gosnowflake driver does not implement queryerContext")
}
rows, err = queryer.QueryContext(WithArrowBatches(ctx), "SELECT 1 WHERE 0 = 1", nil)
return err
})
assertNilF(t, err)
defer rows.Close()
})
}

func TestWithArrowBatchesWhenQueryReturnsNoRows(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
rows := dbt.mustQueryContext(WithArrowBatches(context.Background()), "SELECT 1")
defer rows.Close()
assertFalseF(t, rows.Next())
})
}

func TestWithArrowBatchesWhenQueryReturnsSomeRowsInGivenFormatUsingNativeGoSQLInterface(t *testing.T) {
for _, tc := range []struct {
useJson bool

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Ubuntu

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Ubuntu

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Ubuntu

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.20 on Ubuntu

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.20 on Ubuntu

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Ubuntu

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Mac

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Mac

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Windows

struct field useJson should be useJSON

Check failure on line 495 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.20 on Mac

struct field useJson should be useJSON
desc string
}{
{
useJson: true,
desc: "json",
},
{
useJson: false,
desc: "arrow",
},
} {
t.Run(tc.desc, func(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
if tc.useJson {
dbt.mustExec(forceJSON)
}
ctx := context.Background()

var rows driver.Rows
var err error
err = dbt.conn.Raw(func(x interface{}) error {
queryer, implementsQueryContext := x.(driver.QueryerContext)
if !implementsQueryContext {
return errors.New("gosnowflake driver does not implement queryerContext")
}
rows, err = queryer.QueryContext(WithArrowBatches(ctx), "SELECT 1", nil)
return err
})
assertNilF(t, err)
defer rows.Close()
values := make([]driver.Value, 1)
rows.Next(values)
assertEqualE(t, values[0], nil)
})
})
}
}

func TestWithArrowBatchesWhenQueryReturnsSomeRowsInGivenFormat(t *testing.T) {
for _, tc := range []struct {
useJson bool

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Ubuntu

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Ubuntu

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Ubuntu

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.20 on Ubuntu

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.20 on Ubuntu

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Ubuntu

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Mac

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Mac

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Windows

struct field useJson should be useJSON

Check failure on line 536 in chunk_test.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.20 on Mac

struct field useJson should be useJSON
desc string
}{
{
useJson: true,
desc: "json",
},
{
useJson: false,
desc: "arrow",
},
} {
t.Run(tc.desc, func(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
if tc.useJson {
dbt.mustExec(forceJSON)
}
rows := dbt.mustQueryContext(WithArrowBatches(context.Background()), "SELECT 1")
defer rows.Close()
assertFalseF(t, rows.Next())
})
})
}
}

func TestWithArrowBatchesAsync(t *testing.T) {
runSnowflakeConnTest(t, func(sct *SCTest) {
ctx := WithAsyncMode(sct.sc.ctx)
Expand Down

0 comments on commit f645123

Please sign in to comment.