embulk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +13 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +33 -0
- data/README.md +117 -0
- data/Rakefile +58 -0
- data/bin/embulk +63 -0
- data/build.gradle +149 -0
- data/embulk-cli/build.gradle +6 -0
- data/embulk-cli/pom.xml +94 -0
- data/embulk-cli/src/main/java/org/embulk/cli/Main.java +15 -0
- data/embulk-core/build.gradle +6 -0
- data/embulk-core/pom.xml +143 -0
- data/embulk-core/src/main/java/org/embulk/EmbulkService.java +39 -0
- data/embulk-core/src/main/java/org/embulk/command/Runner.java +199 -0
- data/embulk-core/src/main/java/org/embulk/command/TablePrinter.java +119 -0
- data/embulk-core/src/main/java/org/embulk/config/CommitReport.java +26 -0
- data/embulk-core/src/main/java/org/embulk/config/Config.java +15 -0
- data/embulk-core/src/main/java/org/embulk/config/ConfigDefault.java +15 -0
- data/embulk-core/src/main/java/org/embulk/config/ConfigException.java +20 -0
- data/embulk-core/src/main/java/org/embulk/config/ConfigLoader.java +83 -0
- data/embulk-core/src/main/java/org/embulk/config/ConfigSource.java +28 -0
- data/embulk-core/src/main/java/org/embulk/config/DataSource.java +35 -0
- data/embulk-core/src/main/java/org/embulk/config/DataSourceImpl.java +208 -0
- data/embulk-core/src/main/java/org/embulk/config/DataSourceSerDe.java +80 -0
- data/embulk-core/src/main/java/org/embulk/config/GenericTypeReference.java +20 -0
- data/embulk-core/src/main/java/org/embulk/config/ModelManager.java +125 -0
- data/embulk-core/src/main/java/org/embulk/config/NextConfig.java +26 -0
- data/embulk-core/src/main/java/org/embulk/config/Task.java +10 -0
- data/embulk-core/src/main/java/org/embulk/config/TaskInvocationHandler.java +180 -0
- data/embulk-core/src/main/java/org/embulk/config/TaskSerDe.java +343 -0
- data/embulk-core/src/main/java/org/embulk/config/TaskSource.java +28 -0
- data/embulk-core/src/main/java/org/embulk/config/TaskValidationException.java +37 -0
- data/embulk-core/src/main/java/org/embulk/config/TaskValidator.java +24 -0
- data/embulk-core/src/main/java/org/embulk/exec/ExecModule.java +45 -0
- data/embulk-core/src/main/java/org/embulk/exec/ExecuteInterruptedException.java +10 -0
- data/embulk-core/src/main/java/org/embulk/exec/ExecuteResult.java +19 -0
- data/embulk-core/src/main/java/org/embulk/exec/ExtensionServiceLoaderModule.java +43 -0
- data/embulk-core/src/main/java/org/embulk/exec/ForSystemConfig.java +16 -0
- data/embulk-core/src/main/java/org/embulk/exec/GuessExecutor.java +307 -0
- data/embulk-core/src/main/java/org/embulk/exec/LocalExecutor.java +274 -0
- data/embulk-core/src/main/java/org/embulk/exec/LoggerProvider.java +30 -0
- data/embulk-core/src/main/java/org/embulk/exec/NoSampleException.java +10 -0
- data/embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java +58 -0
- data/embulk-core/src/main/java/org/embulk/exec/PreviewExecutor.java +138 -0
- data/embulk-core/src/main/java/org/embulk/exec/PreviewResult.java +27 -0
- data/embulk-core/src/main/java/org/embulk/exec/PreviewedNoticeError.java +17 -0
- data/embulk-core/src/main/java/org/embulk/exec/SamplingParserPlugin.java +116 -0
- data/embulk-core/src/main/java/org/embulk/exec/SystemConfigModule.java +24 -0
- data/embulk-core/src/main/java/org/embulk/jruby/JRubyPluginSource.java +69 -0
- data/embulk-core/src/main/java/org/embulk/jruby/JRubyScriptingModule.java +100 -0
- data/embulk-core/src/main/java/org/embulk/plugin/BuiltinPluginSourceModule.java +17 -0
- data/embulk-core/src/main/java/org/embulk/plugin/InjectedPluginSource.java +92 -0
- data/embulk-core/src/main/java/org/embulk/plugin/PluginManager.java +34 -0
- data/embulk-core/src/main/java/org/embulk/plugin/PluginSource.java +6 -0
- data/embulk-core/src/main/java/org/embulk/plugin/PluginSourceNotMatchException.java +19 -0
- data/embulk-core/src/main/java/org/embulk/plugin/PluginType.java +47 -0
- data/embulk-core/src/main/java/org/embulk/plugin/SetThreadContextClassLoader.java +19 -0
- data/embulk-core/src/main/java/org/embulk/spi/Buffer.java +113 -0
- data/embulk-core/src/main/java/org/embulk/spi/BufferAllocator.java +8 -0
- data/embulk-core/src/main/java/org/embulk/spi/Column.java +92 -0
- data/embulk-core/src/main/java/org/embulk/spi/ColumnConfig.java +79 -0
- data/embulk-core/src/main/java/org/embulk/spi/DecoderPlugin.java +16 -0
- data/embulk-core/src/main/java/org/embulk/spi/EncoderPlugin.java +16 -0
- data/embulk-core/src/main/java/org/embulk/spi/Exec.java +76 -0
- data/embulk-core/src/main/java/org/embulk/spi/ExecAction.java +6 -0
- data/embulk-core/src/main/java/org/embulk/spi/ExecSession.java +105 -0
- data/embulk-core/src/main/java/org/embulk/spi/Extension.java +42 -0
- data/embulk-core/src/main/java/org/embulk/spi/FileInput.java +11 -0
- data/embulk-core/src/main/java/org/embulk/spi/FileInputPlugin.java +19 -0
- data/embulk-core/src/main/java/org/embulk/spi/FileInputRunner.java +113 -0
- data/embulk-core/src/main/java/org/embulk/spi/FileOutput.java +13 -0
- data/embulk-core/src/main/java/org/embulk/spi/FileOutputPlugin.java +20 -0
- data/embulk-core/src/main/java/org/embulk/spi/FileOutputRunner.java +167 -0
- data/embulk-core/src/main/java/org/embulk/spi/FormatterPlugin.java +18 -0
- data/embulk-core/src/main/java/org/embulk/spi/GuessPlugin.java +9 -0
- data/embulk-core/src/main/java/org/embulk/spi/InputPlugin.java +20 -0
- data/embulk-core/src/main/java/org/embulk/spi/OutputPlugin.java +21 -0
- data/embulk-core/src/main/java/org/embulk/spi/Page.java +45 -0
- data/embulk-core/src/main/java/org/embulk/spi/PageBuilder.java +327 -0
- data/embulk-core/src/main/java/org/embulk/spi/PageFormat.java +47 -0
- data/embulk-core/src/main/java/org/embulk/spi/PageOutput.java +11 -0
- data/embulk-core/src/main/java/org/embulk/spi/PageReader.java +227 -0
- data/embulk-core/src/main/java/org/embulk/spi/ParserPlugin.java +17 -0
- data/embulk-core/src/main/java/org/embulk/spi/Schema.java +101 -0
- data/embulk-core/src/main/java/org/embulk/spi/SchemaConfig.java +52 -0
- data/embulk-core/src/main/java/org/embulk/spi/SchemaVisitor.java +14 -0
- data/embulk-core/src/main/java/org/embulk/spi/Transactional.java +10 -0
- data/embulk-core/src/main/java/org/embulk/spi/TransactionalFileInput.java +17 -0
- data/embulk-core/src/main/java/org/embulk/spi/TransactionalFileOutput.java +19 -0
- data/embulk-core/src/main/java/org/embulk/spi/TransactionalPageOutput.java +17 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/DateTimeZoneSerDe.java +57 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/JRubyTimeParserHelper.java +8 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/JRubyTimeParserHelperFactory.java +6 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/Timestamp.java +159 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampFormat.java +98 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampFormatter.java +55 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampParseException.java +6 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampParser.java +60 -0
- data/embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java +50 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/AbstractType.java +55 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/BooleanType.java +12 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/DoubleType.java +12 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/LongType.java +12 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/StringType.java +12 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/TimestampType.java +39 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/Type.java +15 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/TypeDeserializer.java +47 -0
- data/embulk-core/src/main/java/org/embulk/spi/type/Types.java +14 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/CharsetSerDe.java +55 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/Decoders.java +81 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/Encoders.java +81 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/FileInputInputStream.java +110 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/FileOutputOutputStream.java +94 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/InputStreamFileInput.java +111 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/Inputs.java +74 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/LineDecoder.java +118 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/LineEncoder.java +109 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/ListFileInput.java +52 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/Newline.java +38 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/PagePrinter.java +102 -0
- data/embulk-core/src/main/java/org/embulk/spi/util/Pages.java +139 -0
- data/embulk-core/src/test/java/org/embulk/EmbulkTestRuntime.java +110 -0
- data/embulk-core/src/test/java/org/embulk/GuiceBinder.java +72 -0
- data/embulk-core/src/test/java/org/embulk/RandomManager.java +53 -0
- data/embulk-core/src/test/java/org/embulk/TestPluginSourceModule.java +23 -0
- data/embulk-core/src/test/java/org/embulk/TestUtilityModule.java +17 -0
- data/embulk-core/src/test/java/org/embulk/config/TestConfigSource.java +114 -0
- data/embulk-core/src/test/java/org/embulk/config/TestTaskSource.java +70 -0
- data/embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java +57 -0
- data/embulk-core/src/test/java/org/embulk/plugin/TestPluginType.java +18 -0
- data/embulk-core/src/test/java/org/embulk/spi/MockFileOutput.java +63 -0
- data/embulk-core/src/test/java/org/embulk/spi/MockFormatterPlugin.java +101 -0
- data/embulk-core/src/test/java/org/embulk/spi/MockParserPlugin.java +73 -0
- data/embulk-core/src/test/java/org/embulk/spi/PageTestUtils.java +78 -0
- data/embulk-core/src/test/java/org/embulk/spi/TestFileInputInputStream.java +67 -0
- data/embulk-core/src/test/java/org/embulk/spi/TestFileInputRunner.java +180 -0
- data/embulk-core/src/test/java/org/embulk/spi/TestFileOutputRunner.java +192 -0
- data/embulk-core/src/test/java/org/embulk/spi/TestInputStreamFileInput.java +188 -0
- data/embulk-core/src/test/java/org/embulk/spi/TestPageBuilderReader.java +301 -0
- data/embulk-core/src/test/java/org/embulk/spi/time/TestTimestamp.java +116 -0
- data/embulk-core/src/test/java/org/embulk/spi/time/TestTimestampFormatterParser.java +52 -0
- data/embulk-core/src/test/java/org/embulk/spi/type/TestTypeSerDe.java +45 -0
- data/embulk-core/src/test/java/org/embulk/spi/util/TestLineDecoder.java +132 -0
- data/embulk-core/src/test/java/org/embulk/spi/util/TestLineEncoder.java +123 -0
- data/embulk-standards/build.gradle +6 -0
- data/embulk-standards/pom.xml +68 -0
- data/embulk-standards/src/main/java/org/embulk/standards/CsvFormatterPlugin.java +158 -0
- data/embulk-standards/src/main/java/org/embulk/standards/CsvParserPlugin.java +233 -0
- data/embulk-standards/src/main/java/org/embulk/standards/CsvTokenizer.java +355 -0
- data/embulk-standards/src/main/java/org/embulk/standards/GzipFileDecoderPlugin.java +55 -0
- data/embulk-standards/src/main/java/org/embulk/standards/GzipFileEncoderPlugin.java +39 -0
- data/embulk-standards/src/main/java/org/embulk/standards/LocalFileInputPlugin.java +138 -0
- data/embulk-standards/src/main/java/org/embulk/standards/LocalFileOutputPlugin.java +128 -0
- data/embulk-standards/src/main/java/org/embulk/standards/NullOutputPlugin.java +46 -0
- data/embulk-standards/src/main/java/org/embulk/standards/S3FileInputPlugin.java +238 -0
- data/embulk-standards/src/main/java/org/embulk/standards/StandardPluginExtension.java +16 -0
- data/embulk-standards/src/main/java/org/embulk/standards/StandardPluginModule.java +44 -0
- data/embulk-standards/src/main/java/org/embulk/standards/StdoutOutputPlugin.java +71 -0
- data/embulk-standards/src/main/resources/META-INF/services/org.embulk.spi.Extension +1 -0
- data/embulk-standards/src/test/java/org/embulk/standards/TestCsvParserPlugin.java +69 -0
- data/embulk-standards/src/test/java/org/embulk/standards/TestCsvTokenizer.java +291 -0
- data/embulk-standards/src/test/java/org/embulk/standards/TestS3FileInputPlugin.java +43 -0
- data/embulk.gemspec +27 -0
- data/examples/config.yml +34 -0
- data/examples/csv/sample.csv.gz +0 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +164 -0
- data/gradlew.bat +90 -0
- data/lib/embulk.rb +16 -0
- data/lib/embulk/buffer.rb +17 -0
- data/lib/embulk/column.rb +47 -0
- data/lib/embulk/command/embulk.rb +39 -0
- data/lib/embulk/command/embulk_example.rb +32 -0
- data/lib/embulk/command/embulk_generate_bin.rb +62 -0
- data/lib/embulk/command/embulk_run.rb +243 -0
- data/lib/embulk/data/bundle/.bundle/config +3 -0
- data/lib/embulk/data/bundle/Gemfile +31 -0
- data/lib/embulk/data/bundle/Gemfile.lock +8 -0
- data/lib/embulk/data/bundle/embulk/input_example.rb +40 -0
- data/lib/embulk/data/bundle/embulk/output_example.rb +51 -0
- data/lib/embulk/data_source.rb +66 -0
- data/lib/embulk/error.rb +5 -0
- data/lib/embulk/guess_charset.rb +26 -0
- data/lib/embulk/guess_csv.rb +195 -0
- data/lib/embulk/guess_gzip.rb +18 -0
- data/lib/embulk/guess_newline.rb +20 -0
- data/lib/embulk/guess_plugin.rb +113 -0
- data/lib/embulk/input_plugin.rb +53 -0
- data/lib/embulk/java/bootstrap.rb +12 -0
- data/lib/embulk/java/imports.rb +26 -0
- data/lib/embulk/java/time_helper.rb +77 -0
- data/lib/embulk/output_plugin.rb +104 -0
- data/lib/embulk/page.rb +28 -0
- data/lib/embulk/page_builder.rb +22 -0
- data/lib/embulk/plugin.rb +152 -0
- data/lib/embulk/plugin_registry.rb +70 -0
- data/lib/embulk/schema.rb +85 -0
- data/lib/embulk/time_format_guess.rb +331 -0
- data/lib/embulk/version.rb +3 -0
- data/pom.xml +533 -0
- data/settings.gradle +5 -0
- metadata +370 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package org.embulk.spi;
|
|
2
|
+
|
|
3
|
+
import java.util.List;
|
|
4
|
+
import org.embulk.config.TaskSource;
|
|
5
|
+
import org.embulk.config.ConfigSource;
|
|
6
|
+
import org.embulk.config.NextConfig;
|
|
7
|
+
import org.embulk.config.CommitReport;
|
|
8
|
+
|
|
9
|
+
public interface FileInputPlugin
|
|
10
|
+
{
|
|
11
|
+
public interface Control
|
|
12
|
+
{
|
|
13
|
+
public List<CommitReport> run(TaskSource taskSource, int processorCount);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public NextConfig transaction(ConfigSource config, FileInputPlugin.Control control);
|
|
17
|
+
|
|
18
|
+
public TransactionalFileInput open(TaskSource taskSource, int processorIndex);
|
|
19
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
package org.embulk.spi;
|
|
2
|
+
|
|
3
|
+
import java.util.ArrayList;
|
|
4
|
+
import java.util.List;
|
|
5
|
+
import org.embulk.config.Task;
|
|
6
|
+
import org.embulk.config.TaskSource;
|
|
7
|
+
import org.embulk.config.ConfigSource;
|
|
8
|
+
import org.embulk.config.NextConfig;
|
|
9
|
+
import org.embulk.config.CommitReport;
|
|
10
|
+
import org.embulk.config.Config;
|
|
11
|
+
import org.embulk.config.ConfigDefault;
|
|
12
|
+
import org.embulk.plugin.PluginType;
|
|
13
|
+
import org.embulk.spi.util.Decoders;
|
|
14
|
+
|
|
15
|
+
public class FileInputRunner
|
|
16
|
+
implements InputPlugin
|
|
17
|
+
{
|
|
18
|
+
private final FileInputPlugin fileInputPlugin;
|
|
19
|
+
|
|
20
|
+
public FileInputRunner(FileInputPlugin fileInputPlugin)
|
|
21
|
+
{
|
|
22
|
+
this.fileInputPlugin = fileInputPlugin;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private interface RunnerTask extends Task
|
|
26
|
+
{
|
|
27
|
+
// TODO "type" needed?
|
|
28
|
+
|
|
29
|
+
@Config("decoders")
|
|
30
|
+
@ConfigDefault("[]")
|
|
31
|
+
public List<ConfigSource> getDecoderConfigs();
|
|
32
|
+
|
|
33
|
+
@Config("parser")
|
|
34
|
+
public ConfigSource getParserConfig();
|
|
35
|
+
|
|
36
|
+
public void setFileInputTaskSource(TaskSource v);
|
|
37
|
+
public TaskSource getFileInputTaskSource();
|
|
38
|
+
|
|
39
|
+
public void setDecoderTaskSources(List<TaskSource> v);
|
|
40
|
+
public List<TaskSource> getDecoderTaskSources();
|
|
41
|
+
|
|
42
|
+
public void setParserTaskSource(TaskSource v);
|
|
43
|
+
public TaskSource getParserTaskSource();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected List<DecoderPlugin> newDecoderPlugins(RunnerTask task)
|
|
47
|
+
{
|
|
48
|
+
return Decoders.newDecoderPlugins(Exec.session(), task.getDecoderConfigs());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected ParserPlugin newParserPlugin(RunnerTask task)
|
|
52
|
+
{
|
|
53
|
+
return Exec.newPlugin(ParserPlugin.class, task.getParserConfig().get(PluginType.class, "type"));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Override
|
|
57
|
+
public NextConfig transaction(ConfigSource config, final InputPlugin.Control control)
|
|
58
|
+
{
|
|
59
|
+
final RunnerTask task = config.loadConfig(RunnerTask.class);
|
|
60
|
+
final List<DecoderPlugin> decoderPlugins = newDecoderPlugins(task);
|
|
61
|
+
final ParserPlugin parserPlugin = newParserPlugin(task);
|
|
62
|
+
|
|
63
|
+
return fileInputPlugin.transaction(config, new FileInputPlugin.Control() {
|
|
64
|
+
public List<CommitReport> run(final TaskSource fileInputTaskSource, final int processorCount)
|
|
65
|
+
{
|
|
66
|
+
final List<CommitReport> commitReports = new ArrayList<CommitReport>();
|
|
67
|
+
Decoders.transaction(decoderPlugins, task.getDecoderConfigs(), new Decoders.Control() {
|
|
68
|
+
public void run(final List<TaskSource> decoderTaskSources)
|
|
69
|
+
{
|
|
70
|
+
parserPlugin.transaction(task.getParserConfig(), new ParserPlugin.Control() {
|
|
71
|
+
public void run(final TaskSource parserTaskSource, final Schema schema)
|
|
72
|
+
{
|
|
73
|
+
task.setFileInputTaskSource(fileInputTaskSource);
|
|
74
|
+
task.setDecoderTaskSources(decoderTaskSources);
|
|
75
|
+
task.setParserTaskSource(parserTaskSource);
|
|
76
|
+
commitReports.addAll(control.run(task.dump(), schema, processorCount));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return commitReports;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Override
|
|
87
|
+
public CommitReport run(TaskSource taskSource, Schema schema, int processorIndex,
|
|
88
|
+
PageOutput output)
|
|
89
|
+
{
|
|
90
|
+
final RunnerTask task = taskSource.loadTask(RunnerTask.class);
|
|
91
|
+
List<DecoderPlugin> decoderPlugins = newDecoderPlugins(task);
|
|
92
|
+
ParserPlugin parserPlugin = newParserPlugin(task);
|
|
93
|
+
|
|
94
|
+
TransactionalFileInput tran = fileInputPlugin.open(task.getFileInputTaskSource(), processorIndex);
|
|
95
|
+
FileInput fileInput = tran;
|
|
96
|
+
try {
|
|
97
|
+
fileInput = Decoders.open(decoderPlugins, task.getDecoderTaskSources(), fileInput);
|
|
98
|
+
parserPlugin.run(task.getParserTaskSource(), schema, fileInput, output);
|
|
99
|
+
|
|
100
|
+
CommitReport report = tran.commit(); // TODO check output.finish() is called. wrap
|
|
101
|
+
tran = null;
|
|
102
|
+
return report;
|
|
103
|
+
} finally {
|
|
104
|
+
try {
|
|
105
|
+
if (tran != null) {
|
|
106
|
+
tran.abort();
|
|
107
|
+
}
|
|
108
|
+
} finally {
|
|
109
|
+
fileInput.close();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package org.embulk.spi;
|
|
2
|
+
|
|
3
|
+
import java.util.List;
|
|
4
|
+
import org.embulk.config.TaskSource;
|
|
5
|
+
import org.embulk.config.ConfigSource;
|
|
6
|
+
import org.embulk.config.NextConfig;
|
|
7
|
+
import org.embulk.config.CommitReport;
|
|
8
|
+
|
|
9
|
+
public interface FileOutputPlugin
|
|
10
|
+
{
|
|
11
|
+
public interface Control
|
|
12
|
+
{
|
|
13
|
+
public List<CommitReport> run(TaskSource taskSource);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public NextConfig transaction(ConfigSource config, int processorCount,
|
|
17
|
+
FileOutputPlugin.Control control);
|
|
18
|
+
|
|
19
|
+
public TransactionalFileOutput open(TaskSource taskSource, int processorIndex);
|
|
20
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
package org.embulk.spi;
|
|
2
|
+
|
|
3
|
+
import java.util.List;
|
|
4
|
+
import java.util.ArrayList;
|
|
5
|
+
import org.embulk.config.Task;
|
|
6
|
+
import org.embulk.config.TaskSource;
|
|
7
|
+
import org.embulk.config.ConfigSource;
|
|
8
|
+
import org.embulk.config.NextConfig;
|
|
9
|
+
import org.embulk.config.CommitReport;
|
|
10
|
+
import org.embulk.config.Config;
|
|
11
|
+
import org.embulk.config.ConfigDefault;
|
|
12
|
+
import org.embulk.plugin.PluginType;
|
|
13
|
+
import org.embulk.spi.util.Encoders;
|
|
14
|
+
|
|
15
|
+
public class FileOutputRunner
|
|
16
|
+
implements OutputPlugin
|
|
17
|
+
{
|
|
18
|
+
private final FileOutputPlugin fileOutputPlugin;
|
|
19
|
+
|
|
20
|
+
public FileOutputRunner(FileOutputPlugin fileOutputPlugin)
|
|
21
|
+
{
|
|
22
|
+
this.fileOutputPlugin = fileOutputPlugin;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private interface RunnerTask extends Task
|
|
26
|
+
{
|
|
27
|
+
@Config("type")
|
|
28
|
+
public PluginType getType();
|
|
29
|
+
|
|
30
|
+
@Config("encoders")
|
|
31
|
+
@ConfigDefault("[]")
|
|
32
|
+
public List<ConfigSource> getEncoderConfigs();
|
|
33
|
+
|
|
34
|
+
@Config("formatter")
|
|
35
|
+
public ConfigSource getFormatterConfig();
|
|
36
|
+
|
|
37
|
+
public void setFileOutputTaskSource(TaskSource v);
|
|
38
|
+
public TaskSource getFileOutputTaskSource();
|
|
39
|
+
|
|
40
|
+
public void setEncoderTaskSources(List<TaskSource> v);
|
|
41
|
+
public List<TaskSource> getEncoderTaskSources();
|
|
42
|
+
|
|
43
|
+
public void setFormatterTaskSource(TaskSource v);
|
|
44
|
+
public TaskSource getFormatterTaskSource();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected List<EncoderPlugin> newEncoderPlugins(RunnerTask task)
|
|
48
|
+
{
|
|
49
|
+
return Encoders.newEncoderPlugins(Exec.session(), task.getEncoderConfigs());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected FormatterPlugin newFormatterPlugin(RunnerTask task)
|
|
53
|
+
{
|
|
54
|
+
return Exec.newPlugin(FormatterPlugin.class, task.getFormatterConfig().get(PluginType.class, "type"));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Override
|
|
58
|
+
public NextConfig transaction(ConfigSource config,
|
|
59
|
+
final Schema schema, final int processorCount,
|
|
60
|
+
final OutputPlugin.Control control)
|
|
61
|
+
{
|
|
62
|
+
final RunnerTask task = config.loadConfig(RunnerTask.class);
|
|
63
|
+
final List<EncoderPlugin> encoderPlugins = newEncoderPlugins(task);
|
|
64
|
+
final FormatterPlugin formatterPlugin = newFormatterPlugin(task);
|
|
65
|
+
|
|
66
|
+
return fileOutputPlugin.transaction(config, processorCount, new FileOutputPlugin.Control() {
|
|
67
|
+
public List<CommitReport> run(final TaskSource fileOutputTaskSource)
|
|
68
|
+
{
|
|
69
|
+
final List<CommitReport> commitReports = new ArrayList<CommitReport>();
|
|
70
|
+
Encoders.transaction(encoderPlugins, task.getEncoderConfigs(), new Encoders.Control() {
|
|
71
|
+
public void run(final List<TaskSource> encoderTaskSources)
|
|
72
|
+
{
|
|
73
|
+
formatterPlugin.transaction(task.getFormatterConfig(), schema, new FormatterPlugin.Control() {
|
|
74
|
+
public void run(final TaskSource formatterTaskSource)
|
|
75
|
+
{
|
|
76
|
+
task.setFileOutputTaskSource(fileOutputTaskSource);
|
|
77
|
+
task.setEncoderTaskSources(encoderTaskSources);
|
|
78
|
+
task.setFormatterTaskSource(formatterTaskSource);
|
|
79
|
+
commitReports.addAll(control.run(task.dump()));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return commitReports;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Override
|
|
90
|
+
public TransactionalPageOutput open(TaskSource taskSource, Schema schema, int processorIndex)
|
|
91
|
+
{
|
|
92
|
+
final RunnerTask task = taskSource.loadTask(RunnerTask.class);
|
|
93
|
+
List<EncoderPlugin> encoderPlugins = newEncoderPlugins(task);
|
|
94
|
+
FormatterPlugin formatterPlugin = newFormatterPlugin(task);
|
|
95
|
+
|
|
96
|
+
TransactionalFileOutput tran = null;
|
|
97
|
+
FileOutput fileOutput = null;
|
|
98
|
+
PageOutput output = null;
|
|
99
|
+
try {
|
|
100
|
+
fileOutput = tran = fileOutputPlugin.open(task.getFileOutputTaskSource(), processorIndex);
|
|
101
|
+
|
|
102
|
+
fileOutput = Encoders.open(encoderPlugins, task.getEncoderTaskSources(), fileOutput);
|
|
103
|
+
output = formatterPlugin.open(task.getFormatterTaskSource(), schema, fileOutput);
|
|
104
|
+
fileOutput = null;
|
|
105
|
+
|
|
106
|
+
TransactionalPageOutput ret = new DelegateTransactionalPageOutput(tran, output);
|
|
107
|
+
tran = null;
|
|
108
|
+
output = null;
|
|
109
|
+
return ret;
|
|
110
|
+
|
|
111
|
+
} finally {
|
|
112
|
+
if (output != null) {
|
|
113
|
+
output.close();
|
|
114
|
+
}
|
|
115
|
+
if (fileOutput != null) {
|
|
116
|
+
fileOutput.close();
|
|
117
|
+
}
|
|
118
|
+
if (tran != null) {
|
|
119
|
+
tran.abort();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private static class DelegateTransactionalPageOutput
|
|
125
|
+
implements TransactionalPageOutput
|
|
126
|
+
{
|
|
127
|
+
private final Transactional tran;
|
|
128
|
+
private final PageOutput output;
|
|
129
|
+
|
|
130
|
+
public DelegateTransactionalPageOutput(Transactional tran, PageOutput output)
|
|
131
|
+
{
|
|
132
|
+
this.tran = tran;
|
|
133
|
+
this.output = output;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Override
|
|
137
|
+
public void add(Page page)
|
|
138
|
+
{
|
|
139
|
+
output.add(page);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@Override
|
|
143
|
+
public void finish()
|
|
144
|
+
{
|
|
145
|
+
output.finish();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@Override
|
|
149
|
+
public void close()
|
|
150
|
+
{
|
|
151
|
+
output.close();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@Override
|
|
155
|
+
public void abort()
|
|
156
|
+
{
|
|
157
|
+
tran.abort();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@Override
|
|
161
|
+
public CommitReport commit()
|
|
162
|
+
{
|
|
163
|
+
// TODO check finished
|
|
164
|
+
return tran.commit();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package org.embulk.spi;
|
|
2
|
+
|
|
3
|
+
import org.embulk.config.TaskSource;
|
|
4
|
+
import org.embulk.config.ConfigSource;
|
|
5
|
+
|
|
6
|
+
public interface FormatterPlugin
|
|
7
|
+
{
|
|
8
|
+
public interface Control
|
|
9
|
+
{
|
|
10
|
+
public void run(TaskSource taskSource);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public void transaction(ConfigSource config, Schema schema,
|
|
14
|
+
FormatterPlugin.Control control);
|
|
15
|
+
|
|
16
|
+
public PageOutput open(TaskSource taskSource, Schema schema,
|
|
17
|
+
FileOutput output);
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package org.embulk.spi;
|
|
2
|
+
|
|
3
|
+
import java.util.List;
|
|
4
|
+
import org.embulk.config.TaskSource;
|
|
5
|
+
import org.embulk.config.ConfigSource;
|
|
6
|
+
import org.embulk.config.NextConfig;
|
|
7
|
+
import org.embulk.config.CommitReport;
|
|
8
|
+
|
|
9
|
+
public interface InputPlugin
|
|
10
|
+
{
|
|
11
|
+
public interface Control
|
|
12
|
+
{
|
|
13
|
+
public List<CommitReport> run(TaskSource taskSource, Schema schema, int processorCount);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public NextConfig transaction(ConfigSource config, InputPlugin.Control control);
|
|
17
|
+
|
|
18
|
+
public CommitReport run(TaskSource taskSource, Schema schema, int processorIndex,
|
|
19
|
+
PageOutput output);
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package org.embulk.spi;
|
|
2
|
+
|
|
3
|
+
import java.util.List;
|
|
4
|
+
import org.embulk.config.TaskSource;
|
|
5
|
+
import org.embulk.config.ConfigSource;
|
|
6
|
+
import org.embulk.config.NextConfig;
|
|
7
|
+
import org.embulk.config.CommitReport;
|
|
8
|
+
|
|
9
|
+
public interface OutputPlugin
|
|
10
|
+
{
|
|
11
|
+
public interface Control
|
|
12
|
+
{
|
|
13
|
+
public List<CommitReport> run(TaskSource taskSource);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public NextConfig transaction(ConfigSource config,
|
|
17
|
+
Schema schema, int processorCount,
|
|
18
|
+
OutputPlugin.Control control);
|
|
19
|
+
|
|
20
|
+
public TransactionalPageOutput open(TaskSource taskSource, Schema schema, int processorIndex);
|
|
21
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package org.embulk.spi;
|
|
2
|
+
|
|
3
|
+
import java.util.List;
|
|
4
|
+
|
|
5
|
+
public class Page
|
|
6
|
+
{
|
|
7
|
+
private final Buffer buffer;
|
|
8
|
+
private List<String> stringReferences;
|
|
9
|
+
|
|
10
|
+
protected Page(Buffer buffer)
|
|
11
|
+
{
|
|
12
|
+
this.buffer = buffer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static Page allocate(int length)
|
|
16
|
+
{
|
|
17
|
+
return new Page(Buffer.allocate(length));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static Page wrap(Buffer buffer)
|
|
21
|
+
{
|
|
22
|
+
return new Page(buffer);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public Page setStringReferences(List<String> values)
|
|
26
|
+
{
|
|
27
|
+
this.stringReferences = values;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public String getStringReference(int index)
|
|
32
|
+
{
|
|
33
|
+
return stringReferences.get(index);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public void release()
|
|
37
|
+
{
|
|
38
|
+
buffer.release();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public Buffer buffer()
|
|
42
|
+
{
|
|
43
|
+
return buffer;
|
|
44
|
+
}
|
|
45
|
+
}
|