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

Appearance settings

Added doc strings to functions with ambiguous args #44

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

Merged
merged 2 commits into from
Jun 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 13 bigquery/samples/export_data_to_cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
def export_table(service, cloud_storage_path,
projectId, datasetId, tableId,
num_retries=5):
"""
Starts an export job

Args:
service: initialized and authorized bigquery
google-api-client object,
cloud_storage_path: fully qualified
path to a Google Cloud Storage location,
e.g. gs://mybucket/myfolder/

Returns: an extract job resource representing the
job, see https://cloud.google.com/bigquery/docs/reference/v2/jobs
"""
# Generate a unique job_id so retries
# don't accidentally duplicate export
job_data = {
Expand Down
12 changes: 12 additions & 0 deletions 12 bigquery/samples/load_data_by_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@

# [START make_post]
def make_post(http, schema, data, projectId, datasetId, tableId):
"""
Creates an http POST request for loading data into
a bigquery table

Args:
http: an authorized httplib2 client,
schema: a valid bigquery schema,
see https://cloud.google.com/bigquery/docs/reference/v2/tables,
data: valid JSON to insert into the table

Returns: an http.request object
"""
url = ('https://www.googleapis.com/upload/bigquery/v2/projects/' +
projectId + '/jobs')
# Create the body of the request, separated by a boundary of xxx
Expand Down
15 changes: 15 additions & 0 deletions 15 bigquery/samples/load_data_from_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
# [START load_table]
def load_table(service, source_schema, source_csv,
projectId, datasetId, tableId, num_retries=5):
"""
Starts a job to load a bigquery table from CSV

Args:
service: an initialized and authorized bigquery
google-api-client object
source_schema: a valid bigquery schema,
see https://cloud.google.com/bigquery/docs/reference/v2/tables
source_csv: the fully qualified Google Cloud Storage location of
the data to load into your table

Returns: a bigquery load job, see
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load
"""

# Generate a unique job_id so retries
# don't accidentally duplicate query
job_data = {
Expand Down
7 changes: 7 additions & 0 deletions 7 bigquery/samples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

# [START get_service]
def get_service():
"""returns an initialized and authorized bigquery client"""

from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped(
Expand All @@ -27,6 +30,8 @@ def get_service():

# [START poll_job]
def poll_job(service, projectId, jobId, interval=5, num_retries=5):
"""checks the status of a job every *interval* seconds"""

import time

job_get = service.jobs().get(projectId=projectId, jobId=jobId)
Expand All @@ -44,6 +49,8 @@ def poll_job(service, projectId, jobId, interval=5, num_retries=5):

# [START paging]
def paging(service, request_func, num_retries=5, **kwargs):
"""pages though the results of an asynchronous job"""

has_next = True
while has_next:
response = request_func(**kwargs).execute(num_retries=num_retries)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.