Skip to content

Commit

Permalink
bigquery: modify LoadJob (#4103)
Browse files Browse the repository at this point in the history
This PR handles loading from GCS. Loading from a local
file will be done separately.
  • Loading branch information
jba authored Oct 4, 2017
1 parent e028c38 commit 01fc4f4
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 370 deletions.
2 changes: 2 additions & 0 deletions bigquery/google/cloud/bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from google.cloud.bigquery.job import CopyJobConfig
from google.cloud.bigquery.job import ExtractJobConfig
from google.cloud.bigquery.job import QueryJobConfig
from google.cloud.bigquery.job import LoadJobConfig
from google.cloud.bigquery.schema import SchemaField
from google.cloud.bigquery.table import Table

Expand All @@ -47,6 +48,7 @@
'CopyJobConfig',
'ExtractJobConfig',
'QueryJobConfig',
'LoadJobConfig',
'ScalarQueryParameter',
'SchemaField',
'StructQueryParameter',
Expand Down
31 changes: 22 additions & 9 deletions bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import collections
import uuid

import six

from google.api.core import page_iterator
from google.cloud.client import ClientWithProject
from google.cloud.bigquery._http import Connection
Expand Down Expand Up @@ -490,26 +492,37 @@ def list_jobs(self, max_results=None, page_token=None, all_users=None,
max_results=max_results,
extra_params=extra_params)

def load_table_from_storage(self, job_id, destination, *source_uris):
"""Construct a job for loading data into a table from CloudStorage.
def load_table_from_storage(self, source_uris, destination,
job_id=None, job_config=None):
"""Starts a job for loading data into a table from CloudStorage.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load
:type job_id: str
:param job_id: Name of the job.
:type source_uris: One of:
str
sequence of string
:param source_uris: URIs of data files to be loaded; in format
``gs://<bucket_name>/<object_name_or_glob>``.
:type destination: :class:`google.cloud.bigquery.table.Table`
:type destination: :class:`google.cloud.bigquery.table.TableReference`
:param destination: Table into which data is to be loaded.
:type source_uris: sequence of string
:param source_uris: URIs of data files to be loaded; in format
``gs://<bucket_name>/<object_name_or_glob>``.
:type job_id: str
:param job_id: Name of the job.
:type job_config: :class:`google.cloud.bigquery.job.LoadJobConfig`
:param job_config: (Optional) Extra configuration options for the job.
:rtype: :class:`google.cloud.bigquery.job.LoadJob`
:returns: a new ``LoadJob`` instance
"""
return LoadJob(job_id, destination, source_uris, client=self)
job_id = _make_job_id(job_id)
if isinstance(source_uris, six.string_types):
source_uris = [source_uris]
job = LoadJob(job_id, source_uris, destination, self, job_config)
job.begin()
return job

def copy_table(self, sources, destination, job_id=None, job_config=None):
"""Start a job for copying one or more tables into another table.
Expand Down
Loading

0 comments on commit 01fc4f4

Please sign in to comment.