LoginSignup
4
3

More than 5 years have passed since last update.

Embulkでinformixのデータをcsvゲット

Last updated at Posted at 2016-02-02

Talend Open Studioの英語のマニュアルもまともに読めないヘタレです。
embulkに浮気します。

僕のデータ取得の用途だとTalendよりも簡単に出来そうに思えたので。

embulkがこのCultなDB Informixでも使えるのか?
csvで吐き出せるのかでテストしてみたいと思います。

やりたいことの図

informix -> embulk -> csv

環境

  • Windows 7 SP1 (x64)
  • Java SE 1.8.0.65
  • embulk v0.8.1

手順

embulkをゲット
#PowerShellの画面
PS1> Invoke-WebRequest http://dl.embulk.org/embulk-latest.jar -OutFile embulk.bat
jdbcのpluginをインストール
#コマンドプロンプト上
embulk.bat gem install embulk-input-jdbc
seed.ymlを作る
atom seed.yml
seed.ymlの中身

in:
        type: jdbc
        driver_path: C:\Program Files\IBM\Informix_JDBC_Driver\lib\ifxjdbc.jar
        driver_class: com.informix.jdbc.IfxDriver
        url: jdbc:informix-sqli://192.168.0.1:1526/mydb:INFORMIXSERVER=myserver;DB_locale=ja_JP.932;NEWCODESET=MS932,sjis-s,932;
        user: username
        password: password
        table: tables
out:
        type: file
        path_prefix: C:\Users\yusuke\tables.csv
        file_ext: csv
        formatter:
                type: csv
                header_line: true
                charset: UTF-8
                newline: CRLF

guessを実行
> embulk.bat guess seed.yml -o guess.yml
2016-02-02 13:53:58.973 +0900 [INFO] (guess): Loaded plugin embulk-input-jdbc (0
.6.4)
in: {type: jdbc, driver_path: 'C:\Program Files\IBM\Informix_JDBC_Driver\lib\ifx
jdbc.jar',
...(省略)...

guess.ymlの中身
in: {type: jdbc, driver_path: 'C:\Program Files\IBM\Informix_JDBC_Driver\lib\ifxjdbc.jar',
  driver_class: com.informix.jdbc.IfxDriver, url: 'jdbc:informix-sqli://192.168.0.1:1526/mydb:INFORMIXSERVER=myserver;DB_locale=ja_JP.932;NEWCODESET=MS932,sjis-s,932;',
  user: username, password: password, table: tables}
out:
  type: file
  path_prefix: C:\Users\yusuke\tables.csv
  file_ext: csv
  formatter: {type: csv, header_line: true, charset: UTF-8, newline: CRLF}

エラーが出なければまずは実行してみましょう。

runを実行
> embulk.bat run guess.yml
2016-02-02 13:54:31.030 +0900 [INFO] (transaction): Loaded plugin embulk-input-j
dbc (0.6.4)
2016-02-02 13:54:31.174 +0900 [INFO] (transaction): SQL: SELECT * FROM  tables
...(以下略)

何故か、8つのcsvファイルが出力されます。
tables.csv.000.00.csvはちゃんと全てのデータが出力されています。

@hiroysato さんから exec: min_output_tasks: 1 加えると、
1つのファイルに出力できるという情報頂きました。
ありがとうございます。

1つのcsvファイルで出力するseed.yml
exec:
  min_output_tasks: 1

in:
        type: jdbc
        driver_path: C:\Program Files\IBM\Informix_JDBC_Driver\lib\ifxjdbc.jar
        driver_class: com.informix.jdbc.IfxDriver
        url: jdbc:informix-sqli://192.168.0.1:1526/mydb:INFORMIXSERVER=myserver;DB_locale=ja_JP.932;NEWCODESET=MS932,sjis-s,932;
        user: username
        password: password
        table: tables
out:
        type: file
        path_prefix: C:\Users\yusuke\tables.csv
        file_ext: csv
        formatter:
                type: csv
                header_line: true
                charset: UTF-8
                newline: CRLF

これを食わせて実行すると1つのcsvファイルになります。

runを実行
> embulk.bat run guess.yml
2016-02-02 13:54:31.030 +0900 [INFO] (transaction): Loaded plugin embulk-input-j
dbc (0.6.4)
2016-02-02 13:54:31.174 +0900 [INFO] (transaction): SQL: SELECT * FROM  tables
...(以下略)

使えるね。

参考文献

データ転送のOSS「Embulk」を使って、MysqlからデータをCsvに落としてみる
csvの出力を参考にさせてもらいました。
embulk-input-jdbc - github
input-jdbcでのデータを取得するときのymlファイルの書き方

4
3
2

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
3