This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 134
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
BigQuery#listTableData & TableResult#iterateAll endless loop #744
Copy link
Copy link
Closed
Labels
api: bigqueryIssues related to the googleapis/java-bigquery API.Issues related to the googleapis/java-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Hello, having the following issue using BigQuery java client libs:
- BigQuery#listTableData + TableResult#iterateAll
- Java 8
- 'com.google.cloud:google-cloud-bigquery:1.117.1'`
Steps to reproduce
Observing endless loop reading rows from BQ tables via java api.
Code example
import static com.google.common.base.Preconditions.checkState;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQuery.TableDataListOption;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.Table;
import com.google.cloud.bigquery.TableId;
import com.google.cloud.bigquery.TableResult;
public class BigQueryListDataTest {
public static void main(String[] args) {
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
TableId tableId = TableId.of(
"bigquery-public-data",
"census_bureau_international",
"midyear_population_agespecific");
Table table = bigquery.getTable(tableId);
long numRows = table.getNumRows().longValue();
System.out.println("Table records # = " + numRows);
checkRecordsConsumed(bigquery, tableId, numRows - 100_000L, 100_000L);
checkRecordsConsumed(bigquery, tableId, numRows - 200_000L, 200_000L);
// this will loop forever, although it should get to end of the table after 300k rows
checkRecordsConsumed(bigquery, tableId, numRows - 300_000L, 300_000L);
}
private static void checkRecordsConsumed(BigQuery bigquery, TableId tableId, long startRow, long expectedRows) {
TableResult tableResult = bigquery.listTableData(
tableId,
TableDataListOption.startIndex(startRow),
TableDataListOption.pageSize(600_000L));
System.out.println("Reading records starting row = " + startRow);
int rowsConsumed = 0;
for (FieldValueList row : tableResult.iterateAll()) {
rowsConsumed++;
if (rowsConsumed % 50_000 == 0) {
System.out.println("% rows consumed: " + rowsConsumed);
}
}
System.out.println("Consumed record count = " + rowsConsumed);
checkState(rowsConsumed == expectedRows, "Expected %s records but iterated over %s", expectedRows, rowsConsumed);
}
}Output
Table records # = 3040302
Reading records starting row = 2940302
% rows consumed: 50000
% rows consumed: 100000
Consumed record count = 100000
Reading records starting row = 2840302
% rows consumed: 50000
% rows consumed: 100000
% rows consumed: 150000
% rows consumed: 200000
Consumed record count = 200000
Reading records starting row = 2740302
% rows consumed: 50000
% rows consumed: 100000
% rows consumed: 150000
% rows consumed: 200000
% rows consumed: 250000
% rows consumed: 300000
% rows consumed: 350000
% rows consumed: 400000
% rows consumed: 450000
% rows consumed: 500000
% rows consumed: 550000
% rows consumed: 600000
% rows consumed: 650000
% rows consumed: 700000
% rows consumed: 750000
% rows consumed: 800000
% rows consumed: 850000
% rows consumed: 900000
% rows consumed: 950000
% rows consumed: 1000000
% rows consumed: 1050000
% rows consumed: 1100000
% rows consumed: 1150000
% rows consumed: 1200000
... etc
.. stuck in endless loop
Our scenario:
- importing from BQ in parallel via splits
- each split set to import certain # of rows starting from a certain index
- => BQ table download does not contain correct data, some rows are duplicated, others are missing
- here presenting a scenario with an endless loop
Question
- is there something i am missing ? this seems like a nasty bug to me.
thx
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: bigqueryIssues related to the googleapis/java-bigquery API.Issues related to the googleapis/java-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.