embulk-filter-copy 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/README.md +5 -1
  4. data/build.gradle +6 -5
  5. data/example/config.yml +1 -0
  6. data/example/data.tsv +5 -5
  7. data/gradle/wrapper/gradle-wrapper.jar +0 -0
  8. data/gradle/wrapper/gradle-wrapper.properties +1 -2
  9. data/gradlew +13 -10
  10. data/src/main/java/org/embulk/filter/copy/CopyFilterPlugin.java +26 -37
  11. data/src/main/java/org/embulk/filter/copy/forward/{ForwardBaseTask.java → ForwardParentTask.java} +1 -1
  12. data/src/main/java/org/embulk/filter/copy/forward/InForwardEventReader.java +67 -62
  13. data/src/main/java/org/embulk/filter/copy/forward/InForwardService.java +102 -35
  14. data/src/main/java/org/embulk/filter/copy/forward/OutForwardEventBuilder.java +66 -54
  15. data/src/main/java/org/embulk/filter/copy/forward/OutForwardService.java +2 -2
  16. data/src/main/java/org/embulk/filter/copy/plugin/InternalForwardInputPlugin.java +11 -13
  17. data/src/main/java/org/embulk/filter/copy/runner/AsyncEmbulkRunnerService.java +32 -0
  18. data/src/main/java/org/embulk/filter/copy/runner/EmbulkRunner.java +124 -0
  19. data/src/main/java/org/embulk/filter/copy/spi/DataBuilder.java +41 -0
  20. data/src/main/java/org/embulk/filter/copy/spi/DataReader.java +41 -0
  21. data/src/main/java/org/embulk/filter/copy/spi/ElapsedTime.java +81 -0
  22. data/src/main/java/org/embulk/filter/copy/spi/PageBuilder.java +16 -0
  23. data/src/main/java/org/embulk/filter/copy/spi/PageReader.java +13 -0
  24. data/src/main/java/org/embulk/filter/copy/{util → spi}/StandardColumnVisitor.java +6 -6
  25. data/src/test/java/org/embulk/filter/copy/TestCopyFilterPlugin.java +0 -11
  26. metadata +24 -16
  27. data/src/main/java/org/embulk/filter/copy/executor/EmbulkExecutor.java +0 -105
  28. data/src/main/java/org/embulk/filter/copy/executor/LocalThreadExecutor.java +0 -96
  29. data/src/main/java/org/embulk/filter/copy/forward/InForwardVisitor.java +0 -63
  30. data/src/main/java/org/embulk/filter/copy/forward/OutForwardVisitor.java +0 -63
  31. data/src/main/java/org/embulk/filter/copy/util/ElapsedTime.java +0 -165
