embulk-filter-base64 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/build.gradle +2 -1
- data/classpath/embulk-filter-base64-0.1.1.jar +0 -0
- data/src/main/java/org/embulk/filter/base64/Base64FilterPlugin.java +65 -149
- data/src/main/java/org/embulk/filter/base64/ColumnVisitorImpl.java +148 -0
- data/src/test/java/org/embulk/filter/base64/TestBase64FilterPlugin.java +87 -0
- data/src/test/java/org/embulk/filter/base64/TestColumnVisitorImpl.java +93 -0
- metadata +5 -3
- data/classpath/embulk-filter-base64-0.1.0.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 920673effb3067f179e366a12a6b1ea760a9c199
|
4
|
+
data.tar.gz: a77a241890b994b2fabc95d1ae175f314f70f6ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85586eecb14aeba081c8706353c393c11d7b3592b1ef3d3f3a5a90bcd8bce8268adaad14c044c35cab95a2da1c94eb6ebdadfb899ffcb2d982a7e287ef635e80
|
7
|
+
data.tar.gz: db625af1af9e2ba4a3b4f38de4c23d5f1f48276be36b45b89edd0408b6eb7cc69f7f88f699edc96f373baa66ec06a0bc283f23cb9fd36b53fa8832bc67e31d3c
|
data/README.md
CHANGED
@@ -17,6 +17,7 @@ An Embulk filter plugin to encode/decode string by Base64.
|
|
17
17
|
|
18
18
|
## Limitation
|
19
19
|
|
20
|
+
* Java8 environment is needed because this plugin uses [java.util.Base64](https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html) of Java8
|
20
21
|
* Type of input value to be encoded must be string.
|
21
22
|
- encoded value is string and is is needed to align the type of input and output value
|
22
23
|
+ e.g. 1234(string) is encoded into MTIzNA==(string)
|
@@ -102,7 +103,8 @@ timestamp to decode (timestamp) : 2017-01-01 00:00:00 UTC
|
|
102
103
|
|
103
104
|
### Todo
|
104
105
|
|
105
|
-
*
|
106
|
+
* [Support base64 in apache commons codec](https://github.com/ysk24ok/embulk-filter-base64/issues/1)
|
107
|
+
* [Support encoder/decoder of URL and MIME](https://github.com/ysk24ok/embulk-filter-base64/issues/2)
|
106
108
|
|
107
109
|
## Build
|
108
110
|
|
data/build.gradle
CHANGED
@@ -13,7 +13,7 @@ configurations {
|
|
13
13
|
provided
|
14
14
|
}
|
15
15
|
|
16
|
-
version = "0.1.
|
16
|
+
version = "0.1.1"
|
17
17
|
|
18
18
|
sourceCompatibility = 1.7
|
19
19
|
targetCompatibility = 1.7
|
@@ -23,6 +23,7 @@ dependencies {
|
|
23
23
|
provided "org.embulk:embulk-core:0.8.15"
|
24
24
|
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
|
25
25
|
testCompile "junit:junit:4.+"
|
26
|
+
testCompile "org.embulk:embulk-core:0.8.15:tests"
|
26
27
|
}
|
27
28
|
|
28
29
|
task classpath(type: Copy, dependsOn: ["jar"]) {
|
Binary file
|
@@ -8,7 +8,6 @@ import java.util.Base64;
|
|
8
8
|
import com.google.common.base.Optional;
|
9
9
|
import org.embulk.config.Config;
|
10
10
|
import org.embulk.config.ConfigDefault;
|
11
|
-
import org.embulk.config.ConfigDiff;
|
12
11
|
import org.embulk.config.ConfigSource;
|
13
12
|
import org.embulk.config.Task;
|
14
13
|
import org.embulk.config.TaskSource;
|
@@ -41,6 +40,8 @@ public class Base64FilterPlugin
|
|
41
40
|
@Config("name")
|
42
41
|
public String getName();
|
43
42
|
|
43
|
+
// TODO: getType
|
44
|
+
|
44
45
|
@Config("encode")
|
45
46
|
@ConfigDefault("false")
|
46
47
|
public Optional<Boolean> getDoEncode();
|
@@ -50,15 +51,35 @@ public class Base64FilterPlugin
|
|
50
51
|
public Optional<Boolean> getDoDecode();
|
51
52
|
}
|
52
53
|
|
54
|
+
public void validate(PluginTask pluginTask, Schema inputSchema)
|
55
|
+
{
|
56
|
+
for (Base64ColumnTask task : pluginTask.getColumns()) {
|
57
|
+
// throws exception if the column name does not exist
|
58
|
+
inputSchema.lookupColumn(task.getName());
|
59
|
+
boolean doEncode = task.getDoEncode().get();
|
60
|
+
boolean doDecode = task.getDoDecode().get();
|
61
|
+
boolean bothTrue = doEncode && doDecode;
|
62
|
+
boolean bothFalse = !doEncode && !doDecode;
|
63
|
+
if (bothTrue || bothFalse) {
|
64
|
+
String errMsg = "Specify either 'encode: true' or 'decode: true'";
|
65
|
+
throw new DataException(errMsg);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
for (Column column : inputSchema.getColumns()) {
|
69
|
+
Type colType = column.getType();
|
70
|
+
if (!Types.STRING.equals(colType)) {
|
71
|
+
String errMsg = "Type of input columns must be string";
|
72
|
+
throw new DataException(errMsg);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
53
77
|
@Override
|
54
78
|
public void transaction(ConfigSource config, Schema inputSchema,
|
55
79
|
FilterPlugin.Control control)
|
56
80
|
{
|
57
81
|
PluginTask task = config.loadConfig(PluginTask.class);
|
58
|
-
|
59
|
-
// throws exception if the column name does not exist
|
60
|
-
inputSchema.lookupColumn(base64ColTask.getName());
|
61
|
-
}
|
82
|
+
validate(task, inputSchema);
|
62
83
|
Schema outputSchema = inputSchema;
|
63
84
|
control.run(task.dump(), outputSchema);
|
64
85
|
}
|
@@ -67,157 +88,52 @@ public class Base64FilterPlugin
|
|
67
88
|
public PageOutput open(TaskSource taskSource, final Schema inputSchema,
|
68
89
|
final Schema outputSchema, final PageOutput output)
|
69
90
|
{
|
70
|
-
PluginTask task = taskSource.loadTask(PluginTask.class);
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
public void add(Page page)
|
81
|
-
{
|
82
|
-
reader.setPage(page);
|
83
|
-
while (reader.nextRecord()) {
|
84
|
-
for (Column column: inputSchema.getColumns()) {
|
85
|
-
String colName = column.getName();
|
86
|
-
Type colType = column.getType();
|
87
|
-
Base64ColumnTask colTask = base64ColumnMap.get(colName);
|
88
|
-
// columns where nothing to be done
|
89
|
-
if (colTask == null) {
|
90
|
-
column.visit(visitor);
|
91
|
-
continue;
|
92
|
-
}
|
93
|
-
Boolean doEncode = colTask.getDoEncode().get();
|
94
|
-
Boolean doDecode = colTask.getDoDecode().get();
|
95
|
-
Boolean bothTrue = doEncode && doDecode;
|
96
|
-
Boolean bothFalse = !doEncode && !doDecode;
|
97
|
-
if (bothTrue || bothFalse) {
|
98
|
-
String errMsg = "Specify either 'encode: true' or 'decode: true'";
|
99
|
-
throw new Base64ValidateException(errMsg);
|
100
|
-
}
|
101
|
-
if (!Types.STRING.equals(colType)) {
|
102
|
-
String errMsg = "Type of input columns must be string";
|
103
|
-
throw new Base64ValidateException(errMsg);
|
104
|
-
}
|
105
|
-
// encode
|
106
|
-
if (doEncode) {
|
107
|
-
String raw = reader.getString(column);
|
108
|
-
String encoded = Base64.getEncoder().encodeToString(raw.getBytes());
|
109
|
-
builder.setString(column, encoded);
|
110
|
-
}
|
111
|
-
// decode
|
112
|
-
if (doDecode) {
|
113
|
-
String encoded = reader.getString(column);
|
114
|
-
String decoded = new String(Base64.getDecoder().decode(encoded));
|
115
|
-
builder.setString(column, decoded);
|
116
|
-
}
|
117
|
-
}
|
118
|
-
builder.addRecord();
|
119
|
-
}
|
120
|
-
}
|
91
|
+
final PluginTask task = taskSource.loadTask(PluginTask.class);
|
92
|
+
PageBuilder pageBuilder = new PageBuilder(
|
93
|
+
Exec.getBufferAllocator(), outputSchema, output);
|
94
|
+
PageReader pageReader = new PageReader(inputSchema);
|
95
|
+
ColumnVisitorImpl visitor = new ColumnVisitorImpl(
|
96
|
+
task, pageReader, pageBuilder);
|
97
|
+
|
98
|
+
return new PageOutputImpl(
|
99
|
+
pageReader, pageBuilder, outputSchema, visitor);
|
100
|
+
}
|
121
101
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
102
|
+
public static class PageOutputImpl implements PageOutput
|
103
|
+
{
|
104
|
+
private PageReader pageReader;
|
105
|
+
private PageBuilder pageBuilder;
|
106
|
+
private Schema outputSchema;
|
107
|
+
private ColumnVisitorImpl visitor;
|
127
108
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
109
|
+
PageOutputImpl(PageReader pageReader, PageBuilder pageBuilder, Schema outputSchema, ColumnVisitorImpl visitor)
|
110
|
+
{
|
111
|
+
this.pageReader = pageReader;
|
112
|
+
this.pageBuilder = pageBuilder;
|
113
|
+
this.outputSchema = outputSchema;
|
114
|
+
this.visitor = visitor;
|
115
|
+
}
|
133
116
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
@Override
|
143
|
-
public void booleanColumn(Column outputColumn)
|
144
|
-
{
|
145
|
-
if (reader.isNull(outputColumn)) {
|
146
|
-
builder.setNull(outputColumn);
|
147
|
-
} else {
|
148
|
-
builder.setBoolean(outputColumn, reader.getBoolean(outputColumn));
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
@Override
|
153
|
-
public void longColumn(Column outputColumn)
|
154
|
-
{
|
155
|
-
if (reader.isNull(outputColumn)) {
|
156
|
-
builder.setNull(outputColumn);
|
157
|
-
} else {
|
158
|
-
builder.setLong(outputColumn, reader.getLong(outputColumn));
|
159
|
-
}
|
160
|
-
}
|
161
|
-
|
162
|
-
@Override
|
163
|
-
public void doubleColumn(Column outputColumn)
|
164
|
-
{
|
165
|
-
if (reader.isNull(outputColumn)) {
|
166
|
-
builder.setNull(outputColumn);
|
167
|
-
} else {
|
168
|
-
builder.setDouble(outputColumn, reader.getDouble(outputColumn));
|
169
|
-
}
|
170
|
-
}
|
171
|
-
|
172
|
-
@Override
|
173
|
-
public void stringColumn(Column outputColumn)
|
174
|
-
{
|
175
|
-
if (reader.isNull(outputColumn)) {
|
176
|
-
builder.setNull(outputColumn);
|
177
|
-
} else {
|
178
|
-
builder.setString(outputColumn, reader.getString(outputColumn));
|
179
|
-
}
|
180
|
-
}
|
181
|
-
|
182
|
-
@Override
|
183
|
-
public void timestampColumn(Column outputColumn)
|
184
|
-
{
|
185
|
-
if (reader.isNull(outputColumn)) {
|
186
|
-
builder.setNull(outputColumn);
|
187
|
-
} else {
|
188
|
-
builder.setTimestamp(outputColumn, reader.getTimestamp(outputColumn));
|
189
|
-
}
|
190
|
-
}
|
191
|
-
|
192
|
-
@Override
|
193
|
-
public void jsonColumn(Column outputColumn)
|
194
|
-
{
|
195
|
-
if (reader.isNull(outputColumn)) {
|
196
|
-
builder.setNull(outputColumn);
|
197
|
-
} else {
|
198
|
-
builder.setJson(outputColumn, reader.getJson(outputColumn));
|
199
|
-
}
|
200
|
-
}
|
117
|
+
@Override
|
118
|
+
public void add(Page page)
|
119
|
+
{
|
120
|
+
pageReader.setPage(page);
|
121
|
+
while (pageReader.nextRecord()) {
|
122
|
+
outputSchema.visitColumns(visitor);
|
123
|
+
pageBuilder.addRecord();
|
201
124
|
}
|
202
|
-
}
|
203
|
-
}
|
125
|
+
}
|
204
126
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
for (Base64ColumnTask columnTask: columnTasks) {
|
210
|
-
m.put(columnTask.getName(), columnTask);
|
127
|
+
@Override
|
128
|
+
public void finish()
|
129
|
+
{
|
130
|
+
pageBuilder.finish();
|
211
131
|
}
|
212
|
-
return m;
|
213
|
-
}
|
214
132
|
|
215
|
-
|
216
|
-
|
217
|
-
{
|
218
|
-
Base64ValidateException(String message)
|
133
|
+
@Override
|
134
|
+
public void close()
|
219
135
|
{
|
220
|
-
|
136
|
+
pageBuilder.close();
|
221
137
|
}
|
222
|
-
}
|
138
|
+
};
|
223
139
|
}
|
@@ -0,0 +1,148 @@
|
|
1
|
+
package org.embulk.filter.base64;
|
2
|
+
|
3
|
+
import java.util.List;
|
4
|
+
import java.util.Map;
|
5
|
+
import java.util.HashMap;
|
6
|
+
import java.util.Base64;
|
7
|
+
|
8
|
+
import org.embulk.config.Config;
|
9
|
+
import org.embulk.config.ConfigDefault;
|
10
|
+
import org.embulk.config.Task;
|
11
|
+
import org.embulk.spi.Column;
|
12
|
+
import org.embulk.spi.ColumnVisitor;
|
13
|
+
import org.embulk.spi.DataException;
|
14
|
+
import org.embulk.spi.PageBuilder;
|
15
|
+
import org.embulk.spi.PageReader;
|
16
|
+
import org.embulk.spi.Schema;
|
17
|
+
|
18
|
+
import org.embulk.filter.base64.Base64FilterPlugin.Base64ColumnTask;
|
19
|
+
import org.embulk.filter.base64.Base64FilterPlugin.PluginTask;
|
20
|
+
|
21
|
+
public class ColumnVisitorImpl
|
22
|
+
implements ColumnVisitor
|
23
|
+
{
|
24
|
+
private final PageReader pageReader;
|
25
|
+
private final PageBuilder pageBuilder;
|
26
|
+
private final Map<String, Base64ColumnTask> base64ColumnMap;
|
27
|
+
|
28
|
+
ColumnVisitorImpl(PluginTask task, PageReader reader, PageBuilder builder)
|
29
|
+
{
|
30
|
+
this.pageReader = reader;
|
31
|
+
this.pageBuilder = builder;
|
32
|
+
this.base64ColumnMap = getBase64ColumnMap(task.getColumns());
|
33
|
+
}
|
34
|
+
|
35
|
+
private static Map<String, Base64ColumnTask> getBase64ColumnMap(
|
36
|
+
List<Base64ColumnTask> columnTasks)
|
37
|
+
{
|
38
|
+
Map<String, Base64ColumnTask> m = new HashMap<>();
|
39
|
+
for (Base64ColumnTask columnTask : columnTasks) {
|
40
|
+
m.put(columnTask.getName(), columnTask);
|
41
|
+
}
|
42
|
+
return m;
|
43
|
+
}
|
44
|
+
|
45
|
+
private Base64ColumnTask getTask(Column column)
|
46
|
+
{
|
47
|
+
String colName = column.getName();
|
48
|
+
return base64ColumnMap.get(colName);
|
49
|
+
}
|
50
|
+
|
51
|
+
private String executeTask(Base64ColumnTask task, Column column)
|
52
|
+
{
|
53
|
+
boolean doEncode = task.getDoEncode().get();
|
54
|
+
boolean doDecode = task.getDoDecode().get();
|
55
|
+
// encode
|
56
|
+
if (doEncode) {
|
57
|
+
String raw = pageReader.getString(column);
|
58
|
+
return Base64.getEncoder().encodeToString(raw.getBytes());
|
59
|
+
}
|
60
|
+
// decode
|
61
|
+
//else if (doDecode) {
|
62
|
+
else {
|
63
|
+
String encoded = pageReader.getString(column);
|
64
|
+
return new String(Base64.getDecoder().decode(encoded));
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
@Override
|
69
|
+
public void booleanColumn(Column outputColumn)
|
70
|
+
{
|
71
|
+
if (pageReader.isNull(outputColumn)) {
|
72
|
+
pageBuilder.setNull(outputColumn);
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
pageBuilder.setBoolean(
|
76
|
+
outputColumn, pageReader.getBoolean(outputColumn));
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
@Override
|
81
|
+
public void longColumn(Column outputColumn)
|
82
|
+
{
|
83
|
+
if (pageReader.isNull(outputColumn)) {
|
84
|
+
pageBuilder.setNull(outputColumn);
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
pageBuilder.setLong(
|
88
|
+
outputColumn, pageReader.getLong(outputColumn));
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
@Override
|
93
|
+
public void doubleColumn(Column outputColumn)
|
94
|
+
{
|
95
|
+
if (pageReader.isNull(outputColumn)) {
|
96
|
+
pageBuilder.setNull(outputColumn);
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
pageBuilder.setDouble(
|
100
|
+
outputColumn, pageReader.getDouble(outputColumn));
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
@Override
|
105
|
+
public void stringColumn(Column outputColumn)
|
106
|
+
{
|
107
|
+
if (pageReader.isNull(outputColumn)) {
|
108
|
+
pageBuilder.setNull(outputColumn);
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
Base64ColumnTask task = getTask(outputColumn);
|
112
|
+
// when there is no task executed on this column
|
113
|
+
if (task == null) {
|
114
|
+
pageBuilder.setString(
|
115
|
+
outputColumn, pageReader.getString(outputColumn));
|
116
|
+
// when there is a task
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
String str = executeTask(task, outputColumn);
|
120
|
+
pageBuilder.setString(outputColumn, str);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
@Override
|
126
|
+
public void timestampColumn(Column outputColumn)
|
127
|
+
{
|
128
|
+
if (pageReader.isNull(outputColumn)) {
|
129
|
+
pageBuilder.setNull(outputColumn);
|
130
|
+
}
|
131
|
+
else {
|
132
|
+
pageBuilder.setTimestamp(
|
133
|
+
outputColumn, pageReader.getTimestamp(outputColumn));
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
@Override
|
138
|
+
public void jsonColumn(Column outputColumn)
|
139
|
+
{
|
140
|
+
if (pageReader.isNull(outputColumn)) {
|
141
|
+
pageBuilder.setNull(outputColumn);
|
142
|
+
}
|
143
|
+
else {
|
144
|
+
pageBuilder.setJson(
|
145
|
+
outputColumn, pageReader.getJson(outputColumn));
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
@@ -1,5 +1,92 @@
|
|
1
1
|
package org.embulk.filter.base64;
|
2
2
|
|
3
|
+
import org.embulk.EmbulkTestRuntime;
|
4
|
+
import org.embulk.config.ConfigLoader;
|
5
|
+
import org.embulk.config.ConfigSource;
|
6
|
+
import org.embulk.spi.DataException;
|
7
|
+
import org.embulk.spi.Exec;
|
8
|
+
import org.embulk.spi.Schema;
|
9
|
+
import org.embulk.spi.SchemaConfigException;
|
10
|
+
import org.embulk.spi.type.Types;
|
11
|
+
import org.embulk.filter.base64.Base64FilterPlugin.PluginTask;
|
12
|
+
|
13
|
+
import org.junit.Rule;
|
14
|
+
import org.junit.Test;
|
15
|
+
|
3
16
|
public class TestBase64FilterPlugin
|
4
17
|
{
|
18
|
+
@Rule
|
19
|
+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
|
20
|
+
|
21
|
+
public Base64FilterPlugin plugin = new Base64FilterPlugin();
|
22
|
+
|
23
|
+
public static PluginTask taskFromYamlString(String... lines)
|
24
|
+
{
|
25
|
+
StringBuilder builder = new StringBuilder();
|
26
|
+
for (String line : lines) {
|
27
|
+
builder.append(line).append("\n");
|
28
|
+
}
|
29
|
+
String yamlString = builder.toString();
|
30
|
+
|
31
|
+
ConfigLoader loader = new ConfigLoader(Exec.getModelManager());
|
32
|
+
ConfigSource config = loader.fromYamlString(yamlString);
|
33
|
+
return config.loadConfig(PluginTask.class);
|
34
|
+
}
|
35
|
+
|
36
|
+
@Test(expected = SchemaConfigException.class)
|
37
|
+
public void testValidate_noColumn()
|
38
|
+
{
|
39
|
+
PluginTask task = taskFromYamlString(
|
40
|
+
"type: base64",
|
41
|
+
"columns:",
|
42
|
+
" - {name: to encode, type: string, encode: true}",
|
43
|
+
" - {name: to decode, type: string, decode: true}"
|
44
|
+
);
|
45
|
+
Schema inputSchema = Schema.builder()
|
46
|
+
.add("to encode", Types.STRING)
|
47
|
+
.build();
|
48
|
+
plugin.validate(task, inputSchema);
|
49
|
+
}
|
50
|
+
|
51
|
+
@Test(expected = DataException.class)
|
52
|
+
public void testValidate_bothSpecified()
|
53
|
+
{
|
54
|
+
PluginTask task = taskFromYamlString(
|
55
|
+
"type: base64",
|
56
|
+
"columns:",
|
57
|
+
" - {name: to encode, type: string, encode: true, decode: true}"
|
58
|
+
);
|
59
|
+
Schema inputSchema = Schema.builder()
|
60
|
+
.add("to encode", Types.STRING)
|
61
|
+
.build();
|
62
|
+
plugin.validate(task, inputSchema);
|
63
|
+
}
|
64
|
+
|
65
|
+
@Test(expected = DataException.class)
|
66
|
+
public void testValidate_bothNotSpecified()
|
67
|
+
{
|
68
|
+
PluginTask task = taskFromYamlString(
|
69
|
+
"type: base64",
|
70
|
+
"columns:",
|
71
|
+
" - {name: to encode, type: string}"
|
72
|
+
);
|
73
|
+
Schema inputSchema = Schema.builder()
|
74
|
+
.add("to encode", Types.STRING)
|
75
|
+
.build();
|
76
|
+
plugin.validate(task, inputSchema);
|
77
|
+
}
|
78
|
+
|
79
|
+
@Test(expected = DataException.class)
|
80
|
+
public void testValidate_invalidInputType()
|
81
|
+
{
|
82
|
+
PluginTask task = taskFromYamlString(
|
83
|
+
"type: base64",
|
84
|
+
"columns:",
|
85
|
+
" - {name: to encode, type: string, type: double}"
|
86
|
+
);
|
87
|
+
Schema inputSchema = Schema.builder()
|
88
|
+
.add("to encode", Types.DOUBLE)
|
89
|
+
.build();
|
90
|
+
plugin.validate(task, inputSchema);
|
91
|
+
}
|
5
92
|
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
package org.embulk.filter.base64;
|
2
|
+
|
3
|
+
import java.util.List;
|
4
|
+
|
5
|
+
import org.embulk.EmbulkTestRuntime;
|
6
|
+
import org.embulk.config.ConfigLoader;
|
7
|
+
import org.embulk.config.ConfigSource;
|
8
|
+
import org.embulk.spi.Exec;
|
9
|
+
import org.embulk.spi.Page;
|
10
|
+
import org.embulk.spi.PageBuilder;
|
11
|
+
import org.embulk.spi.PageOutput;
|
12
|
+
import org.embulk.spi.PageReader;
|
13
|
+
import org.embulk.spi.PageTestUtils;
|
14
|
+
import org.embulk.spi.Schema;
|
15
|
+
import org.embulk.spi.TestPageBuilderReader.MockPageOutput;
|
16
|
+
import org.embulk.spi.type.Types;
|
17
|
+
import org.embulk.spi.util.Pages;
|
18
|
+
import org.embulk.filter.base64.Base64FilterPlugin.PluginTask;
|
19
|
+
import org.embulk.filter.base64.Base64FilterPlugin.PageOutputImpl;
|
20
|
+
import org.embulk.filter.base64.ColumnVisitorImpl;
|
21
|
+
import static org.embulk.filter.base64.TestBase64FilterPlugin.taskFromYamlString;
|
22
|
+
|
23
|
+
import org.junit.Rule;
|
24
|
+
import org.junit.Test;
|
25
|
+
import static org.junit.Assert.*;
|
26
|
+
|
27
|
+
public class TestColumnVisitorImpl
|
28
|
+
{
|
29
|
+
@Rule
|
30
|
+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
|
31
|
+
|
32
|
+
private List<Object[]> filter(PluginTask task, Schema inputSchema, Object... objects)
|
33
|
+
{
|
34
|
+
MockPageOutput output = new MockPageOutput();
|
35
|
+
Schema outputSchema = inputSchema;
|
36
|
+
PageBuilder pageBuilder = new PageBuilder(
|
37
|
+
runtime.getBufferAllocator(), outputSchema, output);
|
38
|
+
PageReader pageReader = new PageReader(inputSchema);
|
39
|
+
ColumnVisitorImpl visitor = new ColumnVisitorImpl(
|
40
|
+
task, pageReader, pageBuilder);
|
41
|
+
|
42
|
+
List<Page> pages = PageTestUtils.buildPage(
|
43
|
+
runtime.getBufferAllocator(), inputSchema, objects);
|
44
|
+
PageOutput mockPageOutput = new PageOutputImpl(
|
45
|
+
pageReader, pageBuilder, outputSchema, visitor);
|
46
|
+
for (Page page : pages) {
|
47
|
+
mockPageOutput.add(page);
|
48
|
+
}
|
49
|
+
mockPageOutput.finish();
|
50
|
+
mockPageOutput.close();
|
51
|
+
return Pages.toObjects(outputSchema, output.pages);
|
52
|
+
}
|
53
|
+
|
54
|
+
@Test
|
55
|
+
public void testExecuteTask_encode()
|
56
|
+
{
|
57
|
+
PluginTask task = taskFromYamlString(
|
58
|
+
"type: base64",
|
59
|
+
"columns:",
|
60
|
+
" - {name: to encode, type: string, encode: true}"
|
61
|
+
);
|
62
|
+
Schema inputSchema = Schema.builder()
|
63
|
+
.add("to encode", Types.STRING)
|
64
|
+
.build();
|
65
|
+
List<Object[]> records = filter(task, inputSchema,
|
66
|
+
"John",
|
67
|
+
"David"
|
68
|
+
);
|
69
|
+
assertEquals(2, records.size());
|
70
|
+
assertEquals("Sm9obg==", records.get(0)[0]);
|
71
|
+
assertEquals("RGF2aWQ=", records.get(1)[0]);
|
72
|
+
}
|
73
|
+
|
74
|
+
@Test
|
75
|
+
public void testExecuteTask_decode()
|
76
|
+
{
|
77
|
+
PluginTask task = taskFromYamlString(
|
78
|
+
"type: base64",
|
79
|
+
"columns:",
|
80
|
+
" - {name: to decode, type: string, decode: true}"
|
81
|
+
);
|
82
|
+
Schema inputSchema = Schema.builder()
|
83
|
+
.add("to decode", Types.STRING)
|
84
|
+
.build();
|
85
|
+
List<Object[]> records = filter(task, inputSchema,
|
86
|
+
"Sm9obg==",
|
87
|
+
"RGF2aWQ="
|
88
|
+
);
|
89
|
+
assertEquals(2, records.size());
|
90
|
+
assertEquals("John", records.get(0)[0]);
|
91
|
+
assertEquals("David", records.get(1)[0]);
|
92
|
+
}
|
93
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-filter-base64
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke NISHIOKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,8 +63,10 @@ files:
|
|
63
63
|
- gradlew.bat
|
64
64
|
- lib/embulk/filter/base64.rb
|
65
65
|
- src/main/java/org/embulk/filter/base64/Base64FilterPlugin.java
|
66
|
+
- src/main/java/org/embulk/filter/base64/ColumnVisitorImpl.java
|
66
67
|
- src/test/java/org/embulk/filter/base64/TestBase64FilterPlugin.java
|
67
|
-
-
|
68
|
+
- src/test/java/org/embulk/filter/base64/TestColumnVisitorImpl.java
|
69
|
+
- classpath/embulk-filter-base64-0.1.1.jar
|
68
70
|
homepage: https://github.com/ysk24ok/embulk-filter-base64
|
69
71
|
licenses:
|
70
72
|
- MIT
|
Binary file
|