You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
QueryJob.result() - pages don't respect the start index #2173
The start_index option is ignored when the page_size option is used (or possible just multiple pages):
from google.cloud import bigquery
start_index = 10
query_job = bigquery.Client().query(
"SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50;",
job_id_prefix="test_query_w_start_index_",
)
# check the normal row iterator
result = query_job.result(start_index=start_index, page_size=10)
print(result.total_rows)
print(len(list(result))) # returns 50 not 40
# iterate over pages
result = query_job.result(start_index=start_index, page_size=10)
print(result.total_rows)
print(sum(len(list(page)) for page in result.pages)) # returns 50 not 40
Thanks for raising the issue, I was able to reproduce it. Interestingly, I could get 40 rows of results if I leave page_size to be empty:
from google.cloud import bigquery
start_index = 10
query_job = bigquery.Client().query(
"SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50;",
job_id_prefix="test_query_w_start_index_",
)
# check the normal row iterator
result = query_job.result(start_index=start_index)
print(result.total_rows)
print(len(list(result))). # get 40
I think it was somewhat related to this change, but it still remains to figure out how to fix it. Mostly, using start_index and using page_size seem incompatible.
IMO the two arguments should work together so you can use start_index to resume / restart iterating over a table (my use case). So the first row in page 0 is start_index.
I was able to make len(list(result)) = 40, but result.total_rows is still 50. This is a number returned by the service, even if we pass start_index, so there isn't much we can do on the SDK side. We may argue that the number of rows of results is still 50, we are just reading the last 40 of them, but that might be a stretch 😂 Let me double check what the intended behavior is.
I have checked with the team and result.total_rows being 50 is the intended behavior, because it reflects the number of rows returned by the query. start_index only reflects how you want to read it.
Activity
Linchin commentedon May 7, 2025
Thanks for raising the issue, I was able to reproduce it. Interestingly, I could get 40 rows of results if I leave page_size to be empty:
I think it was somewhat related to this change, but it still remains to figure out how to fix it. Mostly, using start_index and using page_size seem incompatible.
asmith-wowcorp commentedon May 8, 2025
IMO the two arguments should work together so you can use
start_indexto resume / restart iterating over a table (my use case). So the first row in page 0 isstart_index.Linchin commentedon May 13, 2025
I was able to make
len(list(result)) = 40, butresult.total_rowsis still 50. This is a number returned by the service, even if we passstart_index, so there isn't much we can do on the SDK side. We may argue that the number of rows of results is still 50, we are just reading the last 40 of them, but that might be a stretch 😂 Let me double check what the intended behavior is.Linchin commentedon May 13, 2025
I have checked with the team and
result.total_rowsbeing 50 is the intended behavior, because it reflects the number of rows returned by the query.start_indexonly reflects how you want to read it.