@@ -0,0 +1,32 @@
1
+ package org.embulk.filter.copy.runner;
2
+
3
+ import com.google.common.util.concurrent.AbstractExecutionThreadService;
4
+ import org.embulk.exec.ExecutionResult;
5
+ import org.embulk.spi.Exec;
6
+ import org.slf4j.Logger;
7
+
8
+ public class AsyncEmbulkRunnerService
9
+ extends AbstractExecutionThreadService
10
+ {
11
+ private static final Logger logger = Exec.getLogger(AsyncEmbulkRunnerService.class);
12
+ private final EmbulkRunner runner;
13
+
14
+ public AsyncEmbulkRunnerService(EmbulkRunner runner)
15
+ {
16
+ this.runner = runner;
17
+ }
18
+
19
+ @Override
20
+ protected void run()
21
+ throws Exception
22
+ {
23
+ ExecutionResult result = runner.run();
24
+ if (result.isSkipped()) {
25
+ logger.warn("ExecutionResult: EmbulkRunner.run is skipped");
26
+ }
27
+ if (!result.getIgnoredExceptions().isEmpty()) {
28
+ result.getIgnoredExceptions().forEach(e -> logger.warn("Ignored Error is found", e));
29
+ }
30
+ logger.debug("Execution Result: {}", result);
31
+ }
32
+ }
@@ -0,0 +1,124 @@
1
+ package org.embulk.filter.copy.runner;
2
+
3
+ import com.google.common.collect.Lists;
4
+ import com.google.inject.Injector;
5
+ import org.embulk.EmbulkEmbed;
6
+ import org.embulk.config.ConfigException;
7
+ import org.embulk.config.ConfigSource;
8
+ import org.embulk.exec.ExecutionResult;
9
+ import org.embulk.filter.copy.spi.ElapsedTime;
10
+ import org.embulk.spi.Exec;
11
+ import org.slf4j.Logger;
12
+
13
+ import java.lang.reflect.Constructor;
14
+ import java.lang.reflect.InvocationTargetException;
15
+ import java.util.List;
16
+ import java.util.Optional;
17
+
18
+ public class EmbulkRunner
19
+ {
20
+ private static final Logger logger = Exec.getLogger(EmbulkRunner.class);
21
+
22
+ public static Builder builder()
23
+ {
24
+ return new Builder();
25
+ }
26
+
27
+ public static class Builder
28
+ {
29
+ private ConfigSource execConfig;
30
+ private ConfigSource inputConfig;
31
+ private List<ConfigSource> filtersConfig;
32
+ private ConfigSource outputConfig;
33
+
34
+ public Builder()
35
+ {
36
+ }
37
+
38
+ public Builder execConfig(ConfigSource execConfig)
39
+ {
40
+ this.execConfig = execConfig;
41
+ return this;
42
+ }
43
+
44
+ public Builder inputConfig(ConfigSource inputConfig)
45
+ {
46
+ this.inputConfig = inputConfig;
47
+ return this;
48
+ }
49
+
50
+ public Builder filterConfig(List<ConfigSource> filtersConfig)
51
+ {
52
+ this.filtersConfig = filtersConfig;
53
+ return this;
54
+ }
55
+
56
+ public Builder outputConfig(ConfigSource outputConfig)
57
+ {
58
+ this.outputConfig = outputConfig;
59
+ return this;
60
+ }
61
+
62
+ public EmbulkRunner build()
63
+ {
64
+ return new EmbulkRunner(buildConfig());
65
+ }
66
+
67
+ protected ConfigSource buildConfig()
68
+ {
69
+ ConfigSource config = Exec.newConfigSource();
70
+
71
+ config.set("exec", Optional.ofNullable(execConfig).orElse(Exec.newConfigSource()));
72
+ config.set("in", Optional.ofNullable(inputConfig).orElseThrow(() -> new ConfigException("in: is null.")));
73
+ config.set("filters", Optional.ofNullable(filtersConfig).orElse(Lists.newArrayList()));
74
+ config.set("out", Optional.ofNullable(outputConfig).orElseThrow(() -> new ConfigException("out: is null.")));
75
+
76
+ return config;
77
+ }
78
+ }
79
+
80
+ private final ConfigSource config;
81
+
82
+ EmbulkRunner(ConfigSource config)
83
+ {
84
+ this.config = config;
85
+ }
86
+
87
+ private EmbulkEmbed newEmbulkEmbed()
88
+ {
89
+ try {
90
+ Constructor<EmbulkEmbed> constructor = EmbulkEmbed.class
91
+ .getDeclaredConstructor(ConfigSource.class, Injector.class);
92
+ constructor.setAccessible(true);
93
+ return constructor.newInstance(null, Exec.getInjector());
94
+ }
95
+ catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
96
+ throw new ConfigException(e);
97
+ }
98
+ }
99
+
100
+ public ExecutionResult run()
101
+ {
102
+ // TODO: expose config without secret configurations.
103
+ return ElapsedTime.measure(new ElapsedTime.Measurable<ExecutionResult>()
104
+ {
105
+ @Override
106
+ public void onStart()
107
+ {
108
+ logger.info("Start: Embulk Run");
109
+ }
110
+
111
+ @Override
112
+ public void onFinished(long elapsedMillis)
113
+ {
114
+ logger.info("Finished: Embulk Run (Elapsed: {} ms)", elapsedMillis);
115
+ }
116
+
117
+ @Override
118
+ public ExecutionResult run()
119
+ {
120
+ return newEmbulkEmbed().run(config);
121
+ }
122
+ });
123
+ }
124
+ }
@@ -0,0 +1,41 @@
1
+ package org.embulk.filter.copy.spi;
2
+
3
+ import org.embulk.spi.Column;
4
+ import org.embulk.spi.Schema;
5
+ import org.embulk.spi.time.Timestamp;
6
+ import org.msgpack.value.Value;
7
+
8
+ public interface DataBuilder
9
+ {
10
+ Schema getSchema();
11
+
12
+ void addRecord();
13
+
14
+ void setNull(Column column);
15
+
16
+ void setNull(int columnIndex);
17
+
18
+ void setBoolean(Column column, boolean v);
19
+
20
+ void setBoolean(int columnIndex, boolean v);
21
+
22
+ void setString(Column column, String v);
23
+
24
+ void setString(int columnIndex, String v);
25
+
26
+ void setLong(Column column, long v);
27
+
28
+ void setLong(int columnIndex, long v);
29
+
30
+ void setDouble(Column column, double v);
31
+
32
+ void setDouble(int columnIndex, double v);
33
+
34
+ void setTimestamp(Column column, Timestamp v);
35
+
36
+ void setTimestamp(int columnIndex, Timestamp v);
37
+
38
+ void setJson(Column column, Value v);
39
+
40
+ void setJson(int columnIndex, Value v);
41
+ }
@@ -0,0 +1,41 @@
1
+ package org.embulk.filter.copy.spi;
2
+
3
+ import org.embulk.spi.Column;
4
+ import org.embulk.spi.Schema;
5
+ import org.embulk.spi.time.Timestamp;
6
+ import org.msgpack.value.Value;
7
+
8
+ public interface DataReader
9
+ {
10
+ Schema getSchema();
11
+
12
+ boolean nextRecord();
13
+
14
+ boolean isNull(Column column);
15
+
16
+ boolean isNull(int columnIndex);
17
+
18
+ boolean getBoolean(Column column);
19
+
20
+ boolean getBoolean(int columnIndex);
21
+
22
+ String getString(Column column);
23
+
24
+ String getString(int columnIndex);
25
+
26
+ long getLong(Column column);
27
+
28
+ long getLong(int columnIndex);
29
+
30
+ double getDouble(Column column);
31
+
32
+ double getDouble(int columnIndex);
33
+
34
+ Timestamp getTimestamp(Column column);
35
+
36
+ Timestamp getTimestamp(int columnIndex);
37
+
38
+ Value getJson(Column column);
39
+
40
+ Value getJson(int columnIndex);
41
+ }
@@ -0,0 +1,81 @@
1
+ package org.embulk.filter.copy.spi;
2
+
3
+ public class ElapsedTime
4
+ {
5
+ private final static long DEFAULT_POLLING_INTERVAL = 1_000; // ms
6
+
7
+ private static long getNow()
8
+ {
9
+ return System.currentTimeMillis();
10
+ }
11
+
12
+ private static long getElapsed(long start)
13
+ {
14
+ return System.currentTimeMillis() - start;
15
+ }
16
+
17
+ private static void waitUntilNextPolling(long pollingInterval)
18
+ {
19
+ try {
20
+ Thread.sleep(pollingInterval);
21
+ }
22
+ catch (InterruptedException e) {
23
+ // Do Nothing
24
+ }
25
+ }
26
+
27
+ public interface Measurable<T>
28
+ {
29
+ T run();
30
+
31
+ void onStart();
32
+
33
+ void onFinished(long elapsedMillis);
34
+ }
35
+
36
+ public interface Pollable<T>
37
+ {
38
+ boolean poll();
39
+
40
+ T getResult();
41
+
42
+ void onStart();
43
+
44
+ void onWaiting(long elapsedMillis);
45
+
46
+ void onFinished(long elapsedMillis);
47
+ }
48
+
49
+ public static <T> T measure(Measurable<T> measurable)
50
+ {
51
+ long start = getNow();
52
+ measurable.onStart();
53
+ try {
54
+ return measurable.run();
55
+ }
56
+ finally {
57
+ measurable.onFinished(getElapsed(start));
58
+ }
59
+ }
60
+
61
+ public static <T> T measureWithPolling(long pollingInterval, Pollable<T> pollable)
62
+ {
63
+ long start = getNow();
64
+ pollable.onStart();
65
+ while (!pollable.poll()) {
66
+ pollable.onWaiting(getElapsed(start));
67
+ waitUntilNextPolling(pollingInterval);
68
+ }
69
+ try {
70
+ return pollable.getResult();
71
+ }
72
+ finally {
73
+ pollable.onFinished(getElapsed(start));
74
+ }
75
+ }
76
+
77
+ public static <T> T measureWithPolling(Pollable<T> pollable)
78
+ {
79
+ return measureWithPolling(DEFAULT_POLLING_INTERVAL, pollable);
80
+ }
81
+ }
@@ -0,0 +1,16 @@
1
+ package org.embulk.filter.copy.spi;
2
+
3
+ import org.embulk.spi.BufferAllocator;
4
+ import org.embulk.spi.PageOutput;
5
+ import org.embulk.spi.Schema;
6
+ import org.embulk.filter.copy.spi.DataBuilder;
7
+
8
+ public class PageBuilder
9
+ extends org.embulk.spi.PageBuilder
10
+ implements DataBuilder
11
+ {
12
+ public PageBuilder(BufferAllocator allocator, Schema schema, PageOutput output)
13
+ {
14
+ super(allocator, schema, output);
15
+ }
16
+ }
@@ -0,0 +1,13 @@
1
+ package org.embulk.filter.copy.spi;
2
+
3
+ import org.embulk.spi.Schema;
4
+
5
+ public class PageReader
6
+ extends org.embulk.spi.PageReader
7
+ implements DataReader
8
+ {
9
+ public PageReader(Schema schema)
10
+ {
11
+ super(schema);
12
+ }
13
+ }
@@ -1,17 +1,17 @@
1
- package org.embulk.filter.copy.util;
1
+ package org.embulk.filter.copy.spi;
2
2
 
