embulk-output-td 0.1.7 → 0.1.8

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: 7f75918c0833bfac5a887d29736ec84c572e9594
4
- data.tar.gz: b4079b5ed3740e5f36c3f3c60763549dd2921ff8
3
+ metadata.gz: 7926b5de5fab7cc6f9343b39e0c5d35f8e2e160e
4
+ data.tar.gz: 1f581633d6365c1043fef772f856c79e1b29397e
5
5
  SHA512:
6
- metadata.gz: 80584f78e0fc8c85255e4a10bc53e2e39819253634f22d109e0c5542da4c4e83f7eb43fefc94f9d21ac8cdfe5be6ae3704684f6622b5728f5d6a66c4a9975602
7
- data.tar.gz: 5134cd1a02a2c96c8330206d5ced8780ebae83954b825d8bf606b76cf44b9a31bb1801a9133ac5cc4b56c7a5305c66093f1c01839ee36d1113111edf8b2b4d0a
6
+ metadata.gz: 668eec6a9224c66c7bc0d750af02a8d8a577a584482fa44599722a0478d517ef09b80b214a6821eefee32ebd65ee0dc38d164fb0cd7b3dc13df208d85872aff8
7
+ data.tar.gz: 94a707125cc4631a6cf71fe4af3a720370cf667374d7eb6e8772a7d478b38b1affea2d44244a91dcef9fb0c47ffb7d0ee67751ce392b622de40dd66e2a1a3d63
@@ -1,3 +1,8 @@
1
+ ## 0.1.8 - 2016-01-09
2
+
3
+ * [new feature] Add mode to time value option [#31](https://github.com/treasure-data/embulk-output-td/pull/31)
4
+ * [maintenance] Remove unnecessary warning messages within showErrorRecord method [#30](https://github.com/treasure-data/embulk-output-td/pull/30)
5
+
1
6
  ## 0.1.7 - 2016-01-07
2
7
 
3
8
  * [new feature] Add time_value option [#16](https://github.com/treasure-data/embulk-output-td/pull/16)
@@ -16,7 +16,7 @@ configurations {
16
16
  provided
17
17
  }
18
18
 
19
- version = "0.1.7"
19
+ version = "0.1.8"
20
20
 
21
21
  compileJava.options.encoding = 'UTF-8' // source encoding
22
22
  sourceCompatibility = 1.7
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-output-td"
4
- spec.version = "0.1.7"
4
+ spec.version = "0.1.8"
5
5
  spec.authors = ["Muga Nishizawa"]
6
6
  spec.summary = %[TreasureData output plugin for Embulk]
7
7
  spec.description = %[TreasureData output plugin is an Embulk plugin that loads records to TreasureData read by any input plugins. Search the input plugins by 'embulk-output' keyword.]
@@ -213,19 +213,6 @@ public class TdOutputPlugin
213
213
  public boolean getUseSsl();
214
214
  }
215
215
 
216
- public interface TimeValueConfig
217
- extends Task
218
- {
219
- @Config("from")
220
- @Min(0)
221
- public long getFrom();
222
-
223
- @Config("to")
224
- @ConfigDefault("0")
225
- @Min(0)
226
- public long getTo();
227
- }
228
-
229
216
  public static enum ConvertTimestampType
230
217
  {
231
218
  STRING(-1),
@@ -606,7 +593,9 @@ public class TdOutputPlugin
606
593
  log.info(" - {}: {}", pair.getKey(), pair.getValue());
607
594
  }
608
595
 
609
- showBulkImportErrorRecords(client, sessionName, (int) Math.min(session.getErrorRecords(), task.getDisplayedErrorRecordsCountLimit()));
596
+ if (session.getErrorRecords() > 0L) {
597
+ showBulkImportErrorRecords(client, sessionName, (int) Math.min(session.getErrorRecords(), task.getDisplayedErrorRecordsCountLimit()));
598
+ }
610
599
 
611
600
  if (session.getErrorRecords() > 0 && task.getStopOnInvalidRecord()) {
612
601
  throw new DataException(String.format("Stop committing because the perform job skipped %d error records", session.getErrorRecords()));
@@ -0,0 +1,35 @@
1
+ package org.embulk.output.td;
2
+
3
+ import com.google.common.base.Optional;
4
+ import org.embulk.config.Config;
5
+ import org.embulk.config.ConfigDefault;
6
+ import org.embulk.config.Task;
7
+
8
+ import javax.validation.constraints.Max;
9
+ import javax.validation.constraints.Min;
10
+
11
+ public interface TimeValueConfig
12
+ extends Task
13
+ {
14
+ @Config("mode")
15
+ @ConfigDefault("\"incremental_time\"")
16
+ String getMode();
17
+
18
+ @Config("value")
19
+ @ConfigDefault("null")
20
+ @Min(0)
21
+ @Max(253402300799L) // '9999-12-31 23:59:59 UTC'
22
+ Optional<Long> getValue();
23
+
24
+ @Config("from")
25
+ @ConfigDefault("null")
26
+ @Min(0)
27
+ @Max(253402300799L) // '9999-12-31 23:59:59 UTC'
28
+ Optional<Long> getFrom();
29
+
30
+ @Config("to")
31
+ @ConfigDefault("null")
32
+ @Min(0)
33
+ @Max(253402300799L) // '9999-12-31 23:59:59 UTC'
34
+ Optional<Long> getTo();
35
+ }
@@ -0,0 +1,79 @@
1
+ package org.embulk.output.td;
2
+
3
+ import com.google.common.base.Optional;
4
+ import org.embulk.config.ConfigException;
5
+
6
+ public abstract class TimeValueGenerator
7
+ {
8
+ public abstract long next();
9
+
10
+ public static TimeValueGenerator newGenerator(final TimeValueConfig config)
11
+ {
12
+ switch (config.getMode()) {
13
+ case "incremental_time": { // default mode
14
+ require(config.getFrom(), "'from', 'to'");
15
+ require(config.getTo(), "'to'");
16
+ reject(config.getValue(), "'value'");
17
+
18
+ return new TimeValueGenerator()
19
+ {
20
+ private final long from = config.getFrom().get();
21
+ private final long to = config.getTo().get();
22
+
23
+ private long current = from;
24
+
25
+ @Override
26
+ public long next()
27
+ {
28
+ try {
29
+ return current++;
30
+ }
31
+ finally {
32
+ if (current > to) {
33
+ current = from;
34
+ }
35
+ }
36
+ }
37
+ };
38
+ }
39
+ case "fixed_time": {
40
+ require(config.getValue(), "'value'");
41
+ reject(config.getFrom(), "'from'");
42
+ reject(config.getTo(), "'to'");
43
+
44
+ return new TimeValueGenerator()
45
+ {
46
+ private final long fixed = config.getValue().get();
47
+
48
+ @Override
49
+ public long next()
50
+ {
51
+ return fixed;
52
+ }
53
+ };
54
+ }
55
+ default: {
56
+ throw new ConfigException(String.format("Unknwon mode '%s'. Supported methods are incremental_time, fixed_time.", config.getMode()));
57
+ }
58
+ }
59
+ }
60
+
61
+ // ported from embulk-input-s3
62
+ private static <T> T require(Optional<T> value, String message)
63
+ {
64
+ if (value.isPresent()) {
65
+ return value.get();
66
+ }
67
+ else {
68
+ throw new ConfigException("Required option is not set: " + message);
69
+ }
70
+ }
71
+
72
+ // ported from embulk-input-s3
73
+ private static <T> void reject(Optional<T> value, String message)
74
+ {
75
+ if (value.isPresent()) {
76
+ throw new ConfigException("Invalid option is set: " + message);
77
+ }
78
+ }
79
+ }
@@ -7,6 +7,8 @@ import com.google.common.base.Optional;
7
7
  import com.google.common.base.Throwables;
8
8
  import org.embulk.config.ConfigException;
9
9
  import org.embulk.output.td.TdOutputPlugin;
10
+ import org.embulk.output.td.TimeValueConfig;
11
+ import org.embulk.output.td.TimeValueGenerator;
10
12
  import org.embulk.spi.Column;
11
13
  import org.embulk.spi.ColumnVisitor;
12
14
  import org.embulk.spi.PageReader;
@@ -20,7 +22,6 @@ import org.embulk.spi.type.TimestampType;
20
22
  import org.embulk.spi.type.Type;
21
23
  import org.embulk.spi.util.Timestamps;
22
24
  import org.embulk.output.td.MsgpackGZFileBuilder;
23
- import org.embulk.output.td.TdOutputPlugin.TimeValueConfig;
24
25
  import org.slf4j.Logger;
25
26
 
26
27
  public class FieldWriterSet
@@ -220,7 +221,7 @@ public class FieldWriterSet
220
221
  }
221
222
 
222
223
  if (timeValueConfig.isPresent()) {
223
- staticTimeValue = Optional.of(new TimeValueGenerator(timeValueConfig.get()));
224
+ staticTimeValue = Optional.of(TimeValueGenerator.newGenerator(timeValueConfig.get()));
224
225
  }
225
226
  else {
226
227
  staticTimeValue = Optional.absent();
@@ -321,29 +322,4 @@ public class FieldWriterSet
321
322
  throw Throwables.propagate(e);
322
323
  }
323
324
  }
324
-
325
- static class TimeValueGenerator
326
- {
327
- private final long from;
328
- private final long to;
329
- private long current;
330
-
331
- TimeValueGenerator(TimeValueConfig config)
332
- {
333
- current = from = config.getFrom();
334
- to = config.getTo();
335
- }
336
-
337
- long next()
338
- {
339
- try {
340
- return current++;
341
- }
342
- finally {
343
- if (current >= to) {
344
- current = from;
345
- }
346
- }
347
- }
348
- }
349
325
  }
