embulk-filter-json_csv2arrayofobjects 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ package org.embulk.filter.json_csv2arrayofobjects;
2
+
3
+ import org.embulk.EmbulkTestRuntime;
4
+ import org.embulk.config.ConfigException;
5
+ import org.embulk.config.ConfigLoader;
6
+ import org.embulk.config.ConfigSource;
7
+ import org.embulk.filter.json_csv2arrayofobjects.JsonCsv2arrayofobjectsFilterPlugin.PluginTask;
8
+ import org.embulk.spi.Exec;
9
+ import org.embulk.spi.Schema;
10
+ import org.embulk.spi.SchemaConfigException;
11
+ import org.embulk.spi.type.Types;
12
+ import org.junit.Rule;
13
+ import org.junit.Test;
14
+
15
+ public class TestJsonCsv2arrayofobjectsFilterPlugin
16
+ {
17
+ @Rule
18
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
19
+
20
+ public JsonCsv2arrayofobjectsFilterPlugin plugin = new JsonCsv2arrayofobjectsFilterPlugin();
21
+
22
+ public static PluginTask taskFromYamlString(String... lines)
23
+ {
24
+ StringBuilder builder = new StringBuilder();
25
+ for (String line : lines) {
26
+ builder.append(line).append("\n");
27
+ }
28
+ String yamlString = builder.toString();
29
+
30
+ ConfigLoader loader = new ConfigLoader(Exec.getModelManager());
31
+ ConfigSource config = loader.fromYamlString(yamlString);
32
+ return config.loadConfig(PluginTask.class);
33
+ }
34
+
35
+ @Test(expected = SchemaConfigException.class)
36
+ public void validateColumnExists()
37
+ {
38
+ PluginTask task = taskFromYamlString(
39
+ "type: json_csv2arrayofobjects",
40
+ "column: json_payload1",
41
+ "key: key",
42
+ "output_keys:",
43
+ " - {name: name, type: string}"
44
+ );
45
+ Schema inputSchema = Schema.builder()
46
+ .add("json_payload", Types.STRING)
47
+ .build();
48
+ plugin.validate(task, inputSchema);
49
+ }
50
+
51
+ @Test(expected = ConfigException.class)
52
+ public void validateDelimiterAndSubDelimiterShouldNotBeEqual()
53
+ {
54
+ PluginTask task = taskFromYamlString(
55
+ "type: json_csv2arrayofobjects",
56
+ "column: json_payload",
57
+ "key: key",
58
+ "delimiter: \"-\"",
59
+ "output_keys:",
60
+ " - {name: name, type: string}"
61
+ );
62
+ Schema inputSchema = Schema.builder()
63
+ .add("json_payload", Types.STRING)
64
+ .build();
65
+ plugin.validate(task, inputSchema);
66
+ }
67
+ }
@@ -0,0 +1,99 @@
1
+ package org.embulk.filter.json_csv2arrayofobjects;
2
+
3
+ import org.embulk.EmbulkTestRuntime;
4
+ import org.embulk.config.ConfigException;
5
+ import org.embulk.spi.DataException;
6
+ import org.embulk.spi.type.Types;
7
+ import org.junit.Rule;
8
+ import org.junit.Test;
9
+
10
+ import static org.junit.Assert.assertEquals;
11
+ import static org.junit.Assert.assertTrue;
12
+ import static org.junit.Assert.fail;
13
+
14
+ public class TestStringCast
15
+ {
16
+ @Rule
17
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
18
+
19
+ @Test
20
+ public void asBoolean()
21
+ {
22
+ for (String str : StringCast.TRUE_STRINGS) {
23
+ assertEquals(true, StringCast.asBoolean(str));
24
+ }
25
+ for (String str : StringCast.FALSE_STRINGS) {
26
+ assertEquals(false, StringCast.asBoolean(str));
27
+ }
28
+ try {
29
+ StringCast.asBoolean("foo");
30
+ fail();
31
+ }
32
+ catch (Throwable t) {
33
+ assertTrue(t instanceof DataException);
34
+ }
35
+ }
36
+
37
+ @Test
38
+ public void asDouble()
39
+ {
40
+ assertEquals(1.0, StringCast.asDouble("1"), 0.0);
41
+ assertEquals(1.5, StringCast.asDouble("1.5"), 0.0);
42
+ try {
43
+ StringCast.asDouble("foo");
44
+ fail();
45
+ }
46
+ catch (Throwable t) {
47
+ assertTrue(t instanceof DataException);
48
+ }
49
+ }
50
+
51
+ @Test
52
+ public void asLong()
53
+ {
54
+ assertEquals(1, StringCast.asLong("1"));
55
+ try {
56
+ StringCast.asLong("1.5");
57
+ fail();
58
+ }
59
+ catch (Throwable t) {
60
+ assertTrue(t instanceof DataException);
61
+ }
62
+ try {
63
+ StringCast.asLong("foo");
64
+ fail();
65
+ }
66
+ catch (Throwable t) {
67
+ assertTrue(t instanceof DataException);
68
+ }
69
+ }
70
+
71
+ @Test
72
+ public void asString()
73
+ {
74
+ assertEquals("1", StringCast.asString("1"));
75
+ assertEquals("1.5", StringCast.asString("1.5"));
76
+ assertEquals("foo", StringCast.asString("foo"));
77
+ }
78
+
79
+ @Test
80
+ public void cast()
81
+ {
82
+ assertTrue((boolean) StringCast.cast("true", Types.BOOLEAN));
83
+ assertEquals(1.5, (Double) StringCast.cast("1.5", Types.DOUBLE), 0.0);
84
+ assertEquals(1L, StringCast.cast("1", Types.LONG));
85
+ assertEquals("foo", StringCast.cast("foo", Types.STRING));
86
+ }
87
+
88
+ @Test(expected = ConfigException.class)
89
+ public void castToJson()
90
+ {
91
+ StringCast.cast("{\"a\":1}", Types.JSON);
92
+ }
93
+
94
+ @Test(expected = ConfigException.class)
95
+ public void castToTimestamp()
96
+ {
97
+ StringCast.cast("2012-12-12 12:12:12.121212", Types.TIMESTAMP);
98
+ }
99
+ }
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-filter-json_csv2arrayofobjects
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke NISHIOKA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ name: bundler
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '10.0'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Json Csv2arrayofobjects
42
+ email:
43
+ - yusuke.nishioka.0713@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - LICENSE.txt
50
+ - README.md
51
+ - build.gradle
52
+ - config/checkstyle/checkstyle.xml
53
+ - config/checkstyle/default.xml
54
+ - example/example.tsv
55
+ - example/example.yml
56
+ - gradle/wrapper/gradle-wrapper.jar
57
+ - gradle/wrapper/gradle-wrapper.properties
58
+ - gradlew
59
+ - gradlew.bat
60
+ - lib/embulk/filter/json_csv2arrayofobjects.rb
61
+ - src/main/java/org/embulk/filter/json_csv2arrayofobjects/ColumnVisitorImpl.java
62
+ - src/main/java/org/embulk/filter/json_csv2arrayofobjects/Filter.java
63
+ - src/main/java/org/embulk/filter/json_csv2arrayofobjects/JsonCsv2arrayofobjectsFilterPlugin.java
64
+ - src/main/java/org/embulk/filter/json_csv2arrayofobjects/StringCast.java
65
+ - src/test/java/org/embulk/filter/json_csv2arrayofobjects/TestFilter.java
66
+ - src/test/java/org/embulk/filter/json_csv2arrayofobjects/TestJsonCsv2arrayofobjectsFilterPlugin.java
67
+ - src/test/java/org/embulk/filter/json_csv2arrayofobjects/TestStringCast.java
68
+ - classpath/accessors-smart-1.2.jar
69
+ - classpath/asm-5.0.4.jar
70
+ - classpath/embulk-filter-json_csv2arrayofobjects-0.1.0.jar
71
+ - classpath/json-path-2.4.0.jar
72
+ - classpath/json-smart-2.3.jar
73
+ - classpath/slf4j-api-1.7.25.jar
74
+ homepage:
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.1.9
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Json Csv2arrayofobjects filter plugin for Embulk
98
+ test_files: []