3
3
  import org.embulk.spi.Column;
4
4
  import org.embulk.spi.ColumnVisitor;
5
- import org.embulk.spi.PageBuilder;
6
- import org.embulk.spi.PageReader;
5
+ import org.embulk.filter.copy.spi.DataBuilder;
6
+ import org.embulk.filter.copy.spi.DataReader;
7
7
 
8
8
  public class StandardColumnVisitor
9
9
  implements ColumnVisitor
10
10
  {
11
- private final PageReader reader;
12
- private final PageBuilder builder;
11
+ private final DataReader reader;
12
+ private final DataBuilder builder;
13
13
 
14
- public StandardColumnVisitor(PageReader reader, PageBuilder builder)
14
+ public StandardColumnVisitor(DataReader reader, DataBuilder builder)
15
15
  {
16
16
  this.reader = reader;
17
17
  this.builder = builder;
@@ -4,12 +4,10 @@ import com.google.common.collect.Lists;
4
4
  import org.embulk.EmbulkTestRuntime;
5
5
  import org.embulk.config.ConfigLoader;
6
6
  import org.embulk.config.ConfigSource;
7
- import org.embulk.filter.copy.executor.EmbulkExecutor.ExecutorTask;
8
7
  import org.embulk.spi.Exec;
9
8
  import org.embulk.spi.Schema;
10
9
  import org.embulk.spi.type.Type;
11
10
  import org.embulk.spi.type.Types;
12
- import org.joda.time.DateTimeZone;
13
11
  import org.junit.Before;
14
12
  import org.junit.Rule;
15
13
  import org.junit.Test;
@@ -18,7 +16,6 @@ import org.junit.rules.ExpectedException;
18
16
  import static com.google.common.base.Optional.absent;
19
17
  import static org.embulk.filter.copy.CopyFilterPlugin.EmbulkConfig;
20
18
  import static org.embulk.filter.copy.CopyFilterPlugin.PluginTask;
21
- import static org.embulk.filter.copy.executor.EmbulkExecutor.ExecutorTask.ExecutorType.LOCAL_THREAD;
22
19
  import static org.embulk.filter.copy.forward.InForwardService.InForwardTask;
23
20
  import static org.embulk.filter.copy.forward.OutForwardService.OutForwardTask;
24
21
  import static org.junit.Assert.assertEquals;
@@ -73,14 +70,6 @@ public class TestCopyFilterPlugin
73
70
  assertEquals(Exec.newConfigSource(), embulkConfig.getExecConfig());
74
71
  assertEquals(Lists.<ConfigSource>newArrayList(), embulkConfig.getFilterConfig());
75
72
 
76
- // EmbulkExecutor
77
- ExecutorTask executorTask = task.getExecutorTask();
78
- assertEquals(LOCAL_THREAD, executorTask.getType());
79
-
80
- // TimestampFormatter
81
- assertEquals(DateTimeZone.UTC, task.getDefaultTimeZone());
82
- assertEquals("%Y-%m-%d %H:%M:%S.%6N %z", task.getDefaultTimestampFormat());
83
-
84
73
  // ForwardBaseTask
85
74
  assertEquals("message", task.getMessageTag());
86
75
  assertEquals("shutdown", task.getShutdownTag());
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-filter-copy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Civitaspo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-01 00:00:00.000000000 Z
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -61,30 +61,38 @@ files:
61
61
  - lib/embulk/filter/copy.rb
62
62
  - settings.gradle
63
63
  - src/main/java/org/embulk/filter/copy/CopyFilterPlugin.java
64
- - src/main/java/org/embulk/filter/copy/executor/EmbulkExecutor.java
65
- - src/main/java/org/embulk/filter/copy/executor/LocalThreadExecutor.java
66
- - src/main/java/org/embulk/filter/copy/forward/ForwardBaseTask.java
64
+ - src/main/java/org/embulk/filter/copy/forward/ForwardParentTask.java
67
65
  - src/main/java/org/embulk/filter/copy/forward/InForwardEventReader.java
68
66
  - src/main/java/org/embulk/filter/copy/forward/InForwardService.java
69
- - src/main/java/org/embulk/filter/copy/forward/InForwardVisitor.java
70
67
  - src/main/java/org/embulk/filter/copy/forward/OutForwardEventBuilder.java
71
68
  - src/main/java/org/embulk/filter/copy/forward/OutForwardService.java
72
- - src/main/java/org/embulk/filter/copy/forward/OutForwardVisitor.java
73
69
  - src/main/java/org/embulk/filter/copy/plugin/InternalForwardInputPlugin.java
74
- - src/main/java/org/embulk/filter/copy/util/ElapsedTime.java
75
- - src/main/java/org/embulk/filter/copy/util/StandardColumnVisitor.java
70
+ - src/main/java/org/embulk/filter/copy/runner/AsyncEmbulkRunnerService.java
71
+ - src/main/java/org/embulk/filter/copy/runner/EmbulkRunner.java
72
+ - src/main/java/org/embulk/filter/copy/spi/DataBuilder.java
73
+ - src/main/java/org/embulk/filter/copy/spi/DataReader.java
74
+ - src/main/java/org/embulk/filter/copy/spi/ElapsedTime.java
75
+ - src/main/java/org/embulk/filter/copy/spi/PageBuilder.java
76
+ - src/main/java/org/embulk/filter/copy/spi/PageReader.java
77
+ - src/main/java/org/embulk/filter/copy/spi/StandardColumnVisitor.java
76
78
  - src/test/java/org/embulk/filter/copy/TestCopyFilterPlugin.java
77
79
  - src/test/java/org/embulk/filter/copy/plugin/TestInternalForwardInputPlugin.java
78
- - classpath/embulk-filter-copy-0.0.2.jar
80
+ - classpath/jsr305-1.3.9.jar
81
+ - classpath/error_prone_annotations-2.0.18.jar
82
+ - classpath/jackson-databind-2.7.1.jar
83
+ - classpath/jackson-core-2.7.1.jar
84
+ - classpath/embulk-filter-copy-0.1.0.jar
85
+ - classpath/slf4j-api-1.7.25.jar
86
+ - classpath/phi-accural-failure-detector-0.0.4.jar
87
+ - classpath/influent-transport-0.3.0.jar
79
88
  - classpath/fluency-1.1.0.jar
80
- - classpath/influent-java-0.2.0.jar
81
- - classpath/influent-transport-0.2.0.jar
89
+ - classpath/influent-java-0.3.0.jar
90
+ - classpath/msgpack-core-0.8.13.jar
91
+ - classpath/guava-23.0.jar
82
92
  - classpath/jackson-annotations-2.7.0.jar
83
- - classpath/jackson-core-2.7.1.jar
84
- - classpath/jackson-databind-2.7.1.jar
93
+ - classpath/j2objc-annotations-1.1.jar
94
+ - classpath/animal-sniffer-annotations-1.14.jar
85
95
  - classpath/jackson-dataformat-msgpack-0.8.11.jar
86
- - classpath/phi-accural-failure-detector-0.0.4.jar
87
- - classpath/slf4j-api-1.7.22.jar
88
96
  homepage: https://github.com/civitaspo/embulk-filter-copy
89
97
  licenses:
90
98
  - MIT