forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(bigquery): add create job method #81
Draft
HemangChothani
wants to merge
5
commits into
master
Choose a base branch
from
bigquery_add_create_job_method
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+177
−1
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
583ad56
feat(bigquery): add create job method
HemangChothani 28dbb77
feat(bigquery): cosmetic change
HemangChothani d9e8015
feat(bigquery): remove the keyword arguments
HemangChothani 5e98027
Merge remote-tracking branch 'upstream/master' into bigquery_add_crea…
HemangChothani 11902fc
feat(bigquery): conflict resolved
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,6 @@ | |
from google.cloud.bigquery.table import TableReference | ||
from google.cloud.bigquery.table import RowIterator | ||
|
||
|
||
_DEFAULT_CHUNKSIZE = 1048576 # 1024 * 1024 B = 1 MB | ||
_MAX_MULTIPART_SIZE = 5 * 1024 * 1024 | ||
_DEFAULT_NUM_RETRIES = 6 | ||
|
@@ -1127,6 +1126,82 @@ def job_from_resource(self, resource): | |
return job.QueryJob.from_api_repr(resource, self) | ||
return job.UnknownJob.from_api_repr(resource, self) | ||
|
||
def create_job( | ||
self, job_config, source=None, destination=None, query=None, retry=DEFAULT_RETRY | ||
): | ||
"""Create a new job. | ||
Arguments: | ||
job_config (dict): configuration job representation returned from the API | ||
|
||
Keyword Arguments: | ||
source (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
str, \ | ||
Sequence[str] | ||
]): | ||
(Optional) URIs of data files to be loaded; in format | ||
``gs://<bucket_name>/<object_name_or_glob>`` or Table | ||
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. Cosmetics: extra |
||
into which data is to be loaded. | ||
|
||
destination (Union[ \ | ||
google.cloud.bigquery.table.Table, \ | ||
google.cloud.bigquery.table.TableReference, \ | ||
str, \ | ||
]): | ||
(Optional) Table into which data is to be loaded. If a string is passed | ||
in, this method attempts to create a table reference from a string using | ||
:func:`google.cloud.bigquery.table.TableReference.from_string` or URIs of | ||
Cloud Storage file(s) into which table data is to be extracted; in format | ||
``gs://<bucket_name>/<object_name_or_glob>``. | ||
|
||
query (str): | ||
(Optional) SQL query to be executed. Defaults to the standard SQL dialect. | ||
Use the ``job_config`` parameter to change dialects. | ||
|
||
retry (google.api_core.retry.Retry): | ||
(Optional) How to retry the RPC. | ||
|
||
Returns: | ||
Union[ \ | ||
google.cloud.bigquery.job.LoadJob, \ | ||
google.cloud.bigquery.job.CopyJob, \ | ||
google.cloud.bigquery.job.ExtractJob, \ | ||
google.cloud.bigquery.job.QueryJob \ | ||
]: | ||
A new job instance. | ||
""" | ||
|
||
if "load" in job_config: | ||
job_config = google.cloud.bigquery.job.LoadJobConfig.from_api_repr( | ||
job_config | ||
) | ||
return self.load_table_from_uri( | ||
source, destination, job_config=job_config, retry=retry | ||
) | ||
elif "copy" in job_config: | ||
job_config = google.cloud.bigquery.job.CopyJobConfig.from_api_repr( | ||
job_config | ||
) | ||
return self.copy_table( | ||
source, destination, job_config=job_config, retry=retry | ||
) | ||
elif "extract" in job_config: | ||
job_config = google.cloud.bigquery.job.ExtractJobConfig.from_api_repr( | ||
job_config | ||
) | ||
return self.extract_table( | ||
source, destination, job_config=job_config, retry=retry | ||
) | ||
elif "query" in job_config: | ||
del job_config["query"]["destinationTable"] | ||
job_config = google.cloud.bigquery.job.QueryJobConfig.from_api_repr( | ||
job_config | ||
) | ||
return self.query(query, job_config=job_config, retry=retry) | ||
else: | ||
raise TypeError("Invalid job configuration received.") | ||
|
||
def get_job(self, job_id, project=None, location=None, retry=DEFAULT_RETRY): | ||
"""Fetch a job for the project associated with this client. | ||
|
||
|
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
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.
Cosmetics: the line should end with a dot.