[
https://issues.apache.org/jira/browse/BEAM-6892?focusedWorklogId=218368&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-218368
]
ASF GitHub Bot logged work on BEAM-6892:
----------------------------------------
Author: ASF GitHub Bot
Created on: 26/Mar/19 00:16
Start Date: 26/Mar/19 00:16
Worklog Time Spent: 10m
Work Description: udim commented on pull request #8135: [BEAM-6892]
Adding support for auto-creating buckets for BigQuery file loads
URL: https://github.com/apache/beam/pull/8135#discussion_r268895938
##########
File path: sdks/python/apache_beam/io/gcp/bigquery_file_loads.py
##########
@@ -490,9 +498,93 @@ def __init__(
# job to run - and thus we avoid using temporary tables
self.temp_tables = True if callable(destination) else False
+ self.kms_key = kms_key
+
+ self._validate = validate
+
+ def verify(self, options):
+
+ self._custom_gcs_temp_location = (
+ self._custom_gcs_temp_location
+ or options.view_as(GoogleCloudOptions).temp_location)
+
+ if (not self._custom_gcs_temp_location or
+ not self._custom_gcs_temp_location.startswith('gs://')):
+
+ logging.info('No appropriate location was provided to perform file loads'
+ 'to GCS.')
+ bucket = self.try_to_create_default_gcs_bucket(options)
+
+ if bucket:
+ self._custom_gcs_temp_location = 'gs://%s/temp/' % bucket.name
+ return
+
+ raise ValueError('Invalid GCS location.\n'
+ 'Writing to BigQuery with FILE_LOADS method requires a '
+ 'GCS location to be provided to write files to be '
+ 'loaded into BigQuery. Please provide a GCS bucket, or '
+ 'pass method="STREAMING_INSERTS" to WriteToBigQuery.')
+
+ def try_to_create_default_gcs_bucket(self, options):
+ DEFAULT_BUCKET_NAME = "dataflow-staging-%s-%s"
+ DEFAULT_REGION = "US"
+ logging.info('Attempting to get or create a default GCS bucket.')
+
+ project_name = options.view_as(GoogleCloudOptions).project
+
+ if not project_name and isinstance(self.destination,
+ bigquery_api.TableReference):
+ project_name = self.destination.projectId
+
+ region = options.view_as(GoogleCloudOptions).region
+
+ if not project_name:
+ raise ValueError('--project is a required option.'
+ ' To create a default bucket, Beam needs a project '
+ 'parameter passed to your pipeline.')
+
+ # Retrieve the project number for the default bucket
+ from google.cloud import resource_manager
+ client = resource_manager.Client()
+ project_number = client.fetch_project(project_name).number
+
+ # We get the region, and cut off the zone id if there is one.
+ region = (region or DEFAULT_REGION).split('-')[0].lower()
+
+ bucket_name = DEFAULT_BUCKET_NAME % (region, project_number)
+
+ gcs = gcsio.GcsIO()
+ bucket = gcs.get_bucket(bucket_name)
+
+ if not bucket:
+ logging.warn(
Review comment:
I think this should be an info-level message, if it's part of normal flow.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 218368)
Time Spent: 0.5h (was: 20m)
> Use temp_location for BQ FILE_LOADS on DirectRunner, and autocreate it in GCS
> if not specified by user.
> -------------------------------------------------------------------------------------------------------
>
> Key: BEAM-6892
> URL: https://issues.apache.org/jira/browse/BEAM-6892
> Project: Beam
> Issue Type: Bug
> Components: sdk-py-core
> Reporter: Valentyn Tymofieiev
> Assignee: Pablo Estrada
> Priority: Blocker
> Fix For: 2.12.0
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)