embulk-filter-speedometer 0.3.2 → 0.3.3

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: 958b4d942aed7b7887b9e1ef551eff708fc6c772
4
- data.tar.gz: 494333e5bdf90fe38a4b4cb2bfe51d3fd4243ae7
3
+ metadata.gz: 4439cf02600ec5d3100d5e55278db0f621ea0379
4
+ data.tar.gz: 50d8c16f4517f224d220a5dfea9e00e7f18ede42
5
5
  SHA512:
6
- metadata.gz: a079f858ae03565450f89bfcb549da32cdc4ee0decbb132ae711a9a48e99b8a084f92ad22f02843d57324879ba17863ebb5db643acd681d626f610ebc9385716
7
- data.tar.gz: 61c318a6d621d39f54a4493e7113d94dd273c7bb417a01bcd91e91945cdad10f54fddbdbe40fafaac1c3aece860fe6ecd7c7fdbe084fcf5be8dd335815dd6e7c
6
+ metadata.gz: 961d57c198263a6a5288e9b5d88ae88a41db7207782aabe9f6a8a237f4ae92029f82c58ce4e07cbe6beddc0e136ede9559971aeeaac2f19430950f5801773cae
7
+ data.tar.gz: e7afe0a2ca10f05912444ad06619b3b88b61f91ae1f4b0669097c0c478d116d316cdb00cf74a141334d2918399776ee1f9335dbddbc4aaafab91258b320b5464
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/hata/embulk-filter-speedometer.svg?branch=master)](https://travis-ci.org/hata/embulk-filter-speedometer.svg?branch=master)
4
4
 
5
5
  Write log message of processed bytes and throughput periodically.
6
- This plugin works with embulk:0.6.17 or later versions because of removing deprecated APIs.
6
+ This plugin works with embulk:0.8.0 or later versions.
7
7
 
8
8
  ## Overview
9
9
 
data/build.gradle CHANGED
@@ -18,11 +18,12 @@ configurations {
18
18
  provided
19
19
  }
20
20
 
21
- version = "0.3.2"
21
+ version = "0.3.3"
22
22
 
23
23
  dependencies {
24
- compile "org.embulk:embulk-core:0.6.17+"
25
- provided "org.embulk:embulk-core:0.6.17+"
24
+ compile "org.embulk:embulk-core:0.8.0+"
25
+ compile "org.msgpack:msgpack-core:0.7.1"
26
+ provided "org.embulk:embulk-core:0.8.0+"
26
27
  // compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
27
28
  testCompile "org.jmockit:jmockit:1.15+"
28
29
  testCompile "junit:junit:4.+"
@@ -14,7 +14,10 @@ import java.io.InputStream;
14
14
  import java.util.regex.Pattern;
15
15
  import java.util.zip.GZIPInputStream;
16
16
  import java.util.ArrayList;
17
+ import java.util.TreeSet;
18
+ import java.util.List;
17
19
  import java.util.Collections;
20
+ import java.util.Set;
18
21
 
19
22
  import org.junit.Test;
20
23
 
@@ -38,6 +41,11 @@ public class TestSingleRun {
38
41
  validateResultFiles("big_01.csv.gz", "result_big_");
39
42
  }
40
43
 
44
+ @Test
45
+ public void testValidateJsonOutputFile() throws Exception {
46
+ validateJsonResultFiles("ref_json_result_01.csv.gz", "result_json_");
47
+ }
48
+
41
49
  @Test
42
50
  public void testSpeedometerMinLog() throws Exception {
43
51
  validateSpeedometerLog("config_min.yml.run.log");
@@ -48,6 +56,11 @@ public class TestSingleRun {
48
56
  validateSpeedometerLog("config_big.yml.run.log");
49
57
  }
50
58
 
59
+ @Test
60
+ public void testSpeedometerJsonLog() throws Exception {
61
+ validateSpeedometerLog("config_json.yml.run.log");
62
+ }
63
+
51
64
  private void validateSpeedometerLog(String logFile) throws Exception {
52
65
  boolean found = false;
53
66
  try (BufferedReader r = new BufferedReader(new FileReader(getTestFile(logFile)))) {
@@ -64,19 +77,44 @@ public class TestSingleRun {
64
77
  }
65
78
 
66
79
  private void validateResultFiles(String gzipSrcFile, final String prefix) throws Exception {
67
- ArrayList inList = new ArrayList();
68
- ArrayList outList = new ArrayList();
80
+ ArrayList<String> inList = new ArrayList();
81
+ ArrayList<String> outList = new ArrayList();
82
+
83
+ readToListFromGzipFile(gzipSrcFile, inList);
84
+ readToListFromPrefixMatching(prefix, outList);
85
+
86
+ Collections.sort(inList);
87
+ Collections.sort(outList);
88
+
89
+ assertEquals("Verify input and output lines are identical. in:" +
90
+ inList.size() + ", out:" + outList.size(), inList.toString(), outList.toString());
91
+ }
92
+
69
93
 
94
+ private void validateJsonResultFiles(String gzipSrcFile, final String prefix) throws Exception {
95
+ ArrayList<String> inList = new ArrayList();
96
+ ArrayList<String> outList = new ArrayList();
97
+
98
+ readToListFromGzipFile(gzipSrcFile, inList);
99
+ readToListFromPrefixMatching(prefix, outList);
100
+
101
+ assertEquals("Verify input and output lines are identical. in:" +
102
+ inList.size() + ", out:" + outList.size(), readToSet(inList), readToSet(outList));
103
+ }
104
+
105
+ private void readToListFromGzipFile(String gzipSrcFile, List<String> lineList) throws IOException {
70
106
  try (BufferedReader reader = new BufferedReader(new InputStreamReader(
71
107
  new GZIPInputStream(new FileInputStream(getTestFile(gzipSrcFile)))))) {
72
108
  String line = reader.readLine(); // Discard a header line
73
109
  line = reader.readLine();
74
110
  while (line != null) {
75
- inList.add(line);
111
+ lineList.add(line);
76
112
  line = reader.readLine();
77
113
  }
78
114
  }
115
+ }
79
116
 
117
+ private void readToListFromPrefixMatching(final String prefix, List<String> lineList) throws IOException {
80
118
  // In travis env, there are many cpus and it may be different from
81
119
  // my local environment. From this, list all files using File.list method.
82
120
  String[] resultFiles = new File(TEST_DIR).list(new FilenameFilter() {
@@ -90,16 +128,32 @@ public class TestSingleRun {
90
128
  String line = reader.readLine(); // Discard a header line
91
129
  line = reader.readLine();
92
130
  while (line != null) {
93
- outList.add(line);
131
+ lineList.add(line);
94
132
  line = reader.readLine();
95
133
  }
96
134
  }
97
135
  }
136
+ }
98
137
 
99
- Collections.sort(inList);
100
- Collections.sort(outList);
138
+ private TreeSet<String> readToSet(List<String> lineList) throws Exception {
139
+ TreeSet<String> set = new TreeSet<>();
140
+ for (String line : lineList) {
141
+ line = stripQuote(line);
142
+ if (line.startsWith("{") && line.endsWith("}")) {
143
+ ArrayList<String> fields = new ArrayList<>();
144
+ for (String field : line.substring(1, line.length() - 1).split(",")) {
145
+ fields.add(field);
146
+ }
147
+ Collections.sort(fields);
148
+ set.add(fields.toString());
149
+ } else {
150
+ throw new Exception("Unexpected lines." + lineList);
151
+ }
152
+ }
153
+ return set;
154
+ }
101
155
 
102
- assertEquals("Verify input and output lines are identical. in:" +
103
- inList.size() + ", out:" + outList.size(), inList.toString(), outList.toString());
156
+ private String stripQuote(String line) {
157
+ return line.startsWith("'") && line.endsWith("'") ? line.substring(1, line.length() -1) : line;
104
158
  }
105
159
  }
@@ -0,0 +1,20 @@
1
+ in:
2
+ type: file
3
+ path_prefix: ./json_
4
+ decoders:
5
+ - {type: gzip}
6
+ parser:
7
+ type: json
8
+ filters:
9
+ - type: speedometer
10
+ speed_limit: 250000
11
+ out:
12
+ type: file
13
+ path_prefix: ./result_json_
14
+ file_ext: csv
15
+ formatter:
16
+ type: csv
17
+ quote_policy: MINIMAL
18
+ default_timezone: UTC
19
+ newline: LF
20
+ quote: "'"
@@ -22,6 +22,7 @@ import org.embulk.spi.Schema;
22
22
  import org.embulk.spi.time.Timestamp;
23
23
  import org.embulk.spi.time.TimestampFormatter;
24
24
  import org.embulk.spi.util.Timestamps;
25
+ import org.msgpack.value.Value;
25
26
 
26
27
  public class SpeedometerFilterPlugin
27
28
  implements FilterPlugin
@@ -188,6 +189,16 @@ public class SpeedometerFilterPlugin
188
189
  }
189
190
  }
190
191
 
192
+ @Override
193
+ public void jsonColumn(Column column) {
194
+ if (pageReader.isNull(column)) {
195
+ speedMonitor(column);
196
+ pageBuilder.setNull(column);
197
+ } else {
198
+ pageBuilder.setJson(column, speedMonitor(column, pageReader.getJson(column)));
199
+ }
200
+ }
201
+
191
202
  private void speedMonitorStartRecord() {
192
203
  startRecordTime = System.currentTimeMillis();
193
204
  }
@@ -232,6 +243,14 @@ public class SpeedometerFilterPlugin
232
243
  return t;
233
244
  }
234
245
 
246
+ private Value speedMonitor(Column column, Value v) {
247
+ speedMonitorForDelimiter(column);
248
+ // NOTE: This may not be good for performance. But, I have no other idea.
249
+ String s = v.toJson();
250
+ controller.checkSpeedLimit(startRecordTime, s != null ? s.length() : 0);
251
+ return v;
252
+ }
253
+
235
254
  private void speedMonitorForDelimiter(Column column) {
236
255
  if (column.getIndex() > 0) {
237
256
  controller.checkSpeedLimit(startRecordTime, delimiterLength);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-filter-speedometer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-23 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -58,8 +58,11 @@ files:
58
58
  - src/integration-test/java/org/embulk/filter/TestSingleRun.java
59
59
  - src/integration-test/resources/big_01.csv.gz
60
60
  - src/integration-test/resources/config_big.yml
61
+ - src/integration-test/resources/config_json.yml
61
62
  - src/integration-test/resources/config_min.yml
63
+ - src/integration-test/resources/json_01.json.gz
62
64
  - src/integration-test/resources/min_01.csv.gz
65
+ - src/integration-test/resources/ref_json_result_01.csv.gz
63
66
  - src/main/java/org/embulk/filter/SpeedometerFilterPlugin.java
64
67
  - src/main/java/org/embulk/filter/SpeedometerSpeedAggregator.java
65
68
  - src/main/java/org/embulk/filter/SpeedometerSpeedController.java
@@ -68,7 +71,7 @@ files:
68
71
  - src/test/java/org/embulk/filter/TestSpeedometerSpeedAggregator.java
69
72
  - src/test/java/org/embulk/filter/TestSpeedometerSpeedController.java
70
73
  - src/test/java/org/embulk/filter/TestSpeedometerUtil.java
71
- - classpath/embulk-filter-speedometer-0.3.2.jar
74
+ - classpath/embulk-filter-speedometer-0.3.3.jar
72
75
  homepage: https://github.com/hata/embulk-filter-speedometer
73
76
  licenses:
74
77
  - MIT