GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BigQuery API -- List Row with 'start Index' and Big 'Max Results' induce wrong output. · Issue #4 · googleapis/python-bigquery

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.

BigQuery API -- List Row with 'start Index' and Big 'Max Results' induce wrong output. #4

Copy link
Copy link
Closed
#27
Closed
BigQuery API -- List Row with 'start Index' and Big 'Max Results' induce wrong output.#4
#27
Copy link
Assignees
HemangChothani
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.

Description

@adussarps
adussarps
opened on Jan 23, 2020
Issue body actions
Environment details

Using the google-cloud-bigquery client with version 1.23.1
Python 3.7 (on linux and macos)

Steps to reproduce

  1. Using client.list_row with max_result and start_index induce wrong data to be pulled when
    the client needs to use more than one page.
    He then issued a second call with 'nextPageToken' and 'startIndex' wich seems to be incompatible.

Code example

def table_to_df_iterator(project_id, dataset_id, table_id) -> iter:
    table_full_id = project_id + "." + dataset_id + "." + table_id
    client = get_client()
    index = 0
    while True:
        offset = BATCH_SIZE_ROWS * index
        df = client.list_rows(table_full_id, max_results=BATCH_SIZE_ROWS, 
                                          start_index=offset).to_dataframe()
        if df.empty:
            break
        logging.info(f"Offset is at {offset} got a dataframe of size {len(DataFrame.index)}")
        yield df
        index += 1

Trace

DEBUG:google.cloud.bigquery.table:Started reading table 'samsung-global-dashboard.1_Raw.Facebook_SEUK_VIDEO_20190101' with tabledata.list.
DEBUG:urllib3.connectionpool:https://bigquery.googleapis.com:443 "GET /bigquery/v2/projects/samsung-global-dashboard/datasets/1_Raw/tables/Facebook_SEUK_VIDEO_20190101/data?maxResults=100000&startIndex=100000 HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:https://bigquery.googleapis.com:443 "GET /bigquery/v2/projects/samsung-global-dashboard/datasets/1_Raw/tables/Facebook_SEUK_VIDEO_20190101/data?pageToken=BEP6ZNORN4AQAAASAUIIBAEAAUNAQCEG6ADBBIENAYQP777777777777P4VAA%3D%3D%3D&maxResults=87354&startIndex=100000 HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:https://bigquery.googleapis.com:443 "GET /bigquery/v2/projects/samsung-global-dashboard/datasets/1_Raw/tables/Facebook_SEUK_VIDEO_20190101/data?pageToken=BEP6ZNORN4AQAAASAUIIBAEAAUNAQCEG6ADBBOVKAUQP777777777777P4VAA%3D%3D%3D&maxResults=74708&startIndex=100000 HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:https://bigquery.googleapis.com:443 "GET /bigquery/v2/projects/samsung-global-dashboard/datasets/1_Raw/tables/Facebook_SEUK_VIDEO_20190101/data?pageToken=BEP6ZNORN4AQAAASAUIIBAEAAUNAQCEG6ADBBVGHAQQP777777777777P4VAA%3D%3D%3D&maxResults=62062&startIndex=100000 HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:https://bigquery.googleapis.com:443 "GET /bigquery/v2/projects/samsung-global-dashboard/datasets/1_Raw/tables/Facebook_SEUK_VIDEO_20190101/data?pageToken=BEP6ZNORN4AQAAASAUIIBAEAAUNAQCEG6ADBB3XEAMQP777777777777P4VAA%3D%3D%3D&maxResults=49416&startIndex=100000 HTTP/1.1" 200 None

Idea to fix

Make the second call use an updated startIndex instead of 'nextPageToken'

Thanks!

Activity

  1. HemangChothani
    self-assigned this
    on Jan 27, 2020
  2. HemangChothani commented on Jan 28, 2020

    @HemangChothani
    HemangChothani
    on Jan 28, 2020
    Contributor
    More actions

    @tswast @plamut Need your opinion as this issue is reproducible when passing startIndex >0 with page_size, In the response found same next_page_token every time so may be it's a backend issue, but it's working fine when startIndex=0 with page_size.

    Temp Fix:
    For now we can update startIndex manually here.

    sample Code:

    if 'startIndex' in params:
        start_index = self._extra_params['startIndex']
        new_start_index = start_index + self._page_size
        self._extra_params['startIndex'] = new_start_index
        params['startIndex'] = new_start_index  
    
  3. tswast commented on Jan 28, 2020

    @tswast
    tswast
    on Jan 28, 2020
    Contributor
    More actions

    Don't use startIndex once you have a page token.

    We should drop the start index from the request after the first page.

  4. plamut
    transferred this issue fromgoogleapis/google-cloud-pythonon Feb 4, 2020
  5. product-auto-label
    added
    api: bigqueryIssues related to the googleapis/python-bigquery API.
    on Feb 4, 2020
  6. plamut
    added
    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.
    on Feb 4, 2020
  7. plamut
    closed this as completedin #27on Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @HemangChothani
    HemangChothani

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.