概要
任意の列を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以外では動きません。
- Java7以前ではapache commons codecのbase64が使えるそうなので、そちらもサポートしたいと思っています。
- 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結果も違うのでしょうか。。。文字コードについては不勉強なので、確認次第対応したいと思います。