embulk-filter-typecast 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d936b48df269ca51c971f2f258c2ae54abd492b5
4
- data.tar.gz: 7611a81214e865fb9f63ab3d346f45b4e2d68063
3
+ metadata.gz: a1c1a4e112a53e015c9c9a42d0c1c696fbc5171a
4
+ data.tar.gz: 625666a86b20a2d45e120eabd5eda2a2d6256e2e
5
5
  SHA512:
6
- metadata.gz: 588142a7396f9a03ac3820276e5cf213345bb0674e72364faba6f0de26157d3184c16edee9d7b874fc2b0a7e73305661a74cc5f81819568c12d3c7b0d127032b
7
- data.tar.gz: 6806eff6b7f631388ca2946b2a8732b824f40418b9e347fc674c9616e4cff1741278da825a3a8f2b8e987626d27dc6bc0c154bf86f71d8d459d0ea956e11ba54
6
+ metadata.gz: 6c462c39a5444702970b6373f6935f665cce915fd57cb0b104013f1f4f407a777e071ad5a7a1cde7ca47e13ee94770be9a1fa497d1c67378ad4071e50bc74b07
7
+ data.tar.gz: 0a12fe293a6205cc90028c5c9efd87222d2a0cd3b1a037c9630f287d1b398b5473df0c7649596ab334e1ee65d6e70ab06703151af02ef23e1454394c7467c9be
@@ -1,3 +1,9 @@
1
+ # 0.2.1 (2017-08-26)
2
+
3
+ Enhancements:
4
+
5
+ * Use old, but non-deprecated TimestampParser and TimestampFormatter API to support embulk < 0.8.29
6
+
1
7
  # 0.2.0 (2017-08-23)
2
8
 
3
9
  Changes:
@@ -13,13 +13,13 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.2.0"
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.29+"
22
- provided "org.embulk:embulk-core:0.8.29+"
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 io.github.medjed.jsonpathcompiler.expressions.Path;
4
- import io.github.medjed.jsonpathcompiler.expressions.Utils;
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(columnConfig, task);
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(columnConfig, task);
89
+ TimestampFormatter parser = getTimestampFormatter(task, columnConfig);
89
90
  this.timestampFormatterMap.put(columnConfig.getName(), parser);
90
91
  }
91
92
  }
92
93
  }
93
94
 
94
- private TimestampParser getTimestampParser(ColumnConfig columnConfig, PluginTask task)
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
- DateTimeZone timezone = columnConfig.getTimeZone().or(task.getDefaultTimeZone());
97
- String format = columnConfig.getFormat().or(task.getDefaultTimestampFormat());
98
- return new TimestampParser(format, timezone);
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(ColumnConfig columnConfig, PluginTask task)
228
+ private TimestampFormatter getTimestampFormatter(PluginTask task, ColumnConfig columnConfig)
102
229
  {
103
- String format = columnConfig.getFormat().or(task.getDefaultTimestampFormat());
104
- DateTimeZone timezone = columnConfig.getTimeZone().or(task.getDefaultTimeZone());
105
- return new TimestampFormatter(format, timezone);
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.0
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-23 00:00:00.000000000 Z
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.0.jar
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