Skip to content

feat(bigquery): add support for sheets ranges#9416

Merged
tswast merged 4 commits intogoogleapis:masterfrom
MaxxleLLC:iss-9082
Oct 8, 2019
Merged

feat(bigquery): add support for sheets ranges#9416
tswast merged 4 commits intogoogleapis:masterfrom
MaxxleLLC:iss-9082

Conversation

@emar-kar
Copy link
Contributor

@emar-kar emar-kar commented Oct 7, 2019

Closes: #9082

List of changes:

  • external_config
    • add range property;
  • test_external_config
    • add test to cover range
  • new samples
    • remove old ones from the snippets
    • new sample query_external_sheets_permanent_table + test
    • new sample query_external_sheets_temporary_table + test

@emar-kar emar-kar added the api: bigquery Issues related to the BigQuery API. label Oct 7, 2019
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 7, 2019
@emar-kar emar-kar added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 7, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 7, 2019
@emar-kar emar-kar requested a review from tswast October 7, 2019 09:20
@emar-kar emar-kar marked this pull request as ready for review October 7, 2019 09:20
@emar-kar emar-kar requested review from a team and removed request for a team October 7, 2019 09:20
# Use a shareable link or grant viewing access to the email address you
# used to authenticate with BigQuery (this example Sheet is public).
sheet_url = (
"https://docs.google.com/spreadsheets/"
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, let's continue using the previous sheet. https://docs.google.com/spreadsheets/d/1i_QCL-7HcSyUZmIbP9E6lO_T5u3HnpLe7dnpHaijg_E/edit?usp=sharing

I was thinking we'd want a different set of data for the range queries, but if we're still querying US States, we should just use the existing sheet.

external_config.source_uris = [sheet_url]
external_config.options.skip_leading_rows = 1 # Optionally skip header row.
external_config.options.range = (
"Sheet1!A10:B30"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a range that is more possible to verify the correct behavior. Since the original sheet is sorted alphabetically, the range A1:B48 should only get "Washington".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to use A20:B49 range. To show that it can be used not from the beginning of the sheet.


# Wait for the query to complete.
w_states = list(query_job)
print("There are {} states with names starting with W.".format(len(w_states)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's update the print statement to indicate that we used a range: ... starting with W in the selected range.

@emar-kar emar-kar added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Oct 8, 2019
@tswast tswast merged commit cf27795 into googleapis:master Oct 8, 2019
@emar-kar emar-kar deleted the iss-9082 branch October 8, 2019 23:28
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.

BigQuery: Add support for sheets ranges

4 participants