LoginSignup
4
1

More than 5 years have passed since last update.

Embulk 0.8.9で追加されたdateオプション

Posted at

まとめ

  • Embulk 0.8.9から、時刻のみのカラムに日付を指定できるようになった。
  • デフォルトの日付を指定するときは、default_date
  • カラム毎に指定するには、date
  • タイムゾーン指定を忘れずに

サンプルデータ

次のようなデータがある、3番目のカラムは19:23:49のような時刻形式

id,account,time,comment
1,32864,19:23:49,embulk
2,14824,19:01:23,embulk jruby
3,27559,02:20:02,"Embulk ""csv"" parser plugin"
4,11270,11:54:36,NULL

default_date, dateを使わない場合

  parser:
    charset: UTF-8
    newline: CRLF
    type: csv
    delimiter: ','
    quote: '"'
    escape: '"'
    null_string: 'NULL'
    trim_if_not_quoted: false
    skip_header_lines: 1
    allow_extra_columns: false
    allow_optional_columns: false
    columns:
    - {name: id, type: long}
    - {name: account, type: long}
    - {name: time, type: timestamp, format: "%H:%M:%S" }
    - {name: comment, type: string}
*************************** 1 ***************************
     id (     long) : 1
account (     long) : 32,864
   time (timestamp) : 1970-01-01 19:23:49 UTC
comment (   string) : embulk

日付は、1970/1/1になる。

default_dateを使う場合

  parser:
    charset: UTF-8
    newline: CRLF
    type: csv
    delimiter: ','
    quote: '"'
    escape: '"'
    null_string: 'NULL'
    trim_if_not_quoted: false
    skip_header_lines: 1
    allow_extra_columns: false
    allow_optional_columns: false 
    default_date: "2016-07-22" # 追加
    default_timezone: "Asia/Tokyo" # 追加
    columns:
    - {name: id, type: long}
    - {name: account, type: long}
    - {name: time, type: timestamp, format: "%H:%M:%S" }
    - {name: comment, type: string}

previewすると、最初の日付が、2016/07/22 10:23:49(UTC)になっていることが確認できた。(日本時間は9時間先になる)

*************************** 1 ***************************
     id (     long) : 1
account (     long) : 32,864
   time (timestamp) : 2016-07-22 10:23:49 UTC
comment (   string) : embulk

個別に指定する場合は、date

  parser:
    charset: UTF-8
    newline: CRLF
    type: csv
    delimiter: ','
    quote: '"'
    escape: '"'
    null_string: 'NULL'
    trim_if_not_quoted: false
    skip_header_lines: 1
    allow_extra_columns: false
    allow_optional_columns: false
    default_timezone: "Asia/Tokyo"
    columns:
    - {name: id, type: long}
    - {name: account, type: long}
    - {name: time, type: timestamp, format: "%H:%M:%S", date: "2016-07-22" }
    - {name: comment, type: string}

余談

Embulk 0.8.10が出た日にこの記事を書いたのは、いままでこのプションの存在を知らなかったからだ。:smile:

4
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
4
1