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-988793 Do not read arrow chunk when it is empty for arrow batches #998

Merged
merged 1 commit into from
Dec 19, 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
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
84 changes: 84 additions & 0 deletions chunk_downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gosnowflake

import (
"context"
"database/sql/driver"
"testing"
)

Expand All @@ -26,3 +27,86 @@ func TestChunkDownloaderDoesNotStartWhenArrowParsingCausesError(t *testing.T) {
})
}
}

func TestWithArrowBatchesWhenQueryReturnsNoRowsWhenUsingNativeGoSQLInterface(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
var rows driver.Rows
var err error
err = dbt.conn.Raw(func(x interface{}) error {
rows, err = x.(driver.QueryerContext).QueryContext(WithArrowBatches(context.Background()), "SELECT 1 WHERE 0 = 1", nil)
return err
})
assertNilF(t, err)
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
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)
}
var rows driver.Rows
var err error
err = dbt.conn.Raw(func(x interface{}) error {
rows, err = x.(driver.QueryerContext).QueryContext(WithArrowBatches(context.Background()), "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
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())
})
})
}
}
Loading