-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcs2bq_dataflow.py
More file actions
33 lines (28 loc) · 1.27 KB
/
Copy pathgcs2bq_dataflow.py
File metadata and controls
33 lines (28 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import apache_beam as beam
import argparse
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.io.gcp.internal.clients import bigquery
from sys import argv
options = beam.options.pipeline_options.PipelineOptions()
gcloud_options = options.view_as(
beam.options.pipeline_options.GoogleCloudOptions)
gcloud_options.job_name = 'jobname'
gcloud_options.project = 'project'
gcloud_options.region = 'us-central1'
gcloud_options.staging_location = 'gs://......'
gcloud_options.temp_location = 'gs://......'
worker_options = options.view_as(beam.options.pipeline_options.WorkerOptions)
worker_options.disk_size_gb = 25
worker_options.max_num_workers = 2
# worker_options.num_workers = 2
# worker_options.machine_type = 'n1-standard-8'
options.view_as(beam.options.pipeline_options.StandardOptions).runner = 'DataflowRunner'
p1 = beam.Pipeline(options=options)
# Read froM GCS and write to BigQuery
(p1 | 'read' >> beam.io.ReadFromText('gs://dataflow-samples/shakespeare/kinglear.txt')
| 'write1' >> beam.io.WriteToBigQuery(
'project:dataset.table', schema=table_schema,
create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED,
write_disposition=beam.io.BigQueryDisposition.WRITE_TRUNCATE)
)
p1.run() # .wait_until_finish()