@@ -0,0 +1,125 @@
1
+ package org.embulk.output.td;
2
+
3
+ import com.google.common.collect.ImmutableMap;
4
+ import org.embulk.EmbulkTestRuntime;
5
+ import org.embulk.config.ConfigException;
6
+ import org.embulk.config.ConfigSource;
7
+ import org.embulk.output.td.writer.FieldWriterSet;
8
+ import org.embulk.spi.Exec;
9
+ import org.embulk.spi.Schema;
10
+ import org.embulk.spi.type.Types;
11
+ import org.junit.Before;
12
+ import org.junit.Rule;
13
+ import org.junit.Test;
14
+ import org.slf4j.Logger;
15
+
16
+ import static org.embulk.output.td.TestTdOutputPlugin.config;
17
+ import static org.embulk.output.td.TestTdOutputPlugin.pluginTask;
18
+ import static org.embulk.output.td.TestTdOutputPlugin.schema;
19
+ import static org.junit.Assert.assertTrue;
20
+ import static org.junit.Assert.fail;
21
+
22
+ public class TestTimeValueGenerator
23
+ {
24
+ @Rule
25
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
26
+
27
+ private Logger log;
28
+ private ConfigSource config;
29
+ private Schema schema;
30
+
31
+ @Before
32
+ public void createResources()
33
+ {
34
+ log = Exec.getLogger(TestTimeValueGenerator.class);
35
+ config = config();
36
+ }
37
+
38
+ @Test
39
+ public void validateTimeValue()
40
+ {
41
+ // incremental_time
42
+ { // {from: 0, to: 0} # default incremental_time
43
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
44
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("from", 0L, "to", 0L))), schema);
45
+ }
46
+ { // {from: 0} # default incremental_time
47
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
48
+ try {
49
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("from", 0L))), schema);
50
+ fail();
51
+ }
52
+ catch (Throwable t) {
53
+ assertTrue(t instanceof ConfigException);
54
+ }
55
+ }
56
+ { // {to: 0} # default incremental_time
57
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
58
+ try {
59
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("to", 0L))), schema);
60
+ fail();
61
+ }
62
+ catch (Throwable t) {
63
+ assertTrue(t instanceof ConfigException);
64
+ }
65
+ }
66
+ { // {from: 0, to: 0, mode: incremental_time}
67
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
68
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("from", 0L, "to", 0L, "mode", "incremental_time"))), schema);
69
+ }
70
+ { // {from: 0, mode: incremental_time}
71
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
72
+ try {
73
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("from", 0L, "mode", "incremental_time"))), schema);
74
+ fail();
75
+ }
76
+ catch (Throwable t) {
77
+ assertTrue(t instanceof ConfigException);
78
+ }
79
+ }
80
+ { // {to: 0, mode: incremental_time}
81
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
82
+ try {
83
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("to", 0L, "mode", "incremental_time"))), schema);
84
+ fail();
85
+ }
86
+ catch (Throwable t) {
87
+ assertTrue(t instanceof ConfigException);
88
+ }
89
+ }
90
+ { // {mode: incremental_time}
91
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
92
+ try {
93
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("mode", "incremental_time"))), schema);
94
+ fail();
95
+ }
96
+ catch (Throwable t) {
97
+ assertTrue(t instanceof ConfigException);
98
+ }
99
+ }
100
+
101
+ // fixed_time
102
+ { // {value: 0, mode: fixed_time}
103
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
104
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("value", 0L, "mode", "fixed_time"))), schema);
105
+ }
106
+ { // {mode: fixed_time}
107
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
108
+ try {
109
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("mode", "fixed_time"))), schema);
110
+ }
111
+ catch (Throwable t) {
112
+ assertTrue(t instanceof ConfigException);
113
+ }
114
+ }
115
+ { // {value: 0}
116
+ schema = schema("_c0", Types.STRING, "_c1", Types.LONG);
117
+ try {
118
+ new FieldWriterSet(log, pluginTask(config.set("time_value", ImmutableMap.of("value", 0L))), schema);
119
+ }
120
+ catch (Throwable t) {
121
+ assertTrue(t instanceof ConfigException);
122
+ }
123
+ }
124
+ }
125
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-td
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muga Nishizawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +87,8 @@ files:
87
87
  - src/main/java/org/embulk/output/td/MsgpackGZFileBuilder.java
