LoginSignup
3
1

More than 5 years have passed since last update.

Treasure Workflow(Digdag)で SQL クエリに変数を使う

Last updated at Posted at 2019-01-29

Treasure Workflow で SQL に変数を使いたい場合のメモです。

手元の環境は以下になります。

  • Ubuntu 18.04 LTS
  • td-agent 1.3.3

まず、以下のように .dig ファイルで変数を設定します。

timezone: Asia/Tokyo

_export:
  # 先月の月初から月末まで
  start_date: ${moment(session_time).subtract(1, 'months').startOf('month').format("YYYY-MM-DD 00:00:00")}
  end_date: ${moment(session_time).subtract(1, 'months').endOf('month').format("YYYY-MM-DD 23:59:59")}

クエリを実行する処理を .dig ファイルに追記します。

+task1:
  td>: queries/sample.sql
  create_table: sample_table

SQL ファイルの中で変数を呼び出します。

SELECT
  user_name,
  text
FROM
  review
WHERE
  create_datetime >= '${start_date}' AND
  create_datetime <= '${end_date}'
3
1
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
3
1