Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add sample for fetching total_rows from query results.#7217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tswast merged 2 commits intogoogleapis:masterfromtswast:b123578325-total-rows
Jan 30, 2019

Conversation

@tswast
Copy link
Contributor

In response to feedback internally Bug 123578325, add a sample (acts as a system test, too) which shows how to populate thetotal_rows value.

@googlebotgooglebot added the cla: yesThis human has signed the Contributor License Agreement. labelJan 29, 2019
results=query_job.result()# Waits for query to complete.
next(iter(results))# Fetch the first page of results, which contains total_rows.
print("Got {} rows.".format(results.total_rows))
# [START bigquery_query_total_rows]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

END?



deftest_client_query_total_rows(client,capsys):
"""Run a query an just check for how many rows."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

s/an/and/

@tseavertseaver added api: bigqueryIssues related to the BigQuery API. type: docsImprovement to the documentation for an API. labelsJan 29, 2019
@tswasttswast merged commit51c97cd intogoogleapis:masterJan 30, 2019
@tswasttswast deleted the b123578325-total-rows branchJanuary 30, 2019 00:42
@yan-hic
Copy link

Would fetching the first page ofresult() not make an API call ? If so, why not reading as per#6117._query_results of the query job does get updated byresult()

@tswast
Copy link
ContributorAuthor

@yiga2 Callingresult() makes an API request, but not totabledata.list, where we get thetotal_rows from. As you point out in#6117, the request to wait for the job to complete actually contains atotal_rows value as well, but we don't pass that through to theRowIterator.

I agree that the way I show in this sample is a bit awkward, and I was thinking about fetching the first page automatically in#4152, but I changed my mind about prefetching, since it could mean an extra unnecessary API request if someone just cares that a query completes and not the actual result rows.

Perhaps we could find a way to pass thetotal_rows through to theRowIterator after it is constructed inresult() to avoid the extra API request.

@yan-hic
Copy link

yan-hic commentedMar 15, 2019
edited
Loading

@tswast any further consideration on gettingtotal_rows without an add'l API call ?

@tswast
Copy link
ContributorAuthor

@yiga2 I still think it's a good idea. I just haven't gotten around to. We're open to PRs. The change would likely be to theresult method ofQueryJob injob.py.

@yan-hic
Copy link

@tswast Feel free to bundle with other enhancements as PR would be very light otherwise.

Suggested code change, after

schema=self._query_results.schema

total_rows = self._query_results.total_rows

@yan-hic
Copy link

@tswast any feedback on this ?

@tswast
Copy link
ContributorAuthor

@yiga2 I've prepared#7622 which addresses this issue, but in a slightly more complicated way than we propose here because I wanted to also handle more cases whereClient.list_rows is called directly. My PR has had one pass at review, but I'm waiting on a follow-up now that I've addressed the requested changes.

@yan-hic
Copy link

Cool - thanks Tim !

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

Reviewers

@shollymanshollymanshollyman approved these changes

@crwilcoxcrwilcoxAwaiting requested review from crwilcox

+1 more reviewer

@tseavertseavertseaver approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

api: bigqueryIssues related to the BigQuery API.cla: yesThis human has signed the Contributor License Agreement.type: docsImprovement to the documentation for an API.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@tswast@yan-hic@tseaver@shollyman@googlebot

[8]ページ先頭

©2009-2025 Movatter.jp