File tree 4 files changed +27
-2
lines changed
google-cloud-bigquery/src
main/java/com/google/cloud/bigquery
test/java/com/google/cloud/bigquery
4 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,9 @@ private class BigQueryResultSet extends AbstractJdbcResultSet {
113
113
@ Override
114
114
/*Advances the result set to the next row, returning false if no such row exists. Potentially blocking operation*/
115
115
public boolean next () throws SQLException {
116
+ if (buffer == null ) {
117
+ return false ;
118
+ }
116
119
if (hasReachedEnd ) { // if end of stream is reached then we can simply return false
117
120
return false ;
118
121
}
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ ListenableFuture<ExecuteSelectResponse> executeSelectAsync(String sql)
140
140
* @code
141
141
* ConnectionSettings connectionSettings =
142
142
* ConnectionSettings.newBuilder()
143
- * .. setUseReadAPI(true)
143
+ * .setUseReadAPI(true)
144
144
* .build();
145
145
* Connection connection = bigquery.createConnection(connectionSettings);
146
146
* String selectQuery =
Original file line number Diff line number Diff line change @@ -411,7 +411,7 @@ public void testLegacyQuerySinglePage() throws BigQuerySQLException {
411
411
412
412
// calls executeSelect with a nonFast query where the query returns an empty result.
413
413
@ Test
414
- public void testLegacyQuerySinglePageEmptyResults () throws BigQuerySQLException {
414
+ public void testLegacyQuerySinglePageEmptyResults () throws BigQuerySQLException , SQLException {
415
415
ConnectionImpl connectionSpy = Mockito .spy (connection );
416
416
com .google .api .services .bigquery .model .Job jobResponseMock =
417
417
new com .google .api .services .bigquery .model .Job ()
@@ -428,6 +428,10 @@ public void testLegacyQuerySinglePageEmptyResults() throws BigQuerySQLException
428
428
BigQueryResult res = connectionSpy .executeSelect (SQL_QUERY );
429
429
assertEquals (res .getTotalRows (), 0 );
430
430
assertEquals (QUERY_SCHEMA , res .getSchema ());
431
+ assertEquals (
432
+ false ,
433
+ res .getResultSet ()
434
+ .next ()); // Validates that NPE does not occur when reading from empty ResultSet.
431
435
verify (bigqueryRpcMock , times (1 ))
432
436
.createJobForQuery (any (com .google .api .services .bigquery .model .Job .class ));
433
437
}
Original file line number Diff line number Diff line change @@ -3491,6 +3491,24 @@ public void testExecuteSelectDefaultConnectionSettings() throws SQLException {
3491
3491
assertEquals (42 , bigQueryResult .getTotalRows ());
3492
3492
}
3493
3493
3494
+ @ Test
3495
+ public void testExecuteSelectReadApiEmptyResultSet () throws SQLException {
3496
+ ConnectionSettings connectionSettings =
3497
+ ConnectionSettings .newBuilder ()
3498
+ .setJobTimeoutMs (
3499
+ Long .MAX_VALUE ) // Force executeSelect to use ReadAPI instead of fast query.
3500
+ .setUseReadAPI (true )
3501
+ .setUseQueryCache (false )
3502
+ .build ();
3503
+ Connection connection = bigquery .createConnection (connectionSettings );
3504
+ String query = "SELECT TIMESTAMP '2022-01-24T23:54:25.095574Z' LIMIT 0" ;
3505
+ BigQueryResult bigQueryResult = connection .executeSelect (query );
3506
+
3507
+ ResultSet rs = bigQueryResult .getResultSet ();
3508
+ assertThat (rs .next ()).isFalse ();
3509
+ assertThat (bigQueryResult .getTotalRows ()).isEqualTo (0 );
3510
+ }
3511
+
3494
3512
@ Test
3495
3513
public void testExecuteSelectWithCredentials () throws SQLException {
3496
3514
// This test validate that executeSelect uses the same credential provided by the BigQuery
You can’t perform that action at this time.
0 commit comments