LoginSignup
1
1

More than 5 years have passed since last update.

embulk-filter-base64 を書いた

Posted at

概要

任意の列をbase64でencode/decodeするembulkのfilter pluginを書きました。

使い方

filters:
  - type: base64
    columns:
      - {name: string to decode, decode: true}
      - {name: string to encode, encode: true}

encode: trueとすると入力カラムをencodeし、decode: trueとするとdecodeします。

詳しくはREADMEを参照してください。

example.yml
in:
  type: file
  path_prefix: ./example.csv
  parser:
    type: csv
    columns:
      - {name: id, type: long}
      - {name: column to encode, type: string}
      - {name: column to decode, type: string}
filters:
  - type: base64
    columns:
      - {name: column to encode, encode: true}
      - {name: column to decode, decode: true}
out:
  type: stdout
example.csv
100,1234,MTIzNA==
101,4567,NDU2Nw==
$ embulk run example.yml
2016-11-19 17:57:34.247 +0900: Embulk v0.8.15
2016-11-19 17:57:39.937 +0900 [INFO] (0001:transaction): Loaded plugin embulk-filter-base64 (0.1.0)
2016-11-19 17:57:39.999 +0900 [INFO] (0001:transaction): Listing local files at directory '.' filtering filename by prefix 'example.csv'
2016-11-19 17:57:40.018 +0900 [INFO] (0001:transaction): Loading files [example.csv]
2016-11-19 17:57:40.152 +0900 [INFO] (0001:transaction): Using local thread executor with max_threads=8 / output tasks 4 = input tasks 1 * 4
2016-11-19 17:57:40.167 +0900 [INFO] (0001:transaction): {done:  0 / 1, running: 0}
100,MTIzNA==,1234
101,NDU2Nw==,4567
2016-11-19 17:57:40.292 +0900 [INFO] (0001:transaction): {done:  1 / 1, running: 0}
2016-11-19 17:57:40.301 +0900 [INFO] (main): Committed.
2016-11-19 17:57:40.301 +0900 [INFO] (main): Next config diff: {"in":{"last_path":"example.csv"},"out":{}}

こちらも詳しくはREADMEを参照してください。

注意点

  • Java8のjava.util.Base64を使用しているため、Java8以外では動きません。
  • encodeするカラムの型はstringである必要があります。
    • encodeした文字列を同じカラムの値として置き換えるためです。
    • e.g. 1234(input) -> MTIzNA==(output) のように、inputの1234はlongではなくstringで渡してください。
  • decodeした後の値はstringのままになります。
    • このプラグインでは型変換は対応していません。
    • e.g. MTIzNA==(input) -> 1234(output) のように、outputの1234はlongではなくstringになります。
    • 型変換させたい場合はembulk-filter-typecastを使用してください。
  • 文字コードは特に考慮していません。
    • 同じ文字列でも文字コードが違えばencode結果も違うのでしょうか。。。文字コードについては不勉強なので、確認次第対応したいと思います。
1
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
1
1