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

Added doc strings to functions with ambiguous args #44

Merged
merged 2 commits into from
Jun 19, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions bigquery/samples/export_data_to_cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
def export_table(service, cloud_storage_path,
projectId, datasetId, tableId,
num_retries=5):
"""
service: initialized and authorized bigquery
Copy link
Contributor

Choose a reason for hiding this comment

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

Something like this instead:

"""Exports a table from bigquery.

Arguments: (or Args:)
    service: ..
    cloud_storage_path: ...

Returns: A x instance representing..

"""

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
7 changes: 7 additions & 0 deletions bigquery/samples/load_data_by_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

# [START make_post]
def make_post(http, schema, data, projectId, datasetId, tableId):
"""
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
11 changes: 11 additions & 0 deletions bigquery/samples/load_data_from_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
# [START load_table]
def load_table(service, source_schema, source_csv,
projectId, datasetId, tableId, num_retries=5):
"""
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 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