🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
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

Closed

Description

@asmith-wowcorp

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

Expected result is 40 rows returned (50 - 10).

bigqquery version 3.30.0

Activity

  1. assigned and unassigned on May 7, 2025
  2. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on May 7, 2025
  3. Linchin commented on May 7, 2025

    @Linchin
    Contributor

    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.

  4. asmith-wowcorp commented on May 8, 2025

    @asmith-wowcorp
    Author

    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.

  5. Linchin commented on May 13, 2025

    @Linchin
    Contributor

    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.

  6. Linchin commented on May 13, 2025

    @Linchin
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p2Moderately-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.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions