embulk-filter-typecast 0.2.0 → 0.2.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/CHANGELOG.md +6 -0
- data/build.gradle +3 -3
- data/src/main/java/org/embulk/filter/typecast/ColumnCaster.java +146 -12
- data/src/main/java/org/embulk/filter/typecast/TypecastFilterPlugin.java +8 -1
- data/src/test/java/org/embulk/filter/typecast/cast/TestTimestampCast.java +0 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c1a4e112a53e015c9c9a42d0c1c696fbc5171a
|
4
|
+
data.tar.gz: 625666a86b20a2d45e120eabd5eda2a2d6256e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c462c39a5444702970b6373f6935f665cce915fd57cb0b104013f1f4f407a777e071ad5a7a1cde7ca47e13ee94770be9a1fa497d1c67378ad4071e50bc74b07
|
7
|
+
data.tar.gz: 0a12fe293a6205cc90028c5c9efd87222d2a0cd3b1a037c9630f287d1b398b5473df0c7649596ab334e1ee65d6e70ab06703151af02ef23e1454394c7467c9be
|
data/CHANGELOG.md
CHANGED
data/build.gradle
CHANGED
@@ -13,13 +13,13 @@ configurations {
|
|
13
13
|
provided
|
14
14
|
}
|
15
15
|
|
16
|
-
version = "0.2.
|
16
|
+
version = "0.2.1"
|
17
17
|
sourceCompatibility = 1.7
|
18
18
|
targetCompatibility = 1.7
|
19
19
|
|
20
20
|
dependencies {
|
21
|
-
compile "org.embulk:embulk-core:0.8
|
22
|
-
provided "org.embulk:embulk-core:0.8
|
21
|
+
compile "org.embulk:embulk-core:0.8.+"
|
22
|
+
provided "org.embulk:embulk-core:0.8.+"
|
23
23
|
compile "io.github.medjed:JsonPathCompiler:0.1.1"
|
24
24
|
|
25
25
|
testCompile "junit:junit:4.+"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
package org.embulk.filter.typecast;
|
2
2
|
|
3
|
-
import
|
4
|
-
|
3
|
+
import com.google.common.base.Optional;
|
4
|
+
|
5
5
|
import io.github.medjed.jsonpathcompiler.expressions.path.PathCompiler;
|
6
6
|
import io.github.medjed.jsonpathcompiler.expressions.path.PropertyPathToken;
|
7
7
|
import org.embulk.filter.typecast.TypecastFilterPlugin.ColumnConfig;
|
@@ -29,6 +29,7 @@ import org.embulk.spi.type.StringType;
|
|
29
29
|
import org.embulk.spi.type.TimestampType;
|
30
30
|
import org.embulk.spi.type.Type;
|
31
31
|
import org.joda.time.DateTimeZone;
|
32
|
+
import org.jruby.embed.ScriptingContainer;
|
32
33
|
import org.msgpack.value.Value;
|
33
34
|
|
34
35
|
import org.slf4j.Logger;
|
@@ -70,7 +71,7 @@ class ColumnCaster
|
|
70
71
|
}
|
71
72
|
Column inputColumn = inputSchema.lookupColumn(columnConfig.getName());
|
72
73
|
if (inputColumn.getType() instanceof StringType && columnConfig.getType() instanceof TimestampType) {
|
73
|
-
TimestampParser parser = getTimestampParser(
|
74
|
+
TimestampParser parser = getTimestampParser(task, columnConfig);
|
74
75
|
this.timestampParserMap.put(columnConfig.getName(), parser);
|
75
76
|
}
|
76
77
|
}
|
@@ -85,24 +86,157 @@ class ColumnCaster
|
|
85
86
|
}
|
86
87
|
Column inputColumn = inputSchema.lookupColumn(columnConfig.getName());
|
87
88
|
if (inputColumn.getType() instanceof TimestampType && columnConfig.getType() instanceof StringType) {
|
88
|
-
TimestampFormatter parser = getTimestampFormatter(
|
89
|
+
TimestampFormatter parser = getTimestampFormatter(task, columnConfig);
|
89
90
|
this.timestampFormatterMap.put(columnConfig.getName(), parser);
|
90
91
|
}
|
91
92
|
}
|
92
93
|
}
|
93
94
|
|
94
|
-
private
|
95
|
+
private class TimestampParserTaskImpl implements TimestampParser.Task
|
96
|
+
{
|
97
|
+
private final DateTimeZone defaultTimeZone;
|
98
|
+
private final String defaultTimestampFormat;
|
99
|
+
private final String defaultDate;
|
100
|
+
public TimestampParserTaskImpl(
|
101
|
+
DateTimeZone defaultTimeZone,
|
102
|
+
String defaultTimestampFormat,
|
103
|
+
String defaultDate)
|
104
|
+
{
|
105
|
+
this.defaultTimeZone = defaultTimeZone;
|
106
|
+
this.defaultTimestampFormat = defaultTimestampFormat;
|
107
|
+
this.defaultDate = defaultDate;
|
108
|
+
}
|
109
|
+
@Override
|
110
|
+
public DateTimeZone getDefaultTimeZone()
|
111
|
+
{
|
112
|
+
return this.defaultTimeZone;
|
113
|
+
}
|
114
|
+
@Override
|
115
|
+
public String getDefaultTimestampFormat()
|
116
|
+
{
|
117
|
+
return this.defaultTimestampFormat;
|
118
|
+
}
|
119
|
+
@Override
|
120
|
+
public String getDefaultDate()
|
121
|
+
{
|
122
|
+
return this.defaultDate;
|
123
|
+
}
|
124
|
+
@Override
|
125
|
+
public ScriptingContainer getJRuby()
|
126
|
+
{
|
127
|
+
return null;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
private class TimestampParserColumnOptionImpl implements TimestampParser.TimestampColumnOption
|
132
|
+
{
|
133
|
+
private final Optional<DateTimeZone> timeZone;
|
134
|
+
private final Optional<String> format;
|
135
|
+
private final Optional<String> date;
|
136
|
+
public TimestampParserColumnOptionImpl(
|
137
|
+
Optional<DateTimeZone> timeZone,
|
138
|
+
Optional<String> format,
|
139
|
+
Optional<String> date)
|
140
|
+
{
|
141
|
+
this.timeZone = timeZone;
|
142
|
+
this.format = format;
|
143
|
+
this.date = date;
|
144
|
+
}
|
145
|
+
@Override
|
146
|
+
public Optional<DateTimeZone> getTimeZone()
|
147
|
+
{
|
148
|
+
return this.timeZone;
|
149
|
+
}
|
150
|
+
@Override
|
151
|
+
public Optional<String> getFormat()
|
152
|
+
{
|
153
|
+
return this.format;
|
154
|
+
}
|
155
|
+
@Override
|
156
|
+
public Optional<String> getDate()
|
157
|
+
{
|
158
|
+
return this.date;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
private class TimestampFormatterTaskImpl implements TimestampFormatter.Task
|
163
|
+
{
|
164
|
+
private final DateTimeZone defaultTimeZone;
|
165
|
+
private final String defaultTimestampFormat;
|
166
|
+
public TimestampFormatterTaskImpl(
|
167
|
+
DateTimeZone defaultTimeZone,
|
168
|
+
String defaultTimestampFormat)
|
169
|
+
{
|
170
|
+
this.defaultTimeZone = defaultTimeZone;
|
171
|
+
this.defaultTimestampFormat = defaultTimestampFormat;
|
172
|
+
}
|
173
|
+
@Override
|
174
|
+
public DateTimeZone getDefaultTimeZone()
|
175
|
+
{
|
176
|
+
return this.defaultTimeZone;
|
177
|
+
}
|
178
|
+
@Override
|
179
|
+
public String getDefaultTimestampFormat()
|
180
|
+
{
|
181
|
+
return this.defaultTimestampFormat;
|
182
|
+
}
|
183
|
+
@Override
|
184
|
+
public ScriptingContainer getJRuby()
|
185
|
+
{
|
186
|
+
return null;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
private class TimestampFormatterColumnOptionImpl implements TimestampFormatter.TimestampColumnOption
|
191
|
+
{
|
192
|
+
private final Optional<DateTimeZone> timeZone;
|
193
|
+
private final Optional<String> format;
|
194
|
+
public TimestampFormatterColumnOptionImpl(
|
195
|
+
Optional<DateTimeZone> timeZone,
|
196
|
+
Optional<String> format)
|
197
|
+
{
|
198
|
+
this.timeZone = timeZone;
|
199
|
+
this.format = format;
|
200
|
+
}
|
201
|
+
@Override
|
202
|
+
public Optional<DateTimeZone> getTimeZone()
|
203
|
+
{
|
204
|
+
return this.timeZone;
|
205
|
+
}
|
206
|
+
@Override
|
207
|
+
public Optional<String> getFormat()
|
208
|
+
{
|
209
|
+
return this.format;
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
private TimestampParser getTimestampParser(PluginTask task, ColumnConfig columnConfig)
|
95
214
|
{
|
96
|
-
|
97
|
-
|
98
|
-
|
215
|
+
// ToDo: Use following codes after deciding to drop supporting embulk < 0.8.29.
|
216
|
+
//
|
217
|
+
// DateTimeZone timezone = columnConfig.getTimeZone().or(task.getDefaultTimeZone());
|
218
|
+
// String format = columnConfig.getFormat().or(task.getDefaultTimestampFormat());
|
219
|
+
// String date = columnConfig.getDate().or(task.getDefaultDate());
|
220
|
+
// return new TimestampParser(format, timezone, date);
|
221
|
+
TimestampParserTaskImpl t = new TimestampParserTaskImpl(
|
222
|
+
task.getDefaultTimeZone(), task.getDefaultTimestampFormat(), task.getDefaultDate());
|
223
|
+
TimestampParserColumnOptionImpl columnOption = new TimestampParserColumnOptionImpl(
|
224
|
+
columnConfig.getTimeZone(), columnConfig.getFormat(), columnConfig.getDate());
|
225
|
+
return new TimestampParser(t, columnOption);
|
99
226
|
}
|
100
227
|
|
101
|
-
private TimestampFormatter getTimestampFormatter(
|
228
|
+
private TimestampFormatter getTimestampFormatter(PluginTask task, ColumnConfig columnConfig)
|
102
229
|
{
|
103
|
-
|
104
|
-
|
105
|
-
|
230
|
+
// ToDo: Use following codes after deciding to drop supporting embulk < 0.8.29.
|
231
|
+
//
|
232
|
+
// String format = columnConfig.getFormat().or(task.getDefaultTimestampFormat());
|
233
|
+
// DateTimeZone timezone = columnConfig.getTimeZone().or(task.getDefaultTimeZone());
|
234
|
+
// return new TimestampFormatter(format, timezone);
|
235
|
+
TimestampFormatterTaskImpl t = new TimestampFormatterTaskImpl(
|
236
|
+
task.getDefaultTimeZone(), task.getDefaultTimestampFormat());
|
237
|
+
TimestampFormatterColumnOptionImpl columnOption = new TimestampFormatterColumnOptionImpl(
|
238
|
+
columnConfig.getTimeZone(), columnConfig.getFormat());
|
239
|
+
return new TimestampFormatter(t, Optional.of(columnOption));
|
106
240
|
}
|
107
241
|
|
108
242
|
public void setFromBoolean(Column outputColumn, boolean value)
|
@@ -6,7 +6,6 @@ import io.github.medjed.jsonpathcompiler.expressions.path.PathCompiler;
|
|
6
6
|
import org.embulk.config.Config;
|
7
7
|
import org.embulk.config.ConfigDefault;
|
8
8
|
import org.embulk.config.ConfigException;
|
9
|
-
import org.embulk.config.ConfigInject;
|
10
9
|
import org.embulk.config.ConfigSource;
|
11
10
|
import org.embulk.config.Task;
|
12
11
|
import org.embulk.config.TaskSource;
|
@@ -50,6 +49,10 @@ public class TypecastFilterPlugin implements FilterPlugin
|
|
50
49
|
@Config("format")
|
51
50
|
@ConfigDefault("null")
|
52
51
|
public Optional<String> getFormat();
|
52
|
+
|
53
|
+
@Config("date")
|
54
|
+
@ConfigDefault("null")
|
55
|
+
public Optional<String> getDate();
|
53
56
|
}
|
54
57
|
|
55
58
|
public interface PluginTask extends Task
|
@@ -69,6 +72,10 @@ public class TypecastFilterPlugin implements FilterPlugin
|
|
69
72
|
@Config("default_timestamp_format")
|
70
73
|
@ConfigDefault("\"%Y-%m-%d %H:%M:%S.%N %z\"")
|
71
74
|
public String getDefaultTimestampFormat();
|
75
|
+
|
76
|
+
@Config("default_date")
|
77
|
+
@ConfigDefault("\"1970-01-01\"")
|
78
|
+
public String getDefaultDate();
|
72
79
|
}
|
73
80
|
|
74
81
|
@Override
|
@@ -4,17 +4,12 @@ import org.embulk.EmbulkTestRuntime;
|
|
4
4
|
import org.embulk.spi.DataException;
|
5
5
|
import org.embulk.spi.time.Timestamp;
|
6
6
|
import org.embulk.spi.time.TimestampFormatter;
|
7
|
-
import org.embulk.spi.time.TimestampParser;
|
8
7
|
import org.joda.time.DateTimeZone;
|
9
8
|
import org.junit.Before;
|
10
9
|
import org.junit.Rule;
|
11
10
|
import org.junit.Test;
|
12
|
-
import org.msgpack.value.Value;
|
13
|
-
import org.msgpack.value.ValueFactory;
|
14
11
|
|
15
12
|
import static org.junit.Assert.assertEquals;
|
16
|
-
import static org.junit.Assert.assertTrue;
|
17
|
-
import static org.junit.Assert.fail;
|
18
13
|
|
19
14
|
public class TestTimestampCast
|
20
15
|
{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-filter-typecast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,7 +88,7 @@ files:
|
|
88
88
|
- src/test/java/org/embulk/filter/typecast/cast/TestTimestampCast.java
|
89
89
|
- classpath/accessors-smart-1.1.jar
|
90
90
|
- classpath/asm-5.0.3.jar
|
91
|
-
- classpath/embulk-filter-typecast-0.2.
|
91
|
+
- classpath/embulk-filter-typecast-0.2.1.jar
|
92
92
|
- classpath/json-smart-2.2.1.jar
|
93
93
|
- classpath/JsonPathCompiler-0.1.1.jar
|
94
94
|
- classpath/slf4j-api-1.7.21.jar
|