-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
refactor(bigquery): update code samples of load table file and uri #10175
Merged
plamut
merged 4 commits into
googleapis:master
from
MaxxleLLC:bigquery_update_load_table_code_sample
Feb 3, 2020
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
22e0dd9
refactor(bigquery): update code samples of load table file and uri
HemangChothani ce86acb
refactor(bigquery): add uri for load orc and avro data
HemangChothani 5ee7a04
refactor(bigquery): fix lint and docs
HemangChothani af92114
refactor(bigquery): update copyright to 2020
HemangChothani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
refactor(bigquery): update code samples of load table file and uri
- Loading branch information
commit 22e0dd9627569024e485cc2b988aca7a74a339f4
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ Create an integer range partitioned table with the | |
Load table data from a file with the | ||
:func:`~google.cloud.bigquery.client.Client.load_table_from_file` method: | ||
|
||
.. literalinclude:: ../snippets.py | ||
.. literalinclude:: ../samples/load_table_file.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_load_from_file] | ||
|
@@ -79,7 +79,7 @@ Load table data from a file with the | |
Load a CSV file from Cloud Storage with the | ||
:func:`~google.cloud.bigquery.client.Client.load_table_from_uri` method: | ||
|
||
.. literalinclude:: ../snippets.py | ||
.. literalinclude:: ../samples/load_table_uri_csv.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_load_table_gcs_csv] | ||
|
@@ -90,7 +90,7 @@ See also: `Loading CSV data from Cloud Storage | |
|
||
Load a JSON file from Cloud Storage: | ||
|
||
.. literalinclude:: ../snippets.py | ||
.. literalinclude:: ../samples/load_table_uri_json.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_load_table_gcs_json] | ||
|
@@ -101,7 +101,7 @@ See also: `Loading JSON data from Cloud Storage | |
|
||
Load a Parquet file from Cloud Storage: | ||
|
||
.. literalinclude:: ../snippets.py | ||
.. literalinclude:: ../samples/load_table_uri_parquet.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_load_table_gcs_parquet] | ||
|
@@ -110,6 +110,22 @@ Load a Parquet file from Cloud Storage: | |
See also: `Loading Parquet data from Cloud Storage | ||
<https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-parquet>`_. | ||
|
||
Load a Avro file from Cloud Storage: | ||
|
||
.. literalinclude:: ../samples/load_table_uri_avro.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_load_table_gcs_avro] | ||
:end-before: [END bigquery_load_table_gcs_avro] | ||
|
||
Load a ORC file from Cloud Storage: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/a Orc/an Orc/ |
||
|
||
.. literalinclude:: ../samples/load_table_uri_orc.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_load_table_gcs_orc] | ||
:end-before: [END bigquery_load_table_gcs_orc] | ||
|
||
Updating a Table | ||
^^^^^^^^^^^^^^^^ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2019 Google LLC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update copyright notices to 2020 in the new files |
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
def load_table_file(file_path, table_id): | ||
|
||
# [START bigquery_load_from_file] | ||
from google.cloud import bigquery | ||
|
||
# Construct a BigQuery client object. | ||
client = bigquery.Client() | ||
|
||
# TODO(developer): Set table_id to the ID of the table to create. | ||
# table_id = "your-project.your_dataset.your_table_name" | ||
|
||
job_config = bigquery.LoadJobConfig( | ||
source_format=bigquery.SourceFormat.CSV, skip_leading_rows=1, autodetect=True, | ||
) | ||
|
||
with open(file_path, "rb") as source_file: | ||
job = client.load_table_from_file(source_file, table_id, job_config=job_config) | ||
|
||
job.result() # Waits for the job to complete. | ||
|
||
table = client.get_table(table_id) # Make an API request. | ||
print( | ||
"Loaded {} rows and {} columns to {}".format( | ||
table.num_rows, len(table.schema), table_id | ||
) | ||
) | ||
# [END bigquery_load_from_file] | ||
return table |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/a Avro/an Avro/