Skip to content

Instantly share code, notes, and snippets.

@hiroyuki-sato
Last active November 20, 2015 12:24
embulk-filter-split example

embulk-fiter-splitは、指定したカラムの区切り文字でデータを区切り複数行に変換するためのプラグイン @toyama0919さん作成

設定例

in:
  type: file
  path_prefix: sample.txt
  parser: 
    type: jsonl
    schema:
    - {name: keywords, type: string}
## ここがフィルタの設定
filters:
  - type: split
    delimiter: ','       # 区切り文字
    keep_input: false    # 入力カラムを出力するかどうか
    target_key: keywords # 入力のカラム名
    output_key: keyword  # 出力のカラム名
out:
  type: stdout

サンプルデータ

sample.txt

{ "keywords" : "Ruby,Java,Python" }

実行例1

入力カラムを出力する場合

filters:
  - type: split
    delimiter: ','       # 区切り文字
    keep_input: true     # 入力カラムを出力するかどうか
    target_key: keywords # 入力のカラム名
    output_key: keyword  # 出力のカラム名

実行結果

+------------------+----------------+
|  keywords:string | keyword:string |
+------------------+----------------+
| Ruby,Java,Python |           Ruby |
| Ruby,Java,Python |           Java |
| Ruby,Java,Python |         Python |
+------------------+----------------+

例2

filters:
  - type: split
    delimiter: ','       # 区切り文字
    keep_input: false    # 入力カラムを出力するかどうか
    target_key: keywords # 入力のカラム名
    output_key: keyword  # 出力のカラム名
+----------------+
| keyword:string |
+----------------+
|           Ruby |
|           Java |
|         Python |
+----------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment