embulk-parser-poi_excel 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +35 -0
- data/build.gradle +1 -1
- data/classpath/embulk-parser-poi_excel-0.1.2.jar +0 -0
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelColumnValueType.java +2 -3
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +34 -50
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +300 -0
- data/src/main/java/org/embulk/parser/poi_excel/{visitor → bean}/PoiExcelColumnIndex.java +44 -27
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelSheetBean.java +102 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/AbstractPoiExcelCellAttributeVisitor.java +15 -13
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellCommentVisitor.java +2 -2
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellFontVisitor.java +2 -2
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellStyleVisitor.java +2 -2
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java +52 -31
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelClientAnchorVisitor.java +2 -2
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java +30 -29
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorFactory.java +4 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorValue.java +10 -21
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/BooleanCellVisitor.java +5 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/CellVisitor.java +30 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/DoubleCellVisitor.java +13 -1
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/LongCellVisitor.java +13 -1
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/StringCellVisitor.java +5 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/TimestampCellVisitor.java +30 -8
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin.java +0 -1
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellError.java +184 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java +3 -5
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_constant.java +54 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java +113 -0
- data/src/test/resources/org/embulk/parser/poi_excel/test1.xls +0 -0
- metadata +9 -4
- data/classpath/embulk-parser-poi_excel-0.1.1.jar +0 -0
@@ -1,13 +1,13 @@
|
|
1
1
|
package org.embulk.parser.poi_excel;
|
2
2
|
|
3
3
|
import static org.hamcrest.CoreMatchers.is;
|
4
|
+
import static org.hamcrest.CoreMatchers.nullValue;
|
4
5
|
import static org.junit.Assert.assertThat;
|
5
6
|
|
6
7
|
import java.net.URL;
|
7
8
|
import java.text.ParseException;
|
8
9
|
import java.util.List;
|
9
10
|
|
10
|
-
import org.apache.poi.ss.usermodel.FormulaError;
|
11
11
|
import org.embulk.parser.EmbulkPluginTester;
|
12
12
|
import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
|
13
13
|
import org.embulk.parser.EmbulkTestParserConfig;
|
@@ -23,7 +23,6 @@ public class TestPoiExcelParserPlugin_columnNumber {
|
|
23
23
|
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
24
24
|
parser.set("sheet", "test1");
|
25
25
|
parser.set("skip_header_lines", 1);
|
26
|
-
parser.set("cell_error_null", false);
|
27
26
|
parser.addColumn("text", "string").set("column_number", "D");
|
28
27
|
|
29
28
|
URL inFile = getClass().getResource("test1.xls");
|
@@ -36,7 +35,7 @@ public class TestPoiExcelParserPlugin_columnNumber {
|
|
36
35
|
assertThat(result.get(3).getAsString("text"), is("abc"));
|
37
36
|
assertThat(result.get(4).getAsString("text"), is("abc"));
|
38
37
|
assertThat(result.get(5).getAsString("text"), is("true"));
|
39
|
-
assertThat(result.get(6).getAsString("text"), is(
|
38
|
+
assertThat(result.get(6).getAsString("text"), is(nullValue()));
|
40
39
|
}
|
41
40
|
}
|
42
41
|
|
@@ -48,7 +47,6 @@ public class TestPoiExcelParserPlugin_columnNumber {
|
|
48
47
|
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
49
48
|
parser.set("sheet", "test1");
|
50
49
|
parser.set("skip_header_lines", 1);
|
51
|
-
parser.set("cell_error_null", false);
|
52
50
|
parser.addColumn("long", "long").set("column_number", 2);
|
53
51
|
parser.addColumn("double", "double");
|
54
52
|
|
@@ -62,7 +60,7 @@ public class TestPoiExcelParserPlugin_columnNumber {
|
|
62
60
|
check_int(result, 3, 123L, 123.4d);
|
63
61
|
check_int(result, 4, 123L, 123.4d);
|
64
62
|
check_int(result, 5, 1L, 1d);
|
65
|
-
check_int(result, 6,
|
63
|
+
check_int(result, 6, null, null);
|
66
64
|
}
|
67
65
|
}
|
68
66
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
package org.embulk.parser.poi_excel;
|
2
|
+
|
3
|
+
import static org.hamcrest.CoreMatchers.is;
|
4
|
+
import static org.hamcrest.CoreMatchers.nullValue;
|
5
|
+
import static org.junit.Assert.assertThat;
|
6
|
+
|
7
|
+
import java.net.URL;
|
8
|
+
import java.text.ParseException;
|
9
|
+
import java.util.List;
|
10
|
+
|
11
|
+
import org.embulk.parser.EmbulkPluginTester;
|
12
|
+
import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
|
13
|
+
import org.embulk.parser.EmbulkTestParserConfig;
|
14
|
+
import org.junit.Test;
|
15
|
+
|
16
|
+
public class TestPoiExcelParserPlugin_constant {
|
17
|
+
|
18
|
+
@Test
|
19
|
+
public void testConstant() throws Exception {
|
20
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
21
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
22
|
+
|
23
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
24
|
+
parser.set("sheet", "style");
|
25
|
+
parser.addColumn("const-s", "string").set("value", "constant.zzz");
|
26
|
+
parser.addColumn("const-n", "long").set("value", "constant.-1");
|
27
|
+
parser.addColumn("space", "string").set("value", "constant. ");
|
28
|
+
parser.addColumn("empty", "string").set("value", "constant.");
|
29
|
+
parser.addColumn("null", "string").set("value", "constant");
|
30
|
+
parser.addColumn("cell", "string");
|
31
|
+
|
32
|
+
URL inFile = getClass().getResource("test1.xls");
|
33
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
34
|
+
|
35
|
+
assertThat(result.size(), is(5));
|
36
|
+
check(result, 0, "red");
|
37
|
+
check(result, 1, "green");
|
38
|
+
check(result, 2, "blue");
|
39
|
+
check(result, 3, "white");
|
40
|
+
check(result, 4, "black");
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
private void check(List<OutputRecord> result, int index, String s) throws ParseException {
|
45
|
+
OutputRecord r = result.get(index);
|
46
|
+
// System.out.println(r);
|
47
|
+
assertThat(r.getAsString("const-s"), is("zzz"));
|
48
|
+
assertThat(r.getAsLong("const-n"), is(-1L));
|
49
|
+
assertThat(r.getAsString("space"), is(" "));
|
50
|
+
assertThat(r.getAsString("empty"), is(""));
|
51
|
+
assertThat(r.getAsString("null"), is(nullValue()));
|
52
|
+
assertThat(r.getAsString("cell"), is(s));
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
package org.embulk.parser.poi_excel;
|
2
|
+
|
3
|
+
import static org.hamcrest.CoreMatchers.is;
|
4
|
+
import static org.hamcrest.CoreMatchers.nullValue;
|
5
|
+
import static org.junit.Assert.assertThat;
|
6
|
+
import static org.junit.Assert.fail;
|
7
|
+
|
8
|
+
import java.net.URL;
|
9
|
+
import java.text.SimpleDateFormat;
|
10
|
+
import java.util.List;
|
11
|
+
|
12
|
+
import org.embulk.parser.EmbulkPluginTester;
|
13
|
+
import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
|
14
|
+
import org.embulk.parser.EmbulkTestParserConfig;
|
15
|
+
import org.embulk.spi.time.Timestamp;
|
16
|
+
import org.junit.Test;
|
17
|
+
|
18
|
+
public class TestPoiExcelParserPlugin_convertError {
|
19
|
+
|
20
|
+
@Test
|
21
|
+
public void testConvertError_default() throws Exception {
|
22
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
23
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
24
|
+
|
25
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
26
|
+
parser.set("sheet", "style");
|
27
|
+
parser.addColumn("t", "timestamp").set("column_number", "A");
|
28
|
+
|
29
|
+
URL inFile = getClass().getResource("test1.xls");
|
30
|
+
try {
|
31
|
+
tester.runParser(inFile, parser);
|
32
|
+
} catch (Exception e) {
|
33
|
+
Throwable c1 = e.getCause();
|
34
|
+
assertThat(c1.getMessage().contains("error at Column"), is(true));
|
35
|
+
Throwable c2 = c1.getCause();
|
36
|
+
assertThat(c2.getMessage().contains("convert error"), is(true));
|
37
|
+
return; // success
|
38
|
+
}
|
39
|
+
fail("must throw Exception");
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
@Test
|
44
|
+
public void testConvertError_exception() throws Exception {
|
45
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
46
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
47
|
+
|
48
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
49
|
+
parser.set("sheet", "style");
|
50
|
+
parser.set("on_convert_error", "exception");
|
51
|
+
parser.addColumn("t", "timestamp").set("column_number", "A");
|
52
|
+
|
53
|
+
URL inFile = getClass().getResource("test1.xls");
|
54
|
+
try {
|
55
|
+
tester.runParser(inFile, parser);
|
56
|
+
} catch (Exception e) {
|
57
|
+
Throwable c1 = e.getCause();
|
58
|
+
assertThat(c1.getMessage().contains("error at Column"), is(true));
|
59
|
+
Throwable c2 = c1.getCause();
|
60
|
+
assertThat(c2.getMessage().contains("convert error"), is(true));
|
61
|
+
return; // success
|
62
|
+
}
|
63
|
+
fail("must throw Exception");
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
@Test
|
68
|
+
public void testConvertError_null() throws Exception {
|
69
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
70
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
71
|
+
|
72
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
73
|
+
parser.set("sheet", "comment");
|
74
|
+
parser.set("on_convert_error", "constant");
|
75
|
+
parser.addColumn("t", "timestamp").set("column_number", "A");
|
76
|
+
|
77
|
+
URL inFile = getClass().getResource("test1.xls");
|
78
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
79
|
+
|
80
|
+
assertThat(result.size(), is(2));
|
81
|
+
assertThat(result.get(0).getAsTimestamp("t"), is(nullValue()));
|
82
|
+
assertThat(result.get(1).getAsTimestamp("t"), is(nullValue()));
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
@Test
|
87
|
+
public void testConvertError_constant() throws Exception {
|
88
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
89
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
90
|
+
|
91
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
92
|
+
parser.set("sheet", "comment");
|
93
|
+
parser.set("on_convert_error", "constant.0");
|
94
|
+
parser.addColumn("b", "boolean").set("column_number", "A");
|
95
|
+
parser.addColumn("l", "long").set("column_number", "A");
|
96
|
+
parser.addColumn("d", "double").set("column_number", "A");
|
97
|
+
parser.addColumn("t", "timestamp").set("column_number", "A").set("format", "%Y/%m/%d")
|
98
|
+
.set("on_convert_error", "constant.2000/1/1");
|
99
|
+
|
100
|
+
URL inFile = getClass().getResource("test1.xls");
|
101
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
102
|
+
|
103
|
+
assertThat(result.size(), is(2));
|
104
|
+
for (OutputRecord r : result) {
|
105
|
+
assertThat(r.getAsBoolean("b"), is(false));
|
106
|
+
assertThat(r.getAsLong("l"), is(0L));
|
107
|
+
assertThat(r.getAsDouble("d"), is(0d));
|
108
|
+
assertThat(r.getAsTimestamp("t"), is(Timestamp.ofEpochMilli(new SimpleDateFormat("yyyy/MM/dd z").parse(
|
109
|
+
"2000/01/01 UTC").getTime())));
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-parser-poi_excel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hishidama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,6 +57,9 @@ files:
|
|
57
57
|
- lib/embulk/parser/poi_excel.rb
|
58
58
|
- src/main/java/org/embulk/parser/poi_excel/PoiExcelColumnValueType.java
|
59
59
|
- src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java
|
60
|
+
- src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java
|
61
|
+
- src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnIndex.java
|
62
|
+
- src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelSheetBean.java
|
60
63
|
- src/main/java/org/embulk/parser/poi_excel/visitor/AbstractPoiExcelCellAttributeVisitor.java
|
61
64
|
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellCommentVisitor.java
|
62
65
|
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellFontVisitor.java
|
@@ -64,7 +67,6 @@ files:
|
|
64
67
|
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java
|
65
68
|
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelClientAnchorVisitor.java
|
66
69
|
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColorVisitor.java
|
67
|
-
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnIndex.java
|
68
70
|
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java
|
69
71
|
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorFactory.java
|
70
72
|
- src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorValue.java
|
@@ -80,12 +82,15 @@ files:
|
|
80
82
|
- src/test/java/org/embulk/parser/EmbulkTestParserConfig.java
|
81
83
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin.java
|
82
84
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellComment.java
|
85
|
+
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellError.java
|
83
86
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellFont.java
|
84
87
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellStyle.java
|
85
88
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java
|
89
|
+
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_constant.java
|
90
|
+
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java
|
86
91
|
- src/test/resources/org/embulk/parser/poi_excel/test1.xls
|
87
92
|
- classpath/commons-codec-1.9.jar
|
88
|
-
- classpath/embulk-parser-poi_excel-0.1.
|
93
|
+
- classpath/embulk-parser-poi_excel-0.1.2.jar
|
89
94
|
- classpath/embulk-standards-0.7.5.jar
|
90
95
|
- classpath/poi-3.13.jar
|
91
96
|
- classpath/poi-ooxml-3.13.jar
|
Binary file
|