embulk-parser-joni_regexp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.travis.yml +7 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +107 -0
  6. data/build.gradle +101 -0
  7. data/config/checkstyle/checkstyle.xml +128 -0
  8. data/config/checkstyle/default.xml +108 -0
  9. data/example/apache.txt +5000 -0
  10. data/example/apache.yml +18 -0
  11. data/example/conf.yml +12 -0
  12. data/example/conf2.yml +12 -0
  13. data/example/conf3.yml +12 -0
  14. data/example/seed.yml +8 -0
  15. data/example/test.txt +8 -0
  16. data/example/test2.txt +3 -0
  17. data/gradle/wrapper/gradle-wrapper.jar +0 -0
  18. data/gradle/wrapper/gradle-wrapper.properties +6 -0
  19. data/gradlew +169 -0
  20. data/gradlew.bat +84 -0
  21. data/lib/embulk/guess/joni_regexp.rb +28 -0
  22. data/lib/embulk/parser/joni_regexp.rb +3 -0
  23. data/src/main/java/org/embulk/parser/joni_regexp/ColumnCaster.java +97 -0
  24. data/src/main/java/org/embulk/parser/joni_regexp/ColumnVisitorImpl.java +167 -0
  25. data/src/main/java/org/embulk/parser/joni_regexp/JoniRegexpParserPlugin.java +169 -0
  26. data/src/main/java/org/embulk/parser/joni_regexp/JsonRecordValidateException.java +22 -0
  27. data/src/main/java/org/embulk/parser/joni_regexp/cast/BooleanCast.java +39 -0
  28. data/src/main/java/org/embulk/parser/joni_regexp/cast/DoubleCast.java +41 -0
  29. data/src/main/java/org/embulk/parser/joni_regexp/cast/JsonCast.java +40 -0
  30. data/src/main/java/org/embulk/parser/joni_regexp/cast/LongCast.java +47 -0
  31. data/src/main/java/org/embulk/parser/joni_regexp/cast/StringCast.java +82 -0
  32. data/src/test/java/org/embulk/parser/joni_regexp/TestColumnCaster.java +256 -0
  33. data/src/test/java/org/embulk/parser/joni_regexp/TestJoniRegexpParserPlugin.java +432 -0
  34. data/src/test/java/org/embulk/parser/joni_regexp/cast/TestBooleanCast.java +56 -0
  35. data/src/test/java/org/embulk/parser/joni_regexp/cast/TestDoubleCast.java +49 -0
  36. data/src/test/java/org/embulk/parser/joni_regexp/cast/TestJsonCast.java +79 -0
  37. data/src/test/java/org/embulk/parser/joni_regexp/cast/TestLongCast.java +41 -0
  38. data/src/test/java/org/embulk/parser/joni_regexp/cast/TestStringCast.java +103 -0
  39. metadata +112 -0
@@ -0,0 +1,56 @@
1
+ package org.embulk.parser.joni_regexp.cast;
2
+
3
+ import org.embulk.spi.DataException;
4
+ import org.junit.Test;
5
+
6
+ import static org.junit.Assert.assertEquals;
7
+ import static org.junit.Assert.assertTrue;
8
+ import static org.junit.Assert.fail;
9
+
10
+ public class TestBooleanCast
11
+ {
12
+ @Test
13
+ public void asBoolean()
14
+ {
15
+ assertEquals(true, BooleanCast.asBoolean(true));
16
+ assertEquals(false, BooleanCast.asBoolean(false));
17
+ }
18
+
19
+ @Test
20
+ public void asLong()
21
+ {
22
+ assertEquals(1, BooleanCast.asLong(true));
23
+ assertEquals(0, BooleanCast.asLong(false));
24
+ }
25
+
26
+ @Test
27
+ public void asDouble()
28
+ {
29
+ try {
30
+ BooleanCast.asDouble(true);
31
+ fail();
32
+ }
33
+ catch (Throwable t) {
34
+ assertTrue(t instanceof DataException);
35
+ }
36
+ }
37
+
38
+ @Test
39
+ public void asString()
40
+ {
41
+ assertEquals("true", BooleanCast.asString(true));
42
+ assertEquals("false", BooleanCast.asString(false));
43
+ }
44
+
45
+ @Test
46
+ public void asTimestamp()
47
+ {
48
+ try {
49
+ BooleanCast.asTimestamp(true);
50
+ fail();
51
+ }
52
+ catch (Throwable t) {
53
+ assertTrue(t instanceof DataException);
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,49 @@
1
+ package org.embulk.parser.joni_regexp.cast;
2
+
3
+ import org.embulk.spi.DataException;
4
+ import org.embulk.spi.time.Timestamp;
5
+ import org.junit.Test;
6
+
7
+ import static org.junit.Assert.assertEquals;
8
+ import static org.junit.Assert.assertTrue;
9
+ import static org.junit.Assert.fail;
10
+
11
+ public class TestDoubleCast
12
+ {
13
+ @Test
14
+ public void asBoolean()
15
+ {
16
+ try {
17
+ DoubleCast.asBoolean(0.5);
18
+ fail();
19
+ }
20
+ catch (Throwable t) {
21
+ assertTrue(t instanceof DataException);
22
+ }
23
+ }
24
+
25
+ @Test
26
+ public void asLong()
27
+ {
28
+ assertEquals(0, DoubleCast.asLong(0.5));
29
+ }
30
+
31
+ @Test
32
+ public void asDouble()
33
+ {
34
+ assertEquals(0.5, DoubleCast.asDouble(0.5), 0.0);
35
+ }
36
+
37
+ @Test
38
+ public void asString()
39
+ {
40
+ assertEquals("0.5", DoubleCast.asString(0.5));
41
+ }
42
+
43
+ @Test
44
+ public void asTimestamp()
45
+ {
46
+ Timestamp expected = Timestamp.ofEpochSecond(1, 500000000);
47
+ assertEquals(expected, DoubleCast.asTimestamp(1.5));
48
+ }
49
+ }
@@ -0,0 +1,79 @@
1
+ package org.embulk.parser.joni_regexp.cast;
2
+
3
+ import org.embulk.spi.DataException;
4
+ import org.junit.Before;
5
+ import org.junit.Test;
6
+ import org.msgpack.value.Value;
7
+ import org.msgpack.value.ValueFactory;
8
+
9
+ import static org.junit.Assert.assertEquals;
10
+ import static org.junit.Assert.assertTrue;
11
+ import static org.junit.Assert.fail;
12
+
13
+ public class TestJsonCast
14
+ {
15
+ public Value value;
16
+
17
+ @Before
18
+ public void createResource()
19
+ {
20
+ Value[] kvs = new Value[2];
21
+ kvs[0] = ValueFactory.newString("k");
22
+ kvs[1] = ValueFactory.newString("v");
23
+ value = ValueFactory.newMap(kvs);
24
+ }
25
+
26
+ @Test
27
+ public void asBoolean()
28
+ {
29
+ try {
30
+ JsonCast.asBoolean(value);
31
+ fail();
32
+ }
33
+ catch (Throwable t) {
34
+ assertTrue(t instanceof DataException);
35
+ }
36
+ }
37
+
38
+ @Test
39
+ public void asLong()
40
+ {
41
+ try {
42
+ JsonCast.asLong(value);
43
+ fail();
44
+ }
45
+ catch (Throwable t) {
46
+ assertTrue(t instanceof DataException);
47
+ }
48
+ }
49
+
50
+ @Test
51
+ public void asDouble()
52
+ {
53
+ try {
54
+ JsonCast.asDouble(value);
55
+ fail();
56
+ }
57
+ catch (Throwable t) {
58
+ assertTrue(t instanceof DataException);
59
+ }
60
+ }
61
+
62
+ @Test
63
+ public void asString()
64
+ {
65
+ assertEquals("{\"k\":\"v\"}", JsonCast.asString(value));
66
+ }
67
+
68
+ @Test
69
+ public void asTimestamp()
70
+ {
71
+ try {
72
+ JsonCast.asTimestamp(value);
73
+ fail();
74
+ }
75
+ catch (Throwable t) {
76
+ assertTrue(t instanceof DataException);
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,41 @@
1
+ package org.embulk.parser.joni_regexp.cast;
2
+
3
+ import org.embulk.spi.time.Timestamp;
4
+ import org.junit.Test;
5
+
6
+ import static org.junit.Assert.assertEquals;
7
+
8
+ public class TestLongCast
9
+ {
10
+ @Test
11
+ public void asBoolean()
12
+ {
13
+ assertEquals(true, LongCast.asBoolean(1));
14
+ assertEquals(false, LongCast.asBoolean(0));
15
+ }
16
+
17
+ @Test
18
+ public void asLong()
19
+ {
20
+ assertEquals(1, LongCast.asLong(1));
21
+ }
22
+
23
+ @Test
24
+ public void asDouble()
25
+ {
26
+ assertEquals(1.0, LongCast.asDouble(1), 0.0);
27
+ }
28
+
29
+ @Test
30
+ public void asString()
31
+ {
32
+ assertEquals("1", LongCast.asString(1));
33
+ }
34
+
35
+ @Test
36
+ public void asTimestamp()
37
+ {
38
+ Timestamp expected = Timestamp.ofEpochSecond(1);
39
+ assertEquals(expected, LongCast.asTimestamp(1));
40
+ }
41
+ }
@@ -0,0 +1,103 @@
1
+ package org.embulk.parser.joni_regexp.cast;
2
+
3
+ import org.embulk.EmbulkTestRuntime;
4
+ import org.embulk.spi.DataException;
5
+ import org.embulk.spi.time.Timestamp;
6
+ import org.embulk.spi.time.TimestampParser;
7
+ import org.joda.time.DateTimeZone;
8
+ import org.jruby.embed.ScriptingContainer;
9
+ import org.junit.Before;
10
+ import org.junit.Rule;
11
+ import org.junit.Test;
12
+
13
+ import static org.junit.Assert.assertEquals;
14
+ import static org.junit.Assert.assertTrue;
15
+ import static org.junit.Assert.fail;
16
+
17
+ public class TestStringCast
18
+ {
19
+ @Rule
20
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
21
+ public ScriptingContainer jruby;
22
+
23
+ @Before
24
+ public void createResource()
25
+ {
26
+ jruby = new ScriptingContainer();
27
+ }
28
+
29
+ @Test
30
+ public void asBoolean()
31
+ {
32
+ for (String str : StringCast.TRUE_STRINGS) {
33
+ assertEquals(true, StringCast.asBoolean(str));
34
+ }
35
+ for (String str : StringCast.FALSE_STRINGS) {
36
+ assertEquals(false, StringCast.asBoolean(str));
37
+ }
38
+ try {
39
+ StringCast.asBoolean("foo");
40
+ }
41
+ catch (Throwable t) {
42
+ assertTrue(t instanceof DataException);
43
+ }
44
+ }
45
+
46
+ @Test
47
+ public void asLong()
48
+ {
49
+ assertEquals(1, StringCast.asLong("1"));
50
+ try {
51
+ StringCast.asLong("1.5");
52
+ fail();
53
+ }
54
+ catch (Throwable t) {
55
+ assertTrue(t instanceof DataException);
56
+ }
57
+ try {
58
+ StringCast.asLong("foo");
59
+ fail();
60
+ }
61
+ catch (Throwable t) {
62
+ assertTrue(t instanceof DataException);
63
+ }
64
+ }
65
+
66
+ @Test
67
+ public void asDouble()
68
+ {
69
+ assertEquals(1.0, StringCast.asDouble("1"), 0.0);
70
+ assertEquals(1.5, StringCast.asDouble("1.5"), 0.0);
71
+ try {
72
+ StringCast.asDouble("foo");
73
+ fail();
74
+ }
75
+ catch (Throwable t) {
76
+ assertTrue(t instanceof DataException);
77
+ }
78
+ }
79
+
80
+ @Test
81
+ public void asString()
82
+ {
83
+ assertEquals("1", StringCast.asString("1"));
84
+ assertEquals("1.5", StringCast.asString("1.5"));
85
+ assertEquals("foo", StringCast.asString("foo"));
86
+ }
87
+
88
+ @Test
89
+ public void asTimestamp()
90
+ {
91
+ Timestamp expected = Timestamp.ofEpochSecond(1463084053, 123456000);
92
+ TimestampParser parser = new TimestampParser(jruby, "%Y-%m-%d %H:%M:%S.%N", DateTimeZone.UTC);
93
+ assertEquals(expected, StringCast.asTimestamp("2016-05-12 20:14:13.123456", parser));
94
+
95
+ try {
96
+ StringCast.asTimestamp("foo", parser);
97
+ fail();
98
+ }
99
+ catch (Throwable t) {
100
+ assertTrue(t instanceof DataException);
101
+ }
102
+ }
103
+ }
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-parser-joni_regexp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiroyuki Sato
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-08 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: The Embulk parser plugin for the Fluentd regex parser(Oniguruma) compatible.
42
+ email:
43
+ - hiroysato@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - LICENSE.txt
51
+ - README.md
52
+ - build.gradle
53
+ - config/checkstyle/checkstyle.xml
54
+ - config/checkstyle/default.xml
55
+ - example/apache.txt
56
+ - example/apache.yml
57
+ - example/conf.yml
58
+ - example/conf2.yml
59
+ - example/conf3.yml
60
+ - example/seed.yml
61
+ - example/test.txt
62
+ - example/test2.txt
63
+ - gradle/wrapper/gradle-wrapper.jar
64
+ - gradle/wrapper/gradle-wrapper.properties
65
+ - gradlew
66
+ - gradlew.bat
67
+ - lib/embulk/guess/joni_regexp.rb
68
+ - lib/embulk/parser/joni_regexp.rb
69
+ - src/main/java/org/embulk/parser/joni_regexp/ColumnCaster.java
70
+ - src/main/java/org/embulk/parser/joni_regexp/ColumnVisitorImpl.java
71
+ - src/main/java/org/embulk/parser/joni_regexp/JoniRegexpParserPlugin.java
72
+ - src/main/java/org/embulk/parser/joni_regexp/JsonRecordValidateException.java
73
+ - src/main/java/org/embulk/parser/joni_regexp/cast/BooleanCast.java
74
+ - src/main/java/org/embulk/parser/joni_regexp/cast/DoubleCast.java
75
+ - src/main/java/org/embulk/parser/joni_regexp/cast/JsonCast.java
76
+ - src/main/java/org/embulk/parser/joni_regexp/cast/LongCast.java
77
+ - src/main/java/org/embulk/parser/joni_regexp/cast/StringCast.java
78
+ - src/test/java/org/embulk/parser/joni_regexp/TestColumnCaster.java
79
+ - src/test/java/org/embulk/parser/joni_regexp/TestJoniRegexpParserPlugin.java
80
+ - src/test/java/org/embulk/parser/joni_regexp/cast/TestBooleanCast.java
81
+ - src/test/java/org/embulk/parser/joni_regexp/cast/TestDoubleCast.java
82
+ - src/test/java/org/embulk/parser/joni_regexp/cast/TestJsonCast.java
83
+ - src/test/java/org/embulk/parser/joni_regexp/cast/TestLongCast.java
84
+ - src/test/java/org/embulk/parser/joni_regexp/cast/TestStringCast.java
85
+ - classpath/embulk-parser-joni_regexp-0.1.0.jar
86
+ - classpath/jcodings-1.0.18.jar
87
+ - classpath/joni-2.1.11.jar
88
+ homepage: https://github.com/hiroyuki-sato/embulk-parser-joni_regexp
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.1.9
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A Regular expression(Joni) parser plugin for Embulk(Fluentd compatible)
112
+ test_files: []