88
88
  - src/main/java/org/embulk/output/td/RecordWriter.java
89
89
  - src/main/java/org/embulk/output/td/TdOutputPlugin.java
90
+ - src/main/java/org/embulk/output/td/TimeValueConfig.java
91
+ - src/main/java/org/embulk/output/td/TimeValueGenerator.java
90
92
  - src/main/java/org/embulk/output/td/writer/BooleanFieldWriter.java
91
93
  - src/main/java/org/embulk/output/td/writer/DoubleFieldWriter.java
92
94
  - src/main/java/org/embulk/output/td/writer/FieldWriter.java
@@ -102,8 +104,9 @@ files:
102
104
  - src/test/java/com/treasuredata/api/TestTdApiClient.java
103
105
  - src/test/java/org/embulk/output/td/TestRecordWriter.java
104
106
  - src/test/java/org/embulk/output/td/TestTdOutputPlugin.java
107
+ - src/test/java/org/embulk/output/td/TestTimeValueGenerator.java
105
108
  - src/test/java/org/embulk/output/td/writer/TestFieldWriterSet.java
106
- - classpath/embulk-output-td-0.1.7.jar
109
+ - classpath/embulk-output-td-0.1.8.jar
107
110
  - classpath/javassist-3.18.1-GA.jar
108
111
  - classpath/jetty-client-9.2.2.v20140723.jar
109
112
  - classpath/jetty-http-9.2.2.v20140723.jar