2
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.

Treasure Data CDP から Azure Blob StorageにWorkflowを使用してデータをエクスポートする。

Posted at

Treasure Data CDP とは

Customer Data Platformというジャンル(?)のデータ分析基盤です。
顧客視点での分析ができる様々な機能も魅力ですが、豊富なコネクタを兼ね備えており、柔軟なアーキテクチャを構成することができます。

Azure Blob Storageにデータを連携する

データをBlobにおいておけば、Power BIでの可視化・分析、Azure MLでの機械学習など、さらに様々なシナリオを実現することができます。

実践

コネクタ構成をする

  1. Integrations HubCatalogからMicrosoft Azureをクリック
  2. Blob に必要な情報を入力(画像参照)

image.png

image.png

ここまでやると、Integrations HubAuthenticationsMicrosoft Azureができます。

image.png

Authenticationsは一度つくっておくと、インポート/エクスポート先の接続文字列を共有せずに、組織内のデータソースなどへの接続権限管理ができるようになります。

Workflowの作成をする

Authenticationsを作成したら、次はWorkflowの作成です。

次はData Workbench内のWorkflowsをクリック。右上のNew Workflowを押してWorkflows作成を開始します。

image.png

image.png

エクスポート用の書き方は、Treasure Data CDPのベストプラクティスがつまっているGitHub、「Treasure Boxes」を参照します。

今回は下記URLにAzure Blob Storageの記述例があるので、これをもとにいじっていきます。
事前にAzure側でContainerを作成しておきましょう。

_export:
  td:
    database: <your_database>

+export_to_azure:
  td>:
  query: select * from <your_table>
  result_connection: <your_Authentications_name>
  result_settings: 
    container: testtd
    path_prefix: /file_${moment(session_time).format("YYYYMMDD")}
    file_ext: csv.gz
    format: csv
    delimiter: ","
    null_string: ""
    newline: CRLF

これで最低限のものが作成できました。
フォルダパス及びファイル名はTreasure Data CDPに組み込まれているmoment.jsを使用して、実行時の日付がファイル名になるようになっています。

実行結果

Azure Blob StorageにFileがエクスポートされているのが確認できました。

image.png

今後の方針

  • 定期実行をcronでコントロールする。
  • Queryを直書きではなく、別ファイルに分けて管理。
  • 1つのワークフローで複数のデータベースをエクスポートするようにしたい。

おわりに

触ってみるのが一番理解が進みますよね。教科書ばかり読んでもできるようにはならないね🤔

2
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
2
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?