0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dataflow Workbench で CloudSQL のデータを BigQuery フェデレーションでみる

0
Posted at

Dataflow Workbench の起動

Google Cloud Console > Dataflow > Workbench

Screen Shot 2021-11-01 at 23.14.44.png

新しいノートブック > Apache Beam > Without GPUs をクリックして、設定はそのままに「作成」。
立ち上がったら、「JUPYTERLABを開く」をクリック。

コード

import apache_beam as beam
from apache_beam.runners.interactive.interactive_runner import InteractiveRunner
import apache_beam.runners.interactive.interactive_beam as ib
from apache_beam.options import pipeline_options
# from apache_beam.options.pipeline_options import GoogleCloudOptions
# import google.auth
from apache_beam.io import ReadFromBigQuery
ib.options.recording_duration = '1m'
options = pipeline_options.PipelineOptions(project='<project id>', temp_location='gs://<bucket name>/temp')

p = beam.Pipeline(InteractiveRunner(), options=options)
# need to grand BigQuery connection user paermission to Compute Engine default Service Account
query='SELECT * FROM EXTERNAL_QUERY("projects/<project id>/locations/us/connections/cloudesql-fed", "SELECT * FROM federation_test.item;");'
query_results = p | beam.io.ReadFromBigQuery(
    query=query, use_standard_sql=True)
ib.show(query_results, include_window_info=True)

結果

こんな風にみれる。CloudSQLのフェデレーションでもDataflowでデータ取れた。
Screen Shot 2021-11-01 at 23.22.00.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?