-
Notifications
You must be signed in to change notification settings - Fork 125
/
chunk_downloader_test.go
140 lines (130 loc) · 3.38 KB
/
chunk_downloader_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package gosnowflake
import (
"context"
"database/sql/driver"
"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)
})
}
}
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 TestWithArrowBatchesWhenQueryReturnsRowsAndReadingRows(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
rows := dbt.mustQueryContext(WithArrowBatches(context.Background()), "SELECT 1")
defer rows.Close()
assertFalseF(t, rows.Next())
})
}
func TestWithArrowBatchesWhenQueryReturnsNoRowsAndReadingRows(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
rows := dbt.mustQueryContext(WithArrowBatches(context.Background()), "SELECT 1 WHERE 1 = 0")
defer rows.Close()
assertFalseF(t, rows.Next())
})
}
func TestWithArrowBatchesWhenQueryReturnsNoRowsAndReadingArrowBatches(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
var rows driver.Rows
var err error
err = dbt.conn.Raw(func(x any) error {
rows, err = x.(driver.QueryerContext).QueryContext(WithArrowBatches(context.Background()), "SELECT 1 WHERE 1 = 0", nil)
return err
})
assertNilF(t, err)
defer rows.Close()
batches, err := rows.(SnowflakeRows).GetArrowBatches()
assertNilF(t, err)
assertEmptyE(t, batches)
})
}
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 func() {
assertNilF(t, rows.Close())
}()
values := make([]driver.Value, 1)
assertNotNilE(t, rows.Next(values)) // we deliberately check that there is an error, because we are in arrow batches mode
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 func() {
assertNilF(t, rows.Close())
}()
assertFalseF(t, rows.Next())
})
})
}
}