embulk-filter-timestamp_format 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +3 -2
- data/bench/config_java.yml +2 -1
- data/bench/config_jruby.yml +1 -0
- data/bench/config_jruby_formatter.yml +2 -1
- data/bench/config_jruby_parser.yml +1 -0
- data/bench/config_nano.yml +2 -1
- data/build.gradle +1 -1
- data/example/string_nano.yml +1 -1
- data/src/main/java/org/embulk/filter/timestamp_format/TimestampFormatter.java +31 -4
- data/src/main/java/org/embulk/filter/timestamp_format/TimestampParser.java +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88c7a2edd52859e9304b268ecea6c766158857cd
|
4
|
+
data.tar.gz: 263540b3154fdd4c0a04892db3708b09dac23cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08c540df5bab3aeb3f03c3507042f623fead8488126f714a17dfa3ff09a8c536d03c94ed1773cb6fa37b6255d8cf55f86ed454cb4b6cb229c8bc68e5bcee8c27
|
7
|
+
data.tar.gz: 945fb0c472ee3d9cc42bcfb9dda0a4444919773c42a9b4cca13a274e61505475ce2733e8bfc430449103488cddae5617300d9d0f2195cf779fafc24a96716819
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -111,10 +111,11 @@ yyyy-MM-dd HH:mm:ss.nnnnnnnnn z
|
|
111
111
|
|
112
112
|
This plugin finds places of nano second from texts with regular expression `\.(\d+)`.
|
113
113
|
|
114
|
-
For formatter, you can use
|
114
|
+
For formatter, you can use `nnnnnnnnn` for nano and `nnnnnn` for micro as
|
115
115
|
|
116
116
|
```
|
117
|
-
|
117
|
+
yyyy-MM-dd HH:mm:ss.nnnnnnnnn z
|
118
|
+
yyyy-MM-dd HH:mm:ss.nnnnnn z
|
118
119
|
```
|
119
120
|
|
120
121
|
## ToDo
|
data/bench/config_java.yml
CHANGED
@@ -7,7 +7,8 @@ in:
|
|
7
7
|
- {name: timestamp, type: string}
|
8
8
|
filters:
|
9
9
|
- type: timestamp_format
|
10
|
+
stop_on_invalid_record: true
|
10
11
|
columns:
|
11
|
-
- {name: timestamp, from_format: ["yyyy-MM-dd
|
12
|
+
- {name: timestamp, from_format: ["yyyy-MM-dd HH:mm:ss.SSSSSSSSS"], to_format: "yyyy-MM-dd"}
|
12
13
|
out:
|
13
14
|
type: "null"
|
data/bench/config_jruby.yml
CHANGED
@@ -7,7 +7,8 @@ in:
|
|
7
7
|
- {name: timestamp, type: string}
|
8
8
|
filters:
|
9
9
|
- type: timestamp_format
|
10
|
+
stop_on_invalid_record: true
|
10
11
|
columns:
|
11
|
-
- {name: timestamp, from_format: ["yyyy-MM-dd
|
12
|
+
- {name: timestamp, from_format: ["yyyy-MM-dd HH:mm:ss.SSSSSSSSS"], to_format: "%Y-%m-%d"}
|
12
13
|
out:
|
13
14
|
type: "null"
|
data/bench/config_nano.yml
CHANGED
@@ -7,7 +7,8 @@ in:
|
|
7
7
|
- {name: timestamp, type: string}
|
8
8
|
filters:
|
9
9
|
- type: timestamp_format
|
10
|
+
stop_on_invalid_record: true
|
10
11
|
columns:
|
11
|
-
- {name: timestamp, from_format: ["yyyy-MM-dd
|
12
|
+
- {name: timestamp, from_format: ["yyyy-MM-dd HH:mm:ss.nnnnnnnnn"], to_format: "yyyy-MM-dd HH:mm:ss.nnnnnn"}
|
12
13
|
out:
|
13
14
|
type: "null"
|
data/build.gradle
CHANGED
data/example/string_nano.yml
CHANGED
@@ -13,7 +13,7 @@ filters:
|
|
13
13
|
default_from_timezone: "Asia/Taipei"
|
14
14
|
default_from_timestamp_format: ["yyyy-MM-dd", "yyyy-MM-dd z", "yyyy-MM-dd HH:mm:ss.nnnnnnnnn z", "yyyy-MM-dd HH:mm:ss z", "yyyy-MM-dd HH:mm:ss"]
|
15
15
|
default_to_timezone: "Asia/Taipei"
|
16
|
-
default_to_timestamp_format: "
|
16
|
+
default_to_timestamp_format: "yyyy-MM-dd HH:mm:ss.nnnnnnnn"
|
17
17
|
columns:
|
18
18
|
- {name: string1}
|
19
19
|
- {name: string2, type: timestamp}
|
@@ -16,6 +16,9 @@ import org.jruby.embed.ScriptingContainer;
|
|
16
16
|
import org.jruby.util.RubyDateFormat;
|
17
17
|
|
18
18
|
import java.util.Locale;
|
19
|
+
import java.util.regex.Matcher;
|
20
|
+
import java.util.regex.Pattern;
|
21
|
+
|
19
22
|
import org.joda.time.format.DateTimeFormat;
|
20
23
|
import org.joda.time.format.DateTimeFormatter;
|
21
24
|
|
@@ -45,6 +48,8 @@ public class TimestampFormatter
|
|
45
48
|
|
46
49
|
private final RubyDateFormat jrubyFormatter;
|
47
50
|
private final DateTimeFormatter javaFormatter;
|
51
|
+
private boolean handleNanoResolution = false;
|
52
|
+
private boolean handleMicroResolution = false;
|
48
53
|
private final DateTimeZone toTimeZone;
|
49
54
|
|
50
55
|
public TimestampFormatter(PluginTask task, Optional<? extends TimestampColumnOption> columnOption)
|
@@ -62,12 +67,24 @@ public class TimestampFormatter
|
|
62
67
|
{
|
63
68
|
this.toTimeZone = toTimeZone;
|
64
69
|
if (format.contains("%")) {
|
65
|
-
this.jrubyFormatter = new RubyDateFormat(format, Locale.ENGLISH, true);
|
66
70
|
this.javaFormatter = null;
|
71
|
+
this.jrubyFormatter = new RubyDateFormat(format, Locale.ENGLISH, true);
|
67
72
|
}
|
68
73
|
else {
|
69
74
|
this.jrubyFormatter = null;
|
70
|
-
|
75
|
+
if (format.contains("nnnnnnnnn")) {
|
76
|
+
this.handleNanoResolution = true;
|
77
|
+
String newFormat = format.replaceAll("nnnnnnnnn", "'%09d'");
|
78
|
+
this.javaFormatter = DateTimeFormat.forPattern(newFormat).withLocale(Locale.ENGLISH).withZone(toTimeZone);
|
79
|
+
}
|
80
|
+
else if (format.contains("nnnnnn")) {
|
81
|
+
this.handleMicroResolution = true;
|
82
|
+
String newFormat = format.replaceAll("nnnnnn", "'%06d'");
|
83
|
+
this.javaFormatter = DateTimeFormat.forPattern(newFormat).withLocale(Locale.ENGLISH).withZone(toTimeZone);
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
this.javaFormatter = DateTimeFormat.forPattern(format).withLocale(Locale.ENGLISH).withZone(toTimeZone);
|
87
|
+
}
|
71
88
|
}
|
72
89
|
}
|
73
90
|
|
@@ -106,7 +123,17 @@ public class TimestampFormatter
|
|
106
123
|
|
107
124
|
private String javaFormat(Timestamp value)
|
108
125
|
{
|
109
|
-
|
110
|
-
|
126
|
+
if (handleNanoResolution) {
|
127
|
+
String datetimeFormatted = javaFormatter.print(value.getEpochSecond() * 1000);
|
128
|
+
return String.format(datetimeFormatted, value.getNano());
|
129
|
+
}
|
130
|
+
else if (handleMicroResolution) {
|
131
|
+
String datetimeFormatted = javaFormatter.print(value.getEpochSecond() * 1000);
|
132
|
+
return String.format(datetimeFormatted, value.getNano() / 1000);
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
long milliSecond = value.getEpochSecond() * 1000 + value.getNano() / 1000000;
|
136
|
+
return javaFormatter.print(milliSecond);
|
137
|
+
}
|
111
138
|
}
|
112
139
|
}
|
@@ -74,7 +74,7 @@ public class TimestampParser {
|
|
74
74
|
this.jrubyParserList.add(helper);
|
75
75
|
} else {
|
76
76
|
// special treatment for nano resolution. n is not originally supported by Joda-Time
|
77
|
-
if (format.contains("
|
77
|
+
if (format.contains("nnnnnnnnn")) {
|
78
78
|
this.handleNanoResolutionList.add(true);
|
79
79
|
String newFormat = format.replaceAll("n", "S");
|
80
80
|
DateTimeFormatter parser = DateTimeFormat.forPattern(newFormat).withLocale(Locale.ENGLISH).withZone(defaultFromTimeZone);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-filter-timestamp_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
@@ -97,7 +97,7 @@ files:
|
|
97
97
|
- src/main/java/org/embulk/filter/timestamp_format/cast/StringCast.java
|
98
98
|
- src/main/java/org/embulk/filter/timestamp_format/cast/TimestampCast.java
|
99
99
|
- src/test/java/org/embulk/filter/timestamp_format/TestTimestampUnit.java
|
100
|
-
- classpath/embulk-filter-timestamp_format-0.1.
|
100
|
+
- classpath/embulk-filter-timestamp_format-0.1.9.jar
|
101
101
|
homepage: https://github.com/sonots/embulk-filter-timestamp_format
|
102
102
|
licenses:
|
103
103
|
- MIT
|