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

BigQuery: added methods for getting keys, items and dict #4393

Merged
merged 15 commits into from
Nov 17, 2017

Conversation

josefbarta
Copy link
Contributor

This change enables to retrieve the row as a dict and iterate the keys and/or items, like with a normal dict; in other words, making the Row object a dict-like object:

row.dict()
{'name': 'Isabel', 'profession': 'bridge builder'}
for k, v in row.items():
for k in row.keys():

This change enables to retrieve the row as a dict and iterate the keys and/or items, like with a normal dict; in other words, making the Row object a dict-like object:

>>> row.dict()
{'name': 'Isabel', 'profession': 'bridge builder'}
>>> for k, v in row.items():
>>> for k in row.keys():
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Nov 14, 2017
@josefbarta
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot 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 14, 2017
@dhermes
Copy link
Contributor

dhermes commented Nov 14, 2017

I'd like to do a thorough review of the code (e.g. keys() and items() could be generators) but want to wait until @tswast comments on whether or not these features are desired.

@josefbarta
Copy link
Contributor Author

I see, good point about the generators, thanks. I'd fix that but will hold off until we know more about whether these are desirable at all. The thing is that it would be great to be able to either return the row as a dict or convert it to a dict really easily, which currently is a bit of a hacky process. Thanks!

@josefbarta
Copy link
Contributor Author

I fixed it after all; the tests seem to have run successfully :-)

@chemelnucfin chemelnucfin changed the title added methods for getting keys, items and dict BigQuery: added methods for getting keys, items and dict Nov 14, 2017
@chemelnucfin chemelnucfin added the api: bigquery Issues related to the BigQuery API. label Nov 14, 2017
@tseaver tseaver requested a review from tswast November 15, 2017 20:42
@tswast
Copy link
Contributor

tswast commented Nov 15, 2017

I like keys() and items() to make Row act even more like a dictionary. That part LGTM.

What is your desired use for dict()? Are you using it to serialize the rows?

@josefbarta
Copy link
Contributor Author

I'm using dict() to serialise rows into a standard dict, which I can then convert to json. As long as keys() and/or items() makes it in, I'm happy not to have dict(), simply because I can do it in my own code. Alternatively, I'm happy to write a get() method for Row instead, so it's possible to get a value in a dict-standard failsafe way. Thanks!

@tswast
Copy link
Contributor

tswast commented Nov 16, 2017

As long as keys() and/or items() makes it in, I'm happy not to have dict().

Yeah, I'd prefer not to have dict() since it's not a standard method and it's easy enough for someone to make their own dictionary now that there is keys() and items().

Alternatively, I'm happy to write a get() method for Row instead, so it's possible to get a value in a dict-standard failsafe way. Thanks!

Ooh, yes please to adding the get() method. That sounds great.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). 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 have the pull request author add another comment and the bot will run again.

@googlebot googlebot 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 17, 2017
@josefbarta
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot 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 17, 2017
@josefbarta
Copy link
Contributor Author

So dict() is now removed and get() is in place, including code checks and the tests for the module check out (not yet completed for the whole hog but that should be fine). Please let me know if there are any issues with my code I should fix. Thanks!

''
"""
index = self._xxx_field_to_index.get(key)
if index is None:

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

@tswast tswast merged commit e89ab7e into googleapis:master Nov 17, 2017
@josefbarta
Copy link
Contributor Author

Thanks :-)

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

6 participants