Skip to content

Commit e6bd5de

Browse files
mahitha-adamutianf
authored andcommitted
fix(bigquery): resultSet.getLong() does not truncate for large int64 values (googleapis#13718)
Fixes [googleapis#12938](googleapis#12938) This fixes `BigQueryResultImpl.ResultSet#getLong(int)` for Read API rows. The index-based getter previously delegated to `getInt(String)`, which truncated large INT64 values and could return negative results. A regression test now verifies that `getLong(int)` preserves a value larger than `Integer.MAX_VALUE`. Tests: - `mvn -pl java-bigquery/google-cloud-bigquery -Dtest=BigQueryResultImplTest -DskipITs=true test`
1 parent 1fe8239 commit e6bd5de

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryResultImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ public long getLong(int columnIndex) throws SQLException {
475475
wasNull = false;
476476
return fieldValue.getNumericValue().longValue();
477477
} else { // Data received from Read API (Arrow)
478-
return getInt(schemaFieldList.get(columnIndex).getName());
478+
return getLong(schemaFieldList.get(columnIndex).getName());
479479
}
480480
}
481481

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryResultImplTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,27 @@ void testResultSetReadApi() throws InterruptedException, SQLException {
293293

294294
assertThat(resultSet.next()).isFalse();
295295
}
296+
297+
@Test
298+
void testResultSetReadApiGetLongByColumnIndexPreservesInt64Value()
299+
throws InterruptedException, SQLException {
300+
long largeInt64Value = 3_000_000_000L;
301+
BlockingQueue<BigQueryResultImpl.Row> buffer = new LinkedBlockingDeque<>(BUFFER_SIZE);
302+
303+
Map<String, Object> rowValues = new HashMap<>();
304+
rowValues.put("long", largeInt64Value);
305+
buffer.put(new BigQueryResultImpl.Row(rowValues));
306+
buffer.put(new BigQueryResultImpl.Row(null, true)); // End of buffer marker.
307+
308+
BigQueryResultImpl<BigQueryResultImpl.Row> bigQueryResult =
309+
new BigQueryResultImpl<>(SCHEMA, 1, buffer, null);
310+
ResultSet resultSet = bigQueryResult.getResultSet();
311+
312+
assertThat(resultSet.next()).isTrue();
313+
assertThat(resultSet.getLong(1)).isEqualTo(largeInt64Value);
314+
assertThat(resultSet.wasNull()).isFalse();
315+
assertThat(resultSet.getLong("long")).isEqualTo(largeInt64Value);
316+
assertThat(resultSet.wasNull()).isFalse();
317+
assertThat(resultSet.next()).isFalse();
318+
}
296319
}

0 commit comments

Comments
 (0)