embulk 0.8.25-java → 0.8.26-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/build.gradle +16 -1
- data/embulk-cli/src/main/java/org/embulk/cli/EmbulkMigrate.java +6 -3
- data/embulk-core/build.gradle +7 -0
- data/embulk-core/src/main/java/org/embulk/EmbulkService.java +2 -0
- data/embulk-core/src/main/java/org/embulk/plugin/InjectedPluginSource.java +1 -1
- data/embulk-core/src/main/java/org/embulk/plugin/MavenPluginType.java +21 -6
- data/embulk-core/src/main/java/org/embulk/plugin/PluginClassLoader.java +42 -2
- data/embulk-core/src/main/java/org/embulk/plugin/PluginSourceNotMatchException.java +6 -0
- data/embulk-core/src/main/java/org/embulk/plugin/PluginType.java +2 -1
- data/embulk-core/src/main/java/org/embulk/plugin/jar/InvalidJarPluginException.java +14 -0
- data/embulk-core/src/main/java/org/embulk/plugin/jar/JarPluginLoader.java +205 -0
- data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenArtifactFinder.java +134 -0
- data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenArtifactNotFoundException.java +20 -0
- data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenPluginSource.java +187 -0
- data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenPluginSourceModule.java +22 -0
- data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenRepositoryNotFoundException.java +31 -0
- data/embulk-core/src/main/resources/embulk/parent_first_packages.properties +3 -1
- data/embulk-core/src/main/resources/embulk/parent_first_resources.properties +2 -1
- data/embulk-core/src/test/java/org/embulk/EmbulkTestRuntime.java +8 -0
- data/embulk-core/src/test/java/org/embulk/plugin/TestPluginType.java +24 -0
- data/embulk-core/src/test/java/org/embulk/plugin/TestPluginTypeSerDe.java +17 -0
- data/embulk-core/src/test/java/org/embulk/plugin/jar/ExampleJarSpiV0.java +9 -0
- data/embulk-core/src/test/java/org/embulk/plugin/jar/JarBuilder.java +101 -0
- data/embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java +60 -0
- data/embulk-core/src/test/java/org/embulk/plugin/maven/TestMavenArtifactFinder.java +41 -0
- data/embulk-core/src/test/resources/m2.test/.gitignore +1 -0
- data/embulk-core/src/test/resources/m2.test/org/embulk/example/embulk-example-maven-artifact/0.1.2/embulk-example-maven-artifact-0.1.2.jar +0 -0
- data/embulk-core/src/test/resources/m2.test/org/embulk/example/embulk-example-maven-artifact/0.1.2/embulk-example-maven-artifact-0.1.2.jar.sha1 +1 -0
- data/embulk-core/src/test/resources/m2.test/org/embulk/example/embulk-example-maven-artifact/0.1.2/embulk-example-maven-artifact-0.1.2.pom +9 -0
- data/embulk-core/src/test/resources/m2.test/org/embulk/example/embulk-example-maven-artifact/0.1.2/embulk-example-maven-artifact-0.1.2.pom.sha1 +1 -0
- data/embulk-docs/src/built-in.rst +26 -9
- data/embulk-docs/src/release.rst +1 -0
- data/embulk-docs/src/release/release-0.8.26.rst +16 -0
- data/embulk-standards/src/main/java/org/embulk/standards/ConfigInputPlugin.java +170 -0
- data/embulk-standards/src/main/java/org/embulk/standards/StandardPluginModule.java +1 -0
- data/lib/embulk/version.rb +1 -1
- metadata +58 -29
@@ -2,6 +2,7 @@ package org.embulk.plugin;
|
|
2
2
|
|
3
3
|
import static org.junit.Assert.assertEquals;
|
4
4
|
import static org.junit.Assert.assertFalse;
|
5
|
+
import static org.junit.Assert.assertNull;
|
5
6
|
import static org.junit.Assert.assertTrue;
|
6
7
|
|
7
8
|
import java.util.HashMap;
|
@@ -54,6 +55,29 @@ public class TestPluginType
|
|
54
55
|
assertEquals("e", mavenType.getName());
|
55
56
|
assertEquals("org.embulk.foobar", mavenType.getGroup());
|
56
57
|
assertEquals("0.1.2", mavenType.getVersion());
|
58
|
+
assertNull(mavenType.getClassifier());
|
57
59
|
assertEquals("maven:org.embulk.foobar:e:0.1.2", mavenType.getFullName());
|
58
60
|
}
|
61
|
+
|
62
|
+
@Test
|
63
|
+
public void testMappingMavenWithClassifier()
|
64
|
+
{
|
65
|
+
HashMap<String, String> mapping = new HashMap<String, String>();
|
66
|
+
mapping.put("source", "maven");
|
67
|
+
mapping.put("name", "e");
|
68
|
+
mapping.put("group", "org.embulk.foobar");
|
69
|
+
mapping.put("version", "0.1.2");
|
70
|
+
mapping.put("classifier", "bar");
|
71
|
+
|
72
|
+
PluginType type = PluginType.createFromStringMapForTesting(mapping);
|
73
|
+
assertTrue(type instanceof MavenPluginType);
|
74
|
+
assertEquals(PluginSource.Type.MAVEN, type.getSourceType());
|
75
|
+
MavenPluginType mavenType = (MavenPluginType) type;
|
76
|
+
assertTrue(mavenType.equals(mavenType));
|
77
|
+
assertEquals("e", mavenType.getName());
|
78
|
+
assertEquals("org.embulk.foobar", mavenType.getGroup());
|
79
|
+
assertEquals("0.1.2", mavenType.getVersion());
|
80
|
+
assertEquals("bar", mavenType.getClassifier());
|
81
|
+
assertEquals("maven:org.embulk.foobar:e:0.1.2:bar", mavenType.getFullName());
|
82
|
+
}
|
59
83
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
package org.embulk.plugin;
|
2
2
|
|
3
3
|
import static org.junit.Assert.assertEquals;
|
4
|
+
import static org.junit.Assert.assertNull;
|
4
5
|
import static org.junit.Assert.assertTrue;
|
5
6
|
|
6
7
|
import org.embulk.EmbulkTestRuntime;
|
@@ -46,5 +47,21 @@ public class TestPluginTypeSerDe
|
|
46
47
|
assertEquals(mavenPluginType.getName(), "foo");
|
47
48
|
assertEquals(mavenPluginType.getGroup(), "org.embulk.bar");
|
48
49
|
assertEquals(mavenPluginType.getVersion(), "0.1.2");
|
50
|
+
assertNull(mavenPluginType.getClassifier());
|
51
|
+
}
|
52
|
+
|
53
|
+
@Test
|
54
|
+
public void testParseTypeMavenWithClassifier()
|
55
|
+
{
|
56
|
+
PluginType pluginType = testRuntime.getModelManager().readObjectWithConfigSerDe(
|
57
|
+
PluginType.class,
|
58
|
+
"{ \"name\": \"foo\", \"source\": \"maven\", \"group\": \"org.embulk.bar\", \"version\": \"0.1.2\", \"classifier\": \"foo\" }");
|
59
|
+
assertTrue(pluginType instanceof MavenPluginType);
|
60
|
+
assertEquals(PluginSource.Type.MAVEN, pluginType.getSourceType());
|
61
|
+
MavenPluginType mavenPluginType = (MavenPluginType) pluginType;
|
62
|
+
assertEquals(mavenPluginType.getName(), "foo");
|
63
|
+
assertEquals(mavenPluginType.getGroup(), "org.embulk.bar");
|
64
|
+
assertEquals(mavenPluginType.getVersion(), "0.1.2");
|
65
|
+
assertEquals(mavenPluginType.getClassifier(), "foo");
|
49
66
|
}
|
50
67
|
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
package org.embulk.plugin.jar;
|
2
|
+
|
3
|
+
import java.nio.file.Files;
|
4
|
+
import java.nio.file.Path;
|
5
|
+
import java.nio.file.Paths;
|
6
|
+
import java.util.HashMap;
|
7
|
+
import java.util.TreeSet;
|
8
|
+
import java.util.jar.Attributes;
|
9
|
+
import java.util.jar.JarEntry;
|
10
|
+
import java.util.jar.JarOutputStream;
|
11
|
+
import java.util.jar.Manifest;
|
12
|
+
|
13
|
+
public class JarBuilder
|
14
|
+
{
|
15
|
+
public JarBuilder()
|
16
|
+
{
|
17
|
+
this.manifest = new Manifest();
|
18
|
+
this.entries = new HashMap<String, Path>();
|
19
|
+
}
|
20
|
+
|
21
|
+
public void build(final Path pathToExistingFile)
|
22
|
+
throws Exception
|
23
|
+
{
|
24
|
+
try (final JarOutputStream output = buildPluginJar(pathToExistingFile, this.manifest)) {
|
25
|
+
for (String entryName : new TreeSet<String>(this.entries.keySet())) {
|
26
|
+
final Path pathToRealFile = this.entries.get(entryName);
|
27
|
+
if (pathToRealFile == null) {
|
28
|
+
final JarEntry entry = new JarEntry(entryName + "/");
|
29
|
+
entry.setMethod(JarEntry.STORED);
|
30
|
+
entry.setSize(0);
|
31
|
+
entry.setCrc(0);
|
32
|
+
output.putNextEntry(entry);
|
33
|
+
output.closeEntry();
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
final JarEntry entry = new JarEntry(entryName);
|
37
|
+
output.putNextEntry(entry);
|
38
|
+
Files.copy(pathToRealFile, output);
|
39
|
+
output.closeEntry();
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
public void addClass(final Class<?> klass)
|
46
|
+
throws Exception
|
47
|
+
{
|
48
|
+
final Path classFileRelativePath = getClassFileRelativePath(klass);
|
49
|
+
final Path classFileFullPath = getClassFileFullPath(klass);
|
50
|
+
this.addFile(classFileRelativePath.toString(), classFileFullPath);
|
51
|
+
|
52
|
+
Path directoryPath = classFileRelativePath.getParent();
|
53
|
+
while (directoryPath != null) {
|
54
|
+
this.addDirectoryIfAbsent(directoryPath.toString());
|
55
|
+
directoryPath = directoryPath.getParent();
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
public void addManifestV0(final String embulkPluginMainClass)
|
60
|
+
{
|
61
|
+
final Attributes attributes = this.manifest.getMainAttributes();
|
62
|
+
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
63
|
+
attributes.putValue(MANIFEST_PLUGIN_SPI_VERSION, "0");
|
64
|
+
attributes.putValue(MANIFEST_PLUGIN_MAIN_CLASS, embulkPluginMainClass);
|
65
|
+
}
|
66
|
+
|
67
|
+
private void addDirectoryIfAbsent(final String name)
|
68
|
+
{
|
69
|
+
if (!(this.entries.containsKey(name))) {
|
70
|
+
this.entries.put(name, null);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
private void addFile(final String name, final Path pathToRealFile)
|
75
|
+
{
|
76
|
+
this.entries.put(name, pathToRealFile);
|
77
|
+
}
|
78
|
+
|
79
|
+
private JarOutputStream buildPluginJar(final Path pathToExistingFile, final Manifest embeddedManifest)
|
80
|
+
throws Exception
|
81
|
+
{
|
82
|
+
return new JarOutputStream(Files.newOutputStream(pathToExistingFile), embeddedManifest);
|
83
|
+
}
|
84
|
+
|
85
|
+
private Path getClassFileRelativePath(final Class<?> klass)
|
86
|
+
{
|
87
|
+
return Paths.get(klass.getName().replace('.', '/') + ".class");
|
88
|
+
}
|
89
|
+
|
90
|
+
private Path getClassFileFullPath(final Class<?> klass)
|
91
|
+
throws Exception
|
92
|
+
{
|
93
|
+
return Paths.get(klass.getClassLoader().getResource(klass.getName().replace('.', '/') + ".class").toURI());
|
94
|
+
}
|
95
|
+
|
96
|
+
private final Manifest manifest;
|
97
|
+
private final HashMap<String, Path> entries;
|
98
|
+
|
99
|
+
private static final String MANIFEST_PLUGIN_SPI_VERSION = "Embulk-Plugin-Spi-Version";
|
100
|
+
private static final String MANIFEST_PLUGIN_MAIN_CLASS = "Embulk-Plugin-Main-Class";
|
101
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
package org.embulk.plugin.jar;
|
2
|
+
|
3
|
+
import static org.junit.Assert.assertEquals;
|
4
|
+
import static org.junit.Assert.assertTrue;
|
5
|
+
|
6
|
+
import java.nio.file.Files;
|
7
|
+
import java.nio.file.Path;
|
8
|
+
import java.nio.file.Paths;
|
9
|
+
import org.embulk.EmbulkTestRuntime;
|
10
|
+
import org.junit.Rule;
|
11
|
+
import org.junit.Test;
|
12
|
+
import org.junit.rules.TemporaryFolder;
|
13
|
+
|
14
|
+
public class TestJarPluginLoader
|
15
|
+
{
|
16
|
+
@Rule
|
17
|
+
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
18
|
+
|
19
|
+
@Rule
|
20
|
+
public EmbulkTestRuntime testRuntime = new EmbulkTestRuntime();
|
21
|
+
|
22
|
+
@Test
|
23
|
+
public void test() throws Exception
|
24
|
+
{
|
25
|
+
final Path jarPath = createTemporaryJarFile();
|
26
|
+
|
27
|
+
final JarBuilder jarBuilder = new JarBuilder();
|
28
|
+
jarBuilder.addManifestV0(ExampleJarSpiV0.class.getName());
|
29
|
+
jarBuilder.addClass(ExampleJarSpiV0.class);
|
30
|
+
jarBuilder.build(jarPath);
|
31
|
+
|
32
|
+
final Class<?> loadedClass;
|
33
|
+
try (final JarPluginLoader loader = JarPluginLoader.load(jarPath, testRuntime.getPluginClassLoaderFactory())) {
|
34
|
+
assertEquals(0, loader.getPluginSpiVersion());
|
35
|
+
loadedClass = loader.getPluginMainClass();
|
36
|
+
}
|
37
|
+
|
38
|
+
final Object instanceObject = loadedClass.newInstance();
|
39
|
+
assertTrue(instanceObject instanceof ExampleJarSpiV0);
|
40
|
+
|
41
|
+
final ExampleJarSpiV0 instance = (ExampleJarSpiV0) instanceObject;
|
42
|
+
assertEquals("foobar", instance.getTestString());
|
43
|
+
}
|
44
|
+
|
45
|
+
private Path createTemporaryJarFile() throws Exception
|
46
|
+
{
|
47
|
+
final String temporaryDirectoryString =
|
48
|
+
System.getProperty("org.embulk.plugin.jar.TestJarPluginLoader.temporaryDirectory");
|
49
|
+
|
50
|
+
final Path temporaryDirectoryPath;
|
51
|
+
if (temporaryDirectoryString == null) {
|
52
|
+
temporaryDirectoryPath = temporaryFolder.getRoot().toPath();
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
temporaryDirectoryPath = Paths.get(temporaryDirectoryString);
|
56
|
+
}
|
57
|
+
|
58
|
+
return Files.createTempFile(temporaryDirectoryPath, "testplugin", ".jar");
|
59
|
+
}
|
60
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
package org.embulk.plugin.maven;
|
2
|
+
|
3
|
+
import static org.junit.Assert.assertEquals;
|
4
|
+
import static org.junit.Assert.assertFalse;
|
5
|
+
import static org.junit.Assert.assertNull;
|
6
|
+
import static org.junit.Assert.assertTrue;
|
7
|
+
|
8
|
+
import java.net.URL;
|
9
|
+
import java.net.URISyntaxException;
|
10
|
+
import java.nio.file.Path;
|
11
|
+
import java.nio.file.Paths;
|
12
|
+
import org.junit.Test;
|
13
|
+
|
14
|
+
public class TestMavenArtifactFinder
|
15
|
+
{
|
16
|
+
@Test
|
17
|
+
public void testArtifacts() throws Exception
|
18
|
+
{
|
19
|
+
final Path basePath = getMavenPath();
|
20
|
+
final MavenArtifactFinder finder = MavenArtifactFinder.create(basePath);
|
21
|
+
assertEquals(buildExpectedPath(basePath, GROUP_DIRECTORY, "embulk-example-maven-artifact", "0.1.2"),
|
22
|
+
finder.findMavenArtifactJar("org.embulk.example", "embulk-example-maven-artifact", null, "0.1.2"));
|
23
|
+
}
|
24
|
+
|
25
|
+
private Path getMavenPath() throws URISyntaxException
|
26
|
+
{
|
27
|
+
return Paths.get(this.getClass().getClassLoader().getResource("m2.test").toURI());
|
28
|
+
}
|
29
|
+
|
30
|
+
private Path buildExpectedPath(
|
31
|
+
final Path basePath, final Path groupDirectory, final String artifactId, final String version)
|
32
|
+
{
|
33
|
+
return basePath
|
34
|
+
.resolve(groupDirectory)
|
35
|
+
.resolve(artifactId)
|
36
|
+
.resolve(version)
|
37
|
+
.resolve(artifactId + "-" + version + ".jar");
|
38
|
+
}
|
39
|
+
|
40
|
+
private static final Path GROUP_DIRECTORY = Paths.get("org").resolve("embulk").resolve("example");
|
41
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
_remote.repositories
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
5a068856f7c40ef2cb376018c213f622f3a114d8
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
4
|
+
<groupId>org.embulk.example</groupId>
|
5
|
+
<artifactId>embulk-example-maven-artifact</artifactId>
|
6
|
+
<version>0.1.2</version>
|
7
|
+
<packaging>jar</packaging>
|
8
|
+
<name>embulk-example-maven-artifact</name>
|
9
|
+
</project>
|
@@ -0,0 +1 @@
|
|
1
|
+
63a970e5288cd0452f0558f9dc8ea8498bc8e5b4
|
@@ -329,21 +329,38 @@ The ``json`` parser plugin parses a JSON file that contains a sequence of JSON o
|
|
329
329
|
|
330
330
|
.. code-block:: javascript
|
331
331
|
|
332
|
-
{"time":1455829282,"ip":"93.184.216.34","name":frsyuki}
|
333
|
-
{"time":1455829282,"ip":"172.36.8.109":sadayuki}
|
334
|
-
{"time":1455829284,"ip":"example.com","name":Treasure Data}
|
335
|
-
{"time":1455829282,"ip":"10.98.43.1","name":MessagePack}
|
332
|
+
{"time":1455829282,"ip":"93.184.216.34","name":"frsyuki"}
|
333
|
+
{"time":1455829282,"ip":"172.36.8.109", "name":"sadayuki"}
|
334
|
+
{"time":1455829284,"ip":"example.com","name":"Treasure Data"}
|
335
|
+
{"time":1455829282,"ip":"10.98.43.1","name":"MessagePack"}
|
336
336
|
|
337
337
|
``json`` parser plugin outputs a single record named "record" (type is json).
|
338
338
|
|
339
339
|
Options
|
340
340
|
~~~~~~~~
|
341
341
|
|
342
|
-
|
343
|
-
| name | type | description |
|
344
|
-
|
345
|
-
| stop\_on\_invalid\_record | boolean | Stop bulk load transaction if a file includes invalid record (such as invalid json) | ``false`` by default
|
346
|
-
|
342
|
+
+----------------------------+----------+----------------------------------------------------------------------------------------------------------------+------------------------------+
|
343
|
+
| name | type | description | required? |
|
344
|
+
+============================+==========+================================================================================================================+==============================+
|
345
|
+
| stop\_on\_invalid\_record | boolean | Stop bulk load transaction if a file includes invalid record (such as invalid json) | ``false`` by default |
|
346
|
+
+----------------------------+----------+----------------------------------------------------------------------------------------------------------------+------------------------------+
|
347
|
+
| invalid\_string\_escapes | enum | Escape strategy of invalid json string such as using invalid ``\`` like ``\a``. (PASSTHROUGH, SKIP, UNESCAPE) | ``PASSTHROUGH`` by default |
|
348
|
+
+----------------------------+----------+----------------------------------------------------------------------------------------------------------------+------------------------------+
|
349
|
+
|
350
|
+
|
351
|
+
if you set invalid\_string\_escapes and appear invalid JSON string (such as ``\a``), it makes following the action.
|
352
|
+
|
353
|
+
+----------------------------+------------------+
|
354
|
+
| invalid\_string\_escapes | convert to |
|
355
|
+
+============================+==================+
|
356
|
+
| PASSTHROUGH *1 | ``\a`` |
|
357
|
+
+----------------------------+------------------+
|
358
|
+
| SKIP | empty string |
|
359
|
+
+----------------------------+------------------+
|
360
|
+
| UNESCAPE | ``a`` |
|
361
|
+
+----------------------------+------------------+
|
362
|
+
|
363
|
+
(\*1): Throwing an exception.
|
347
364
|
|
348
365
|
|
349
366
|
Example
|
data/embulk-docs/src/release.rst
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
Release 0.8.26
|
2
|
+
==================================
|
3
|
+
|
4
|
+
General Changes
|
5
|
+
------------------
|
6
|
+
|
7
|
+
* Add ConfigInputPlugin for easier testing [#678]
|
8
|
+
* Add MavenPluginSource to load JAR-based plugins into Embulk [#686] [#687] [#684] [#701]
|
9
|
+
* Fix the "migrate" subcommand to handle build.gradle correctly [#702] [#703]
|
10
|
+
* Fix parent_first_{packages,resources}.properties to delegate msgpack class loading to parent [#694]
|
11
|
+
* Fix documents [#683] [#685]
|
12
|
+
|
13
|
+
|
14
|
+
Release Date
|
15
|
+
------------------
|
16
|
+
2017-07-01
|
@@ -0,0 +1,170 @@
|
|
1
|
+
package org.embulk.standards;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.databind.JsonNode;
|
4
|
+
import java.util.List;
|
5
|
+
import org.embulk.config.Config;
|
6
|
+
import org.embulk.config.ConfigDiff;
|
7
|
+
import org.embulk.config.ConfigSource;
|
8
|
+
import org.embulk.config.Task;
|
9
|
+
import org.embulk.config.TaskReport;
|
10
|
+
import org.embulk.config.TaskSource;
|
11
|
+
import org.embulk.spi.Column;
|
12
|
+
import org.embulk.spi.ColumnVisitor;
|
13
|
+
import org.embulk.spi.DataException;
|
14
|
+
import org.embulk.spi.Exec;
|
15
|
+
import org.embulk.spi.InputPlugin;
|
16
|
+
import org.embulk.spi.PageBuilder;
|
17
|
+
import org.embulk.spi.PageOutput;
|
18
|
+
import org.embulk.spi.Schema;
|
19
|
+
import org.embulk.spi.SchemaConfig;
|
20
|
+
import org.embulk.spi.json.JsonParser;
|
21
|
+
import org.embulk.spi.json.JsonParseException;
|
22
|
+
import org.embulk.spi.time.TimestampParseException;
|
23
|
+
import org.embulk.spi.time.TimestampParser;
|
24
|
+
import org.embulk.spi.util.Timestamps;
|
25
|
+
|
26
|
+
public class ConfigInputPlugin
|
27
|
+
implements InputPlugin
|
28
|
+
{
|
29
|
+
private interface PluginTask
|
30
|
+
extends Task, TimestampParser.Task
|
31
|
+
{
|
32
|
+
@Config("columns")
|
33
|
+
SchemaConfig getSchemaConfig();
|
34
|
+
|
35
|
+
@Config("values")
|
36
|
+
List<List<List<JsonNode>>> getValues();
|
37
|
+
}
|
38
|
+
|
39
|
+
@Override
|
40
|
+
public ConfigDiff transaction(ConfigSource config,
|
41
|
+
InputPlugin.Control control)
|
42
|
+
{
|
43
|
+
final PluginTask task = config.loadConfig(PluginTask.class);
|
44
|
+
final Schema schema = task.getSchemaConfig().toSchema();
|
45
|
+
final List<List<List<JsonNode>>> values = task.getValues();
|
46
|
+
final int taskCount = values.size();
|
47
|
+
|
48
|
+
return resume(task.dump(), schema, taskCount, control);
|
49
|
+
}
|
50
|
+
|
51
|
+
@Override
|
52
|
+
public ConfigDiff resume(TaskSource taskSource,
|
53
|
+
Schema schema, int taskCount,
|
54
|
+
InputPlugin.Control control)
|
55
|
+
{
|
56
|
+
control.run(taskSource, schema, taskCount);
|
57
|
+
return Exec.newConfigDiff();
|
58
|
+
}
|
59
|
+
|
60
|
+
@Override
|
61
|
+
public void cleanup(TaskSource taskSource,
|
62
|
+
Schema schema, int taskCount,
|
63
|
+
List<TaskReport> successTaskReports)
|
64
|
+
{
|
65
|
+
}
|
66
|
+
|
67
|
+
@Override
|
68
|
+
public TaskReport run(TaskSource taskSource,
|
69
|
+
Schema schema, int taskIndex,
|
70
|
+
PageOutput output)
|
71
|
+
{
|
72
|
+
final PluginTask task = taskSource.loadTask(PluginTask.class);
|
73
|
+
final List<List<JsonNode>> taskValues = task.getValues().get(taskIndex);
|
74
|
+
final TimestampParser[] timestampParsers = Timestamps.newTimestampColumnParsers(task, task.getSchemaConfig());
|
75
|
+
final JsonParser jsonParser = new JsonParser();
|
76
|
+
|
77
|
+
try (final PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), schema, output)) {
|
78
|
+
for (final List<JsonNode> rowValues : taskValues) {
|
79
|
+
schema.visitColumns(new ColumnVisitor() {
|
80
|
+
public void booleanColumn(Column column)
|
81
|
+
{
|
82
|
+
final JsonNode value = rowValues.get(column.getIndex());
|
83
|
+
if (value == null || value.isNull()) {
|
84
|
+
pageBuilder.setNull(column);
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
pageBuilder.setBoolean(column, value.asBoolean());
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
public void longColumn(Column column)
|
92
|
+
{
|
93
|
+
final JsonNode value = rowValues.get(column.getIndex());
|
94
|
+
if (value == null || value.isNull()) {
|
95
|
+
pageBuilder.setNull(column);
|
96
|
+
}
|
97
|
+
else {
|
98
|
+
pageBuilder.setLong(column, value.asLong());
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
public void doubleColumn(Column column)
|
103
|
+
{
|
104
|
+
final JsonNode value = rowValues.get(column.getIndex());
|
105
|
+
if (value == null || value.isNull()) {
|
106
|
+
pageBuilder.setNull(column);
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
pageBuilder.setDouble(column, value.asDouble());
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
public void stringColumn(Column column)
|
114
|
+
{
|
115
|
+
final JsonNode value = rowValues.get(column.getIndex());
|
116
|
+
if (value == null || value.isNull()) {
|
117
|
+
pageBuilder.setNull(column);
|
118
|
+
}
|
119
|
+
else {
|
120
|
+
pageBuilder.setString(column, value.asText());
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
public void timestampColumn(Column column)
|
125
|
+
{
|
126
|
+
final JsonNode value = rowValues.get(column.getIndex());
|
127
|
+
if (value == null || value.isNull()) {
|
128
|
+
pageBuilder.setNull(column);
|
129
|
+
}
|
130
|
+
else {
|
131
|
+
try {
|
132
|
+
pageBuilder.setTimestamp(column,
|
133
|
+
timestampParsers[column.getIndex()].parse(value.asText()));
|
134
|
+
}
|
135
|
+
catch (TimestampParseException ex) {
|
136
|
+
throw new DataException(ex);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
public void jsonColumn(Column column)
|
142
|
+
{
|
143
|
+
final JsonNode value = rowValues.get(column.getIndex());
|
144
|
+
if (value == null || value.isNull()) {
|
145
|
+
pageBuilder.setNull(column);
|
146
|
+
}
|
147
|
+
else {
|
148
|
+
try {
|
149
|
+
pageBuilder.setJson(column, jsonParser.parse(value.toString()));
|
150
|
+
}
|
151
|
+
catch (JsonParseException ex) {
|
152
|
+
throw new DataException(ex);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
});
|
157
|
+
pageBuilder.addRecord();
|
158
|
+
}
|
159
|
+
pageBuilder.finish();
|
160
|
+
}
|
161
|
+
|
162
|
+
return Exec.newTaskReport();
|
163
|
+
}
|
164
|
+
|
165
|
+
@Override
|
166
|
+
public ConfigDiff guess(ConfigSource config)
|
167
|
+
{
|
168
|
+
return Exec.newConfigDiff();
|
169
|
+
}
|
170
|
+
}
|