30
30
import java .sql .Timestamp ;
31
31
import java .time .LocalTime ;
32
32
import java .util .AbstractList ;
33
+ import java .util .ArrayList ;
34
+ import java .util .Arrays ;
33
35
import java .util .HashMap ;
34
36
import java .util .Map ;
35
37
import java .util .concurrent .BlockingQueue ;
@@ -58,7 +60,13 @@ public class BigQueryResultImplTest {
58
60
.setMode (Field .Mode .NULLABLE )
59
61
.build (),
60
62
Field .newBuilder ("time" , StandardSQLTypeName .TIME ).setMode (Field .Mode .NULLABLE ).build (),
61
- Field .newBuilder ("date" , StandardSQLTypeName .DATE ).setMode (Field .Mode .NULLABLE ).build ());
63
+ Field .newBuilder ("date" , StandardSQLTypeName .DATE ).setMode (Field .Mode .NULLABLE ).build (),
64
+ Field .newBuilder ("intArray" , StandardSQLTypeName .INT64 )
65
+ .setMode (Field .Mode .REPEATED )
66
+ .build (),
67
+ Field .newBuilder ("stringArray" , StandardSQLTypeName .STRING )
68
+ .setMode (Field .Mode .REPEATED )
69
+ .build ());
62
70
63
71
private static final FieldList FIELD_LIST_SCHEMA =
64
72
FieldList .of (
@@ -69,7 +77,9 @@ public class BigQueryResultImplTest {
69
77
Field .of ("bytes" , LegacySQLTypeName .BYTES ),
70
78
Field .of ("timestamp" , LegacySQLTypeName .TIMESTAMP ),
71
79
Field .of ("time" , LegacySQLTypeName .TIME ),
72
- Field .of ("date" , LegacySQLTypeName .DATE ));
80
+ Field .of ("date" , LegacySQLTypeName .DATE ),
81
+ Field .of ("intArray" , LegacySQLTypeName .INTEGER ),
82
+ Field .of ("stringArray" , LegacySQLTypeName .STRING ));
73
83
74
84
private static final byte [] BYTES = {0xD , 0xE , 0xA , 0xD };
75
85
private static final String BYTES_BASE64 = BaseEncoding .base64 ().encode (BYTES );
@@ -79,6 +89,11 @@ public class BigQueryResultImplTest {
79
89
private static final String DATE = "2020-01-21" ;
80
90
private static final int DATE_INT = 0 ;
81
91
private static final Date EXPECTED_DATE = java .sql .Date .valueOf (DATE );
92
+ private static final ArrayList <Integer > EXPECTED_INT_ARRAY =
93
+ new ArrayList <>(Arrays .asList (0 , 1 , 2 , 3 , 4 ));
94
+ private static final String [] STRING_ARRAY = {"str1" , "str2" , "str3" };
95
+ private static final ArrayList <String > EXPECTED_STRING_ARRAY =
96
+ new ArrayList <>(Arrays .asList (STRING_ARRAY ));
82
97
private static final int BUFFER_SIZE = 10 ;
83
98
84
99
@ Test
@@ -97,7 +112,9 @@ public void testResultSetFieldValueList() throws InterruptedException, SQLExcept
97
112
Long .toString (EXPECTED_TIMESTAMP .getTime () / 1000 ),
98
113
false ), // getTime is in milliseconds.
99
114
FieldValue .of (Attribute .PRIMITIVE , TIME ),
100
- FieldValue .of (Attribute .PRIMITIVE , DATE )),
115
+ FieldValue .of (Attribute .PRIMITIVE , DATE ),
116
+ FieldValue .of (Attribute .REPEATED , EXPECTED_INT_ARRAY ),
117
+ FieldValue .of (Attribute .REPEATED , STRING_ARRAY )),
101
118
FIELD_LIST_SCHEMA );
102
119
buffer .put (fieldValues );
103
120
@@ -111,7 +128,9 @@ public void testResultSetFieldValueList() throws InterruptedException, SQLExcept
111
128
FieldValue .of (Attribute .PRIMITIVE , null ),
112
129
FieldValue .of (Attribute .PRIMITIVE , null ),
113
130
FieldValue .of (Attribute .PRIMITIVE , null ),
114
- FieldValue .of (Attribute .PRIMITIVE , null )),
131
+ FieldValue .of (Attribute .PRIMITIVE , null ),
132
+ FieldValue .of (Attribute .REPEATED , null ),
133
+ FieldValue .of (Attribute .REPEATED , null )),
115
134
FIELD_LIST_SCHEMA );
116
135
buffer .put (nullValues );
117
136
@@ -143,6 +162,10 @@ public void testResultSetFieldValueList() throws InterruptedException, SQLExcept
143
162
assertThat (resultSet .wasNull ()).isFalse ();
144
163
assertThat (resultSet .getDate ("date" ).getTime ()).isEqualTo (EXPECTED_DATE .getTime ());
145
164
assertThat (resultSet .wasNull ()).isFalse ();
165
+ assertThat (resultSet .getArray ("intArray" ).getArray ()).isEqualTo (EXPECTED_INT_ARRAY );
166
+ assertThat (resultSet .wasNull ()).isFalse ();
167
+ assertThat (resultSet .getArray ("stringArray" ).getArray ()).isEqualTo (EXPECTED_STRING_ARRAY );
168
+ assertThat (resultSet .wasNull ()).isFalse ();
146
169
147
170
assertThat (resultSet .next ()).isTrue ();
148
171
assertThat (resultSet .getObject ("string" )).isNull ();
@@ -167,6 +190,10 @@ public void testResultSetFieldValueList() throws InterruptedException, SQLExcept
167
190
assertThat (resultSet .wasNull ()).isTrue ();
168
191
assertThat (resultSet .getDate ("date" )).isNull ();
169
192
assertThat (resultSet .wasNull ()).isTrue ();
193
+ assertThat (resultSet .getArray ("intArray" )).isNull ();
194
+ assertThat (resultSet .wasNull ()).isTrue ();
195
+ assertThat (resultSet .getArray ("stringArray" )).isNull ();
196
+ assertThat (resultSet .wasNull ()).isTrue ();
170
197
171
198
assertThat (resultSet .next ()).isFalse ();
172
199
}
@@ -184,6 +211,8 @@ public void testResultSetReadApi() throws InterruptedException, SQLException {
184
211
rowValues .put ("timestamp" , EXPECTED_TIMESTAMP .getTime () * 1000 );
185
212
rowValues .put ("time" , EXPECTED_TIME .getTime () * 1000 );
186
213
rowValues .put ("date" , DATE_INT );
214
+ rowValues .put ("intArray" , EXPECTED_INT_ARRAY );
215
+ rowValues .put ("stringArray" , STRING_ARRAY );
187
216
buffer .put (new BigQueryResultImpl .Row (rowValues ));
188
217
189
218
Map <String , Object > nullValues = new HashMap <>();
@@ -195,6 +224,8 @@ public void testResultSetReadApi() throws InterruptedException, SQLException {
195
224
nullValues .put ("timestamp" , null );
196
225
nullValues .put ("time" , null );
197
226
nullValues .put ("date" , null );
227
+ nullValues .put ("intArray" , null );
228
+ nullValues .put ("stringArray" , null );
198
229
buffer .put (new BigQueryResultImpl .Row (nullValues ));
199
230
200
231
buffer .put (new BigQueryResultImpl .Row (null , true )); // End of buffer marker.
@@ -227,6 +258,10 @@ public void testResultSetReadApi() throws InterruptedException, SQLException {
227
258
// JVM default timezone which causes flakes in non-UTC zones.
228
259
assertThat (resultSet .getDate ("date" )).isNotNull ();
229
260
assertThat (resultSet .wasNull ()).isFalse ();
261
+ assertThat (resultSet .getArray ("intArray" )).isNotNull ();
262
+ assertThat (resultSet .wasNull ()).isFalse ();
263
+ assertThat (resultSet .getArray ("stringArray" )).isNotNull ();
264
+ assertThat (resultSet .wasNull ()).isFalse ();
230
265
231
266
assertThat (resultSet .next ()).isTrue ();
232
267
assertThat (resultSet .getObject ("string" )).isNull ();
@@ -251,6 +286,10 @@ public void testResultSetReadApi() throws InterruptedException, SQLException {
251
286
assertThat (resultSet .wasNull ()).isTrue ();
252
287
assertThat (resultSet .getDate ("date" )).isNull ();
253
288
assertThat (resultSet .wasNull ()).isTrue ();
289
+ assertThat (resultSet .getArray ("intArray" )).isNull ();
290
+ assertThat (resultSet .wasNull ()).isTrue ();
291
+ assertThat (resultSet .getArray ("stringArray" )).isNull ();
292
+ assertThat (resultSet .wasNull ()).isTrue ();
254
293
255
294
assertThat (resultSet .next ()).isFalse ();
256
295
}
0 commit comments