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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81e7bf1b428ed0d48164dbaaec74a2080be029be
4
- data.tar.gz: 7c8e45fcc5cf72d8ae25eb973382e74bf3b16420
3
+ metadata.gz: 88c7a2edd52859e9304b268ecea6c766158857cd
4
+ data.tar.gz: 263540b3154fdd4c0a04892db3708b09dac23cc0
5
5
  SHA512:
6
- metadata.gz: fbae3c05eb9a2808adab605035e5ad432f9fd61df48b5b077565fcc6372a7e3413ec4ea499ddd98b9ebfbbee3f1073f7fa4a73b4743b238c9532905ee60afcfb
7
- data.tar.gz: b3760fc88ea943d92edc776ef400563affe983718e7d66854e7093ba7a25983d9395ac3a46642ed430c5ccde4dc3845437e10145d7e4d2385e6b722fb021c311
6
+ metadata.gz: 08c540df5bab3aeb3f03c3507042f623fead8488126f714a17dfa3ff09a8c536d03c94ed1773cb6fa37b6255d8cf55f86ed454cb4b6cb229c8bc68e5bcee8c27
7
+ data.tar.gz: 945fb0c472ee3d9cc42bcfb9dda0a4444919773c42a9b4cca13a274e61505475ce2733e8bfc430449103488cddae5617300d9d0f2195cf779fafc24a96716819
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.1.9 (2016-05-10)
2
+
3
+ Enhancements:
4
+
5
+ * Support nano second resolution for Java formatter
6
+
1
7
  # 0.1.8 (2016-05-10)
2
8
 
3
9
  Enhancements:
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 jruby formatter as
114
+ For formatter, you can use `nnnnnnnnn` for nano and `nnnnnn` for micro as
115
115
 
116
116
  ```
117
- %Y-%m-%d %H:%M:%S.%N %z
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
@@ -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 hh:mm:ss.SSSSSSSSS"], to_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"
@@ -7,6 +7,7 @@ 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
12
  - {name: timestamp, from_format: ["%Y-%m-%d %H:%M:%S.%N"], to_format: "%Y-%m-%d"}
12
13
 
@@ -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 hh:mm:ss.SSSSSSSSS"], to_format: "%Y-%m-%d"}
12
+ - {name: timestamp, from_format: ["yyyy-MM-dd HH:mm:ss.SSSSSSSSS"], to_format: "%Y-%m-%d"}
12
13
  out:
13
14
  type: "null"
@@ -7,6 +7,7 @@ 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
12
  - {name: timestamp, from_format: ["%Y-%m-%d %H:%M:%S.%N"], to_format: "yyyy-MM-dd"}
12
13
  out:
@@ -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 hh:mm:ss.nnnnnnnnn"], to_format: "%Y-%m-%d"}
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
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.1.8"
16
+ version = "0.1.9"
17
17
  sourceCompatibility = 1.7
18
18
  targetCompatibility = 1.7
19
19
 
@@ -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: "%Y-%m-%d %H:%M:%S.%N"
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
- this.javaFormatter = DateTimeFormat.forPattern(format).withLocale(Locale.ENGLISH).withZone(toTimeZone);
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
- long milliSecond = value.getEpochSecond() * 1000 + value.getNano() / 1000000;
110
- return javaFormatter.print(milliSecond);
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("n")) {
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.8
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.8.jar
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