Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow cell magic body to be a $variable #1053

Merged
merged 8 commits into from
Nov 16, 2021
Merged

Conversation

plamut
Copy link
Contributor

@plamut plamut commented Nov 8, 2021

Closes #1040.

Thought - we probably want to follow up with a sample demonstrating this new use case.

Also, the length of the _cell_magic() function should be ignored for now, it's been waiting to be split into smaller units since forever. 🙂

PR checklist:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@plamut plamut requested review from loferris and a team November 8, 2021 19:45
@plamut plamut requested a review from a team as a code owner November 8, 2021 19:45
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 8, 2021
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Nov 8, 2021
google/cloud/bigquery/magics/magics.py Outdated Show resolved Hide resolved
google/cloud/bigquery/magics/magics.py Outdated Show resolved Hide resolved
@google-cla
Copy link

google-cla bot commented Nov 8, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Nov 8, 2021
@tseaver
Copy link
Contributor

tseaver commented Nov 8, 2021

@googlebot I consent.

@google-cla
Copy link

google-cla bot commented Nov 8, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@tseaver
Copy link
Contributor

tseaver commented Nov 8, 2021

@plamut Sorry, I tried. :-<

@plamut
Copy link
Contributor Author

plamut commented Nov 8, 2021

OK, I'll edit the commit message then to silence the bot.

@google-cla google-cla bot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Nov 8, 2021
cell_body = "$custom_query"

with pytest.raises(
NameError, match=r".*custom_query does not exist.*"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe comment to indicate we're testing the first kind of error, as I got the regex string match from context of the other file.

Copy link
Contributor Author

@plamut plamut Nov 10, 2021

Choose a reason for hiding this comment

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

The name of the test explains which case it covers ("non-existing query variable"), do you think that's not sufficient by itself?

I always look at the name of the test first, although it might be just how my brain is wired...

Update: Added a comment next to the assignment to cell_body to explain which use case it targets.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM - I really like how you added the "non-existing query variable" condition.

Copy link
Contributor

@loferris loferris left a comment

Choose a reason for hiding this comment

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

LGTM - could do with more comments on test cases, perhaps.

cell_body = "$custom_query"

with pytest.raises(
TypeError, match=r".*must be a string or a bytes-like.*"
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to have another comment here to match it to the other else condition in run_query_magic

tests/unit/test_magics.py Outdated Show resolved Hide resolved
@plamut plamut added the automerge Merge the pull request once unit tests and other checks pass. label Nov 11, 2021
@plamut plamut removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 11, 2021
@plamut plamut requested a review from loferris November 11, 2021 10:17
@loferris
Copy link
Contributor

LGTM - appreciate the changes!!

@plamut plamut merged commit 3a681e0 into googleapis:main Nov 16, 2021
@plamut plamut deleted the iss-1040 branch November 16, 2021 21:57
abdelmegahedgoogle pushed a commit to abdelmegahedgoogle/python-bigquery that referenced this pull request Apr 17, 2023
* feat: allow cell magic body to be a $variable

* Fix missing indefinitive article in error msg

* Adjust test assertion to error message change

* Refactor logic for extracting query variable

* Explicitly warn about missing query variable name

* Thest the query "variable" is not identifier case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow the body of %%bigquery cell magic to be a $variable
3 participants