Skip to content

BigQuery: populate RowIterator.total_rows after running a query job #6117

Closed

Description

@yan-hic

Request to have total_rows property public, under QueryJob() along with other stats

Activity

  1. shollyman commented on Sep 27, 2018

    @shollyman
    Contributor

    My initial preference would be against exposing this directly as property of the QueryJob, as its part of the jobs.getQueryResults / tabledata.list response and not a member of the query stats metadata.

    Is the interest in fetching the table statistics for the results without the extra fetch of destination table metadata, or are you interested in it related to progress while fetching row data?

  2. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    api: bigqueryIssues related to the BigQuery API.
    and removed
    triage meI really want to be triaged.
    on Sep 27, 2018
  3. yan-hic commented on Sep 27, 2018

    @yan-hic
    Author

    The interest is to determine how many rows a query, when completed, has generated.
    Fetching the destination table metadata is not valid if records are appended to an existing table - I would get the total number of rows, not the addition.

    Note that totalRows exists in both jobs.getQueryResults and jobs.query. There is no need to call the former (except if job is inserted) so request is not unreasonable. Also, https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#totalBytesProcessed made it as property of QueryJob() so why not total_rows.

  4. shollyman commented on Sep 27, 2018

    @shollyman
    Contributor

    Thanks for clarifying the interest is in the effective delta.

    For the case where you run a query with a destination table and a WRITE_APPEND disposition, the results (and total_rows) will represent the whole table. For mutation DML queries (e.g. UPDATE/DELETE), num_dml_affected_rows may help, but we should consider exposing something like the statistics.load.outputRows equivalent for query jobs (likely contingent on statement type).

    If that sounds like what you're after, I'll request it for inclusion in the backend response. There's insufficient information in the existing response to correctly report the delta for the append case.

  5. yan-hic commented on Sep 27, 2018

    @yan-hic
    Author

    Let's cancel the request as I just suggested making the existing - and perfectly working - _query_results.total_rows a public property of QueryJob() or another object. I thought https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/generated/google.cloud.bigquery.job.QueryJob.result.html#google.cloud.bigquery.job.QueryJob.result would work but it doesn't, total_rows is None (myqueryjob.result().total_rows).
    This was reported on SO too: https://stackoverflow.com/questions/48799898/bigquery-py-client-library-v0-28-fetch-result-from-table-query-job

    I will just use the private _query_results.total_rows.
    Thanks.

  6. reopened this on Jan 30, 2019
  7. tswast commented on Jan 30, 2019

    @tswast
    Contributor

    Let's write the total_rows value from the QueryResults to the RowIterator so that it's available without an additional (and awkward) API requests to tabledata.list that I do in the code sample at #7217.

  8. yan-hic commented on Jan 30, 2019

    @yan-hic
    Author

    Thanks Tim ! To add some additional context, I have also reported an unexpected behavior of the underlying totalRecords API property here

  9. changed the title [-]BigQuery: make QueryJob._query_results.total_rows public[/-] [+]BigQuery: populate RowIterator.total_rows after running a query job[/+] on Mar 28, 2019
  10. self-assigned this
    on Mar 28, 2019
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 BigQuery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions