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

BigQuery: Add ability to pass in a table ID instead of a query to the %%bigquery magic.#9170

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

Conversation

@shubha-rajan
Copy link
Contributor

@shubha-rajanshubha-rajan commentedSep 4, 2019
edited
Loading

Third of 3 PRs towards resolving#9105 as described in review for#9147
Screenshot of feature in notebook:
image

@googlebotgooglebot added the cla: yesThis human has signed the Contributor License Agreement. labelSep 4, 2019
added default patch to unit tests
@shubha-rajanshubha-rajanforce-pushed thebq-table-id-instead-of-query branch from6761217 to77e62c5CompareSeptember 6, 2019 05:33
@shubha-rajanshubha-rajan marked this pull request as ready for reviewSeptember 6, 2019 14:49
@shubha-rajanshubha-rajan requested a review froma teamSeptember 6, 2019 14:49
rows=client.list_rows(table_id,max_results=max_results)
exceptExceptionasex:
error=str(ex)
iferror:
Copy link
Contributor

Choose a reason for hiding this comment

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

could this be simplified to return from the exception?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

it definitely can. fixed in7a13ca4


error=None

ifnotre.search(r"\s",query.rstrip()):
Copy link
Contributor

Choose a reason for hiding this comment

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

What scenario is this protecting against? Is there a scenario where unicode strings will not remove space characters via rstrip?

What do we expect in the else case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Related: Does this repository enforce code coverage? Is there a case where we test there being unstoppable whitespace and not taking this branch?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This condition is actually testing for queries that contain whitespace characters that aren't removed by rstrip (so any whitespace that isn't a trailing newline). The assumption being made (as described in#9105 ) is that anything containing whitespace is a SQL query and won't take this branch, while anything string without whitespace is a table_id and will take this branch.

So anything regular SQL query would fall into the else case. There are tests that check whether query strings without spaces will be interpreted as table IDs and a test that checks if a string without whitespace that isn't a valid table_id raises an appropriate error message.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I can add a comment in the code if that would be helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also write this down in a comment, i.e. that anything without whitespace is assumed to be table identifier which triggers a different use case of the magic command.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

added comment ind663104

@plamutplamut added the api: bigqueryIssues related to the BigQuery API. labelSep 19, 2019
Copy link
Contributor

@plamutplamut left a comment
edited
Loading

Choose a reason for hiding this comment

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

The change generally works.

I did notice, however, that the logic is sensitive to theleading whitespace:

┌───────────────────────────────────────────┐│ %%bigquery --max_results=6                │                 |  bigquery-public-data.samples.shakespeare │└───────────────────────────────────────────┘  Executing query with job ID: a0f195e6-f748-4c42-8c3b-d89abaa37c9f  Query executing: 0.92s  ERROR:    400 Syntax error: Unexpected identifier "bigquery" at [1:3]

Wouldn't it be better to strip the whitespace on both sides first, or why we only do.rstrip()?

query_job=_run_query(client,query,job_config=job_config)
exceptExceptionasex:
error=str(ex)
return_print_error(str(ex),args.destination_var)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be slightly confusing for the reader at first glance, because_print_error() itself does not return anything, it just has a side effect. I would simply express the same in two lines (a solereturn in its own).

Copy link
ContributorAuthor

@shubha-rajanshubha-rajanSep 21, 2019
edited
Loading

Choose a reason for hiding this comment

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

fixed in6f2dd64


error=None

ifnotre.search(r"\s",query.rstrip()):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also write this down in a comment, i.e. that anything without whitespace is assumed to be table identifier which triggers a different use case of the magic command.

max_results=None

ifnotre.search(r"\s",query.rstrip()):
table_id=query.rstrip()
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, stripping whitespace from the same value again is not necessary, we could store the stripped string into a variable the first time we do it.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fixed ind663104

Copy link
Contributor

@plamutplamut left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

It might cause a merge conflict with#9245, but I'll address that there.

@plamutplamut merged commitee0f70a intogoogleapis:masterSep 23, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@crwilcoxcrwilcoxAwaiting requested review from crwilcox

1 more reviewer

@plamutplamutplamut 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.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@shubha-rajan@crwilcox@plamut@googlebot

[8]ページ先頭

©2009-2025 Movatter.jp