embulk-output-kintone 0.4.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +63 -5
- data/build.gradle +1 -0
- data/classpath/commons-csv-1.9.0.jar +0 -0
- data/classpath/embulk-output-kintone-1.1.0.jar +0 -0
- data/classpath/externalsortinginjava-0.6.2.jar +0 -0
- data/classpath/{shadow-kintone-java-client-0.4.1-all.jar → shadow-kintone-java-client-1.1.0-all.jar} +0 -0
- data/src/main/java/org/embulk/output/kintone/KintoneColumnOption.java +6 -2
- data/src/main/java/org/embulk/output/kintone/KintoneColumnType.java +572 -0
- data/src/main/java/org/embulk/output/kintone/KintoneColumnVisitor.java +214 -135
- data/src/main/java/org/embulk/output/kintone/KintoneMode.java +0 -1
- data/src/main/java/org/embulk/output/kintone/KintoneOutputPlugin.java +12 -5
- data/src/main/java/org/embulk/output/kintone/KintonePageOutput.java +180 -160
- data/src/main/java/org/embulk/output/kintone/KintoneSortColumn.java +33 -0
- data/src/main/java/org/embulk/output/kintone/PluginTask.java +35 -0
- data/src/main/java/org/embulk/output/kintone/deserializer/DeserializeApplier.java +19 -0
- data/src/main/java/org/embulk/output/kintone/deserializer/DeserializeException.java +7 -0
- data/src/main/java/org/embulk/output/kintone/deserializer/Deserializer.java +279 -0
- data/src/main/java/org/embulk/output/kintone/reducer/CSVInputColumnVisitor.java +78 -0
- data/src/main/java/org/embulk/output/kintone/reducer/CSVOutputColumnVisitor.java +79 -0
- data/src/main/java/org/embulk/output/kintone/reducer/ReduceException.java +11 -0
- data/src/main/java/org/embulk/output/kintone/reducer/ReduceType.java +190 -0
- data/src/main/java/org/embulk/output/kintone/reducer/ReducedPageOutput.java +100 -0
- data/src/main/java/org/embulk/output/kintone/reducer/Reducer.java +355 -0
- data/src/test/java/org/embulk/output/kintone/KintoneColumnOptionBuilder.java +9 -3
- data/src/test/java/org/embulk/output/kintone/KintoneColumnTypeTest.java +194 -0
- data/src/test/java/org/embulk/output/kintone/KintoneColumnVisitorTest.java +703 -61
- data/src/test/java/org/embulk/output/kintone/KintoneColumnVisitorVerifier.java +45 -14
- data/src/test/java/org/embulk/output/kintone/KintonePageOutputVerifier.java +43 -5
- data/src/test/java/org/embulk/output/kintone/TestKintoneOutputPlugin.java +106 -16
- data/src/test/java/org/embulk/output/kintone/TestTaskMode.java +12 -0
- data/src/test/java/org/embulk/output/kintone/TestTaskReduce.java +46 -0
- data/src/test/java/org/embulk/output/kintone/TestTaskReduceException.java +50 -0
- data/src/test/java/org/embulk/output/kintone/TestTaskReduceSubtable.java +46 -0
- data/src/test/java/org/embulk/output/kintone/deserializer/DeserializerTest.java +165 -0
- data/src/test/java/org/embulk/output/kintone/reducer/ReduceTypeTest.java +154 -0
- data/src/test/resources/org/embulk/output/kintone/task/config.yml +1 -1
- data/src/test/resources/org/embulk/output/kintone/task/mode/config.yml +110 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/input.csv +7 -7
- data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_ignore_nulls_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_prefer_nulls_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_records.jsonl +6 -6
- data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_records.jsonl +6 -3
- data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_add_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_add_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_add_records.jsonl +2 -2
- data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_records.jsonl +4 -4
- data/src/test/resources/org/embulk/output/kintone/task/mode/values_ignore_nulls.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/values_prefer_nulls.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/config.yml +171 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/input.csv +7 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/insert_add_ignore_nulls_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/insert_add_prefer_nulls_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/insert_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/update_update_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/update_update_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/update_update_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_add_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_add_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_add_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_update_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_update_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_update_records.jsonl +4 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/values_ignore_nulls.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/values_prefer_nulls.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/config.yml +36 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/derived_columns.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/input.csv +13 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/insert_add_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/update_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/config.yml +343 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/derived_columns.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/input.csv +13 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/insert_add_ignore_nulls_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/insert_add_prefer_nulls_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/insert_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/update_update_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/update_update_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/update_update_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_add_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_add_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_add_records.jsonl +0 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_update_ignore_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_update_prefer_nulls_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_update_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/values_ignore_nulls.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/values_prefer_nulls.json +1 -0
- metadata +73 -4
- data/classpath/embulk-output-kintone-0.4.1.jar +0 -0
@@ -4,7 +4,9 @@ import com.kintone.client.model.record.FieldType;
|
|
4
4
|
import com.kintone.client.model.record.Record;
|
5
5
|
import com.kintone.client.model.record.UpdateKey;
|
6
6
|
import java.util.Map;
|
7
|
+
import java.util.Set;
|
7
8
|
import java.util.function.BiConsumer;
|
9
|
+
import javax.validation.UnexpectedTypeException;
|
8
10
|
import org.embulk.spi.Column;
|
9
11
|
import org.embulk.spi.Page;
|
10
12
|
import org.embulk.spi.PageReader;
|
@@ -12,24 +14,48 @@ import org.embulk.spi.Schema;
|
|
12
14
|
|
13
15
|
public class KintoneColumnVisitorVerifier {
|
14
16
|
private final Schema schema;
|
15
|
-
private final Map<String, KintoneColumnOption>
|
16
|
-
private final PageReader
|
17
|
+
private final Map<String, KintoneColumnOption> options;
|
18
|
+
private final PageReader reader;
|
17
19
|
private final KintoneColumnVisitor visitor;
|
18
20
|
|
19
21
|
public KintoneColumnVisitorVerifier(
|
20
22
|
Schema schema,
|
21
|
-
|
23
|
+
Set<Column> derived,
|
24
|
+
Map<String, KintoneColumnOption> options,
|
25
|
+
String reduceKeyName,
|
26
|
+
String updateKeyName,
|
27
|
+
Page page) {
|
28
|
+
this(schema, derived, options, false, false, reduceKeyName, updateKeyName, page);
|
29
|
+
}
|
30
|
+
|
31
|
+
public KintoneColumnVisitorVerifier(
|
32
|
+
Schema schema,
|
33
|
+
Set<Column> derived,
|
34
|
+
Map<String, KintoneColumnOption> options,
|
35
|
+
boolean preferNulls,
|
36
|
+
boolean ignoreNulls,
|
37
|
+
String reduceKeyName,
|
22
38
|
String updateKeyName,
|
23
39
|
Page page) {
|
24
40
|
this.schema = schema;
|
25
|
-
this.
|
26
|
-
|
27
|
-
|
28
|
-
visitor =
|
41
|
+
this.options = options;
|
42
|
+
reader = new PageReader(schema);
|
43
|
+
reader.setPage(page);
|
44
|
+
visitor =
|
45
|
+
new KintoneColumnVisitor(
|
46
|
+
reader, derived, options, preferNulls, ignoreNulls, reduceKeyName, updateKeyName);
|
47
|
+
}
|
48
|
+
|
49
|
+
public void verify() {
|
50
|
+
verify((record, updateKey) -> {});
|
29
51
|
}
|
30
52
|
|
31
53
|
public void verify(BiConsumer<Record, UpdateKey> consumer) {
|
32
|
-
|
54
|
+
verify(consumer, false);
|
55
|
+
}
|
56
|
+
|
57
|
+
public void verify(BiConsumer<Record, UpdateKey> consumer, boolean nullable) {
|
58
|
+
if (!reader.nextRecord()) {
|
33
59
|
throw new IllegalStateException();
|
34
60
|
}
|
35
61
|
Record record = new Record();
|
@@ -37,16 +63,21 @@ public class KintoneColumnVisitorVerifier {
|
|
37
63
|
UpdateKey updateKey = new UpdateKey();
|
38
64
|
visitor.setUpdateKey(updateKey);
|
39
65
|
schema.visitColumns(visitor);
|
40
|
-
schema.getColumns().forEach(column -> verify(record, column));
|
66
|
+
schema.getColumns().forEach(column -> verify(record, column, nullable));
|
41
67
|
consumer.accept(record, updateKey);
|
42
68
|
}
|
43
69
|
|
44
|
-
private void verify(Record record, Column column) {
|
45
|
-
FieldType expected = FieldType.valueOf(
|
70
|
+
private void verify(Record record, Column column, boolean nullable) {
|
71
|
+
FieldType expected = FieldType.valueOf(options.get(column.getName()).getType());
|
46
72
|
FieldType actual = record.getFieldType(column.getName());
|
47
|
-
if (
|
48
|
-
|
49
|
-
|
73
|
+
if (actual == null && nullable) {
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
if (expected != actual) {
|
77
|
+
throw new UnexpectedTypeException(
|
78
|
+
String.format(
|
79
|
+
"%s: Expected type is %s, but actual type is %s%n",
|
80
|
+
column.getName(), expected, actual));
|
50
81
|
}
|
51
82
|
}
|
52
83
|
}
|
@@ -1,10 +1,12 @@
|
|
1
1
|
package org.embulk.output.kintone;
|
2
2
|
|
3
|
+
import static org.embulk.output.kintone.deserializer.DeserializerTest.assertTableRows;
|
3
4
|
import static org.hamcrest.MatcherAssert.assertThat;
|
4
5
|
import static org.hamcrest.Matchers.is;
|
5
6
|
import static org.mockito.ArgumentMatchers.anyList;
|
6
7
|
import static org.mockito.ArgumentMatchers.eq;
|
7
8
|
import static org.mockito.ArgumentMatchers.matches;
|
9
|
+
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
8
10
|
import static org.mockito.Mockito.atLeast;
|
9
11
|
import static org.mockito.Mockito.mock;
|
10
12
|
import static org.mockito.Mockito.mockStatic;
|
@@ -19,16 +21,15 @@ import com.kintone.client.api.record.GetRecordsByCursorResponseBody;
|
|
19
21
|
import com.kintone.client.model.app.field.FieldProperty;
|
20
22
|
import com.kintone.client.model.app.field.NumberFieldProperty;
|
21
23
|
import com.kintone.client.model.app.field.SingleLineTextFieldProperty;
|
22
|
-
import com.kintone.client.model.record.DateTimeFieldValue;
|
23
24
|
import com.kintone.client.model.record.FieldType;
|
24
25
|
import com.kintone.client.model.record.FieldValue;
|
25
26
|
import com.kintone.client.model.record.NumberFieldValue;
|
26
27
|
import com.kintone.client.model.record.Record;
|
27
28
|
import com.kintone.client.model.record.RecordForUpdate;
|
28
29
|
import com.kintone.client.model.record.SingleLineTextFieldValue;
|
30
|
+
import com.kintone.client.model.record.SubtableFieldValue;
|
29
31
|
import com.kintone.client.model.record.UpdateKey;
|
30
32
|
import java.math.BigDecimal;
|
31
|
-
import java.time.ZoneId;
|
32
33
|
import java.util.Collection;
|
33
34
|
import java.util.Collections;
|
34
35
|
import java.util.List;
|
@@ -36,6 +37,9 @@ import java.util.Map;
|
|
36
37
|
import java.util.stream.Collectors;
|
37
38
|
import java.util.stream.IntStream;
|
38
39
|
import org.embulk.config.TaskReport;
|
40
|
+
import org.embulk.deps.buffer.PooledBufferAllocator;
|
41
|
+
import org.embulk.spi.BufferAllocator;
|
42
|
+
import org.embulk.spi.Exec;
|
39
43
|
import org.embulk.spi.Page;
|
40
44
|
import org.embulk.spi.TransactionalPageOutput;
|
41
45
|
import org.mockito.ArgumentCaptor;
|
@@ -49,6 +53,15 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
49
53
|
private final List<Record> addRecords;
|
50
54
|
private final List<RecordForUpdate> updateRecords;
|
51
55
|
|
56
|
+
public KintonePageOutputVerifier(
|
57
|
+
String domain,
|
58
|
+
String field,
|
59
|
+
List<String> values,
|
60
|
+
List<Record> addRecords,
|
61
|
+
List<RecordForUpdate> updateRecords) {
|
62
|
+
this(null, domain, field, values, addRecords, updateRecords);
|
63
|
+
}
|
64
|
+
|
52
65
|
public KintonePageOutputVerifier(
|
53
66
|
TransactionalPageOutput transactionalPageOutput,
|
54
67
|
String domain,
|
@@ -76,6 +89,9 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
76
89
|
|
77
90
|
@Override
|
78
91
|
public void close() {
|
92
|
+
if (transactionalPageOutput == null) {
|
93
|
+
return;
|
94
|
+
}
|
79
95
|
transactionalPageOutput.close();
|
80
96
|
}
|
81
97
|
|
@@ -91,12 +107,20 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
91
107
|
|
92
108
|
public void runWithMock(Runnable runnable) {
|
93
109
|
try {
|
94
|
-
|
110
|
+
runWithMockExec(runnable);
|
95
111
|
} catch (Exception e) {
|
96
112
|
throw new RuntimeException(e);
|
97
113
|
}
|
98
114
|
}
|
99
115
|
|
116
|
+
private void runWithMockExec(Runnable runnable) throws Exception {
|
117
|
+
BufferAllocator bufferAllocator = PooledBufferAllocator.create(1024 * 1024);
|
118
|
+
try (MockedStatic<Exec> mocked = mockStatic(Exec.class, CALLS_REAL_METHODS)) {
|
119
|
+
mocked.when(Exec::getBufferAllocator).thenReturn(bufferAllocator);
|
120
|
+
runWithMockClient(runnable);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
100
124
|
private void runWithMockClient(Runnable runnable) throws Exception {
|
101
125
|
@SuppressWarnings("unchecked")
|
102
126
|
Map<String, FieldProperty> mockFormFields = mock(Map.class);
|
@@ -184,15 +208,29 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
184
208
|
assertThat(reason, actual.getFieldCodes(true), is(expected.getFieldCodes(true)));
|
185
209
|
// spotless:off
|
186
210
|
actual.getFieldCodes(true).forEach(fieldCode -> assertFieldValue(domain, index, fieldCode, actual.getFieldValue(fieldCode), expected.getFieldValue(fieldCode)));
|
211
|
+
actual.getFieldCodes(true).forEach(fieldCode -> assertSubtableFieldValue(domain, index, fieldCode, actual.getFieldValue(fieldCode), expected.getFieldValue(fieldCode)));
|
187
212
|
// spotless:on
|
188
213
|
}
|
189
214
|
|
190
215
|
private static void assertFieldValue(
|
191
216
|
String domain, int index, String fieldCode, FieldValue actual, FieldValue expected) {
|
217
|
+
if (actual.getType() == FieldType.SUBTABLE) {
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
String reason = String.format("%s:%d:%s", domain, index, fieldCode);
|
221
|
+
assertThat(reason, actual.getType(), is(expected.getType()));
|
222
|
+
assertThat(reason, actual, is(expected));
|
223
|
+
}
|
224
|
+
|
225
|
+
private static void assertSubtableFieldValue(
|
226
|
+
String domain, int index, String fieldCode, FieldValue actual, FieldValue expected) {
|
227
|
+
if (actual.getType() != FieldType.SUBTABLE) {
|
228
|
+
return;
|
229
|
+
}
|
192
230
|
String reason = String.format("%s:%d:%s", domain, index, fieldCode);
|
193
231
|
assertThat(reason, actual.getType(), is(expected.getType()));
|
194
232
|
// spotless:off
|
195
|
-
|
233
|
+
assertTableRows(reason, ((SubtableFieldValue) actual).getRows(), ((SubtableFieldValue) expected).getRows());
|
196
234
|
// spotless:on
|
197
235
|
}
|
198
236
|
|
@@ -217,7 +255,7 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
217
255
|
String domain, int index, UpdateKey actual, UpdateKey expected) {
|
218
256
|
String reason = String.format("%s:%d", domain, index);
|
219
257
|
assertThat(reason, actual.getField(), is(expected.getField()));
|
220
|
-
assertThat(reason, actual.getValue(), is(expected.getValue()
|
258
|
+
assertThat(reason, actual.getValue(), is(expected.getValue()));
|
221
259
|
}
|
222
260
|
|
223
261
|
public interface Runnable {
|
@@ -1,5 +1,10 @@
|
|
1
1
|
package org.embulk.output.kintone;
|
2
2
|
|
3
|
+
import static org.mockito.Mockito.inOrder;
|
4
|
+
import static org.mockito.Mockito.spy;
|
5
|
+
import static org.mockito.Mockito.verify;
|
6
|
+
import static org.mockito.Mockito.when;
|
7
|
+
|
3
8
|
import com.google.common.io.Resources;
|
4
9
|
import com.kintone.client.Json;
|
5
10
|
import com.kintone.client.model.record.Record;
|
@@ -14,10 +19,15 @@ import java.util.Arrays;
|
|
14
19
|
import java.util.Collections;
|
15
20
|
import java.util.List;
|
16
21
|
import java.util.Objects;
|
22
|
+
import java.util.Set;
|
23
|
+
import java.util.concurrent.atomic.AtomicReference;
|
17
24
|
import java.util.function.Function;
|
18
25
|
import java.util.stream.Collectors;
|
26
|
+
import org.embulk.config.ConfigDiff;
|
19
27
|
import org.embulk.config.ConfigSource;
|
20
28
|
import org.embulk.config.TaskSource;
|
29
|
+
import org.embulk.spi.Column;
|
30
|
+
import org.embulk.spi.Exec;
|
21
31
|
import org.embulk.spi.OutputPlugin;
|
22
32
|
import org.embulk.spi.Schema;
|
23
33
|
import org.embulk.spi.TransactionalPageOutput;
|
@@ -25,6 +35,7 @@ import org.embulk.spi.json.JsonParser;
|
|
25
35
|
import org.embulk.test.EmbulkTests;
|
26
36
|
import org.embulk.test.TestingEmbulk;
|
27
37
|
import org.junit.Rule;
|
38
|
+
import org.mockito.InOrder;
|
28
39
|
import org.msgpack.value.Value;
|
29
40
|
|
30
41
|
public class TestKintoneOutputPlugin extends KintoneOutputPlugin {
|
@@ -36,18 +47,19 @@ public class TestKintoneOutputPlugin extends KintoneOutputPlugin {
|
|
36
47
|
.registerPlugin(OutputPlugin.class, "kintone", TestKintoneOutputPlugin.class)
|
37
48
|
.build();
|
38
49
|
|
50
|
+
@Override
|
51
|
+
public ConfigDiff transaction(
|
52
|
+
ConfigSource config, Schema schema, int taskCount, Control control) {
|
53
|
+
return config.get(String.class, "reduce_key", null) == null
|
54
|
+
? super.transaction(config, schema, taskCount, control)
|
55
|
+
: transactionWithVerifier(config, schema, taskCount, control);
|
56
|
+
}
|
57
|
+
|
39
58
|
@Override
|
40
59
|
public TransactionalPageOutput open(TaskSource taskSource, Schema schema, int taskIndex) {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
return new KintonePageOutputVerifier(
|
45
|
-
super.open(taskSource, schema, taskIndex),
|
46
|
-
test,
|
47
|
-
field,
|
48
|
-
getValues(test),
|
49
|
-
getAddRecords(test, mode),
|
50
|
-
getUpdateRecords(test, mode, field));
|
60
|
+
return taskSource.get(String.class, "ReduceKeyName") == null
|
61
|
+
? openWithVerifier(taskSource, schema, taskIndex)
|
62
|
+
: super.open(taskSource, schema, taskIndex);
|
51
63
|
}
|
52
64
|
|
53
65
|
protected void runOutput(String configName, String inputName) throws Exception {
|
@@ -89,8 +101,78 @@ public class TestKintoneOutputPlugin extends KintoneOutputPlugin {
|
|
89
101
|
return embulk.configLoader().fromYamlString(string);
|
90
102
|
}
|
91
103
|
|
92
|
-
private
|
93
|
-
|
104
|
+
private ConfigDiff transactionWithVerifier(
|
105
|
+
ConfigSource config, Schema schema, int taskCount, Control control) {
|
106
|
+
try (KintonePageOutputVerifier verifier = verifier(config)) {
|
107
|
+
return runWithMock(verifier, config, schema, taskCount, control);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
private ConfigDiff runWithMock(
|
112
|
+
KintonePageOutputVerifier verifier,
|
113
|
+
ConfigSource config,
|
114
|
+
Schema schema,
|
115
|
+
int taskCount,
|
116
|
+
OutputPlugin.Control control) {
|
117
|
+
String test = config.get(String.class, "domain");
|
118
|
+
PluginTask spyTask = spy(config.loadConfig(PluginTask.class));
|
119
|
+
ConfigSource spyConfig = spy(config);
|
120
|
+
when(spyConfig.loadConfig(PluginTask.class)).thenReturn(spyTask);
|
121
|
+
AtomicReference<ConfigDiff> configDiff = new AtomicReference<>();
|
122
|
+
verifier.runWithMock(
|
123
|
+
() -> configDiff.set(super.transaction(spyConfig, schema, taskCount, control)));
|
124
|
+
verify(spyConfig).loadConfig(PluginTask.class);
|
125
|
+
InOrder inOrderTask = inOrder(spyTask);
|
126
|
+
inOrderTask.verify(spyTask).setDerivedColumns(Collections.emptySet());
|
127
|
+
inOrderTask.verify(spyTask).setDerivedColumns(getDerivedColumns(test));
|
128
|
+
return configDiff.get();
|
129
|
+
}
|
130
|
+
|
131
|
+
private KintonePageOutputVerifier verifier(ConfigSource config) {
|
132
|
+
String test = config.get(String.class, "domain");
|
133
|
+
String mode = config.get(String.class, "mode");
|
134
|
+
String field = config.get(String.class, "update_key", null);
|
135
|
+
boolean preferNulls = config.get(boolean.class, "prefer_nulls", false);
|
136
|
+
boolean ignoreNulls = config.get(boolean.class, "ignore_nulls", false);
|
137
|
+
return new KintonePageOutputVerifier(
|
138
|
+
test,
|
139
|
+
field,
|
140
|
+
getValues(test, preferNulls, ignoreNulls),
|
141
|
+
getAddRecords(test, mode, preferNulls, ignoreNulls),
|
142
|
+
getUpdateRecords(test, mode, preferNulls, ignoreNulls, field));
|
143
|
+
}
|
144
|
+
|
145
|
+
private TransactionalPageOutput openWithVerifier(
|
146
|
+
TaskSource taskSource, Schema schema, int taskIndex) {
|
147
|
+
String test = taskSource.get(String.class, "Domain");
|
148
|
+
String mode = taskSource.get(String.class, "Mode");
|
149
|
+
String field = taskSource.get(String.class, "UpdateKeyName");
|
150
|
+
boolean preferNulls = taskSource.get(boolean.class, "PreferNulls");
|
151
|
+
boolean ignoreNulls = taskSource.get(boolean.class, "IgnoreNulls");
|
152
|
+
return new KintonePageOutputVerifier(
|
153
|
+
super.open(taskSource, schema, taskIndex),
|
154
|
+
test,
|
155
|
+
field,
|
156
|
+
getValues(test, preferNulls, ignoreNulls),
|
157
|
+
getAddRecords(test, mode, preferNulls, ignoreNulls),
|
158
|
+
getUpdateRecords(test, mode, preferNulls, ignoreNulls, field));
|
159
|
+
}
|
160
|
+
|
161
|
+
private static Set<Column> getDerivedColumns(String test) {
|
162
|
+
String name = String.format("%s/derived_columns.json", test);
|
163
|
+
String json = existsResource(name) ? readResource(name) : null;
|
164
|
+
return json == null || json.isEmpty()
|
165
|
+
? Collections.emptySet()
|
166
|
+
: PARSER.parse(json).asArrayValue().list().stream()
|
167
|
+
.map(value -> Exec.getModelManager().readObject(Column.class, value.toJson()))
|
168
|
+
.collect(Collectors.toSet());
|
169
|
+
}
|
170
|
+
|
171
|
+
private static List<String> getValues(String test, boolean preferNulls, boolean ignoreNulls) {
|
172
|
+
String name =
|
173
|
+
String.format(
|
174
|
+
"%s/values%s.json",
|
175
|
+
test, ignoreNulls ? "_ignore_nulls" : preferNulls ? "_prefer_nulls" : "");
|
94
176
|
String json = existsResource(name) ? readResource(name) : null;
|
95
177
|
return json == null || json.isEmpty()
|
96
178
|
? Collections.emptyList()
|
@@ -99,8 +181,12 @@ public class TestKintoneOutputPlugin extends KintoneOutputPlugin {
|
|
99
181
|
.collect(Collectors.toList());
|
100
182
|
}
|
101
183
|
|
102
|
-
private static List<Record> getAddRecords(
|
103
|
-
|
184
|
+
private static List<Record> getAddRecords(
|
185
|
+
String test, String mode, boolean preferNulls, boolean ignoreNulls) {
|
186
|
+
String name =
|
187
|
+
String.format(
|
188
|
+
"%s/%s_add%s_records.jsonl",
|
189
|
+
test, mode, ignoreNulls ? "_ignore_nulls" : preferNulls ? "_prefer_nulls" : "");
|
104
190
|
String jsonl = existsResource(name) ? readResource(name) : null;
|
105
191
|
return jsonl == null || jsonl.isEmpty()
|
106
192
|
? Collections.emptyList()
|
@@ -109,9 +195,13 @@ public class TestKintoneOutputPlugin extends KintoneOutputPlugin {
|
|
109
195
|
.collect(Collectors.toList());
|
110
196
|
}
|
111
197
|
|
112
|
-
private static List<RecordForUpdate> getUpdateRecords(
|
198
|
+
private static List<RecordForUpdate> getUpdateRecords(
|
199
|
+
String test, String mode, boolean preferNulls, boolean ignoreNulls, String field) {
|
113
200
|
Function<Record, UpdateKey> key = getKey(field);
|
114
|
-
String name =
|
201
|
+
String name =
|
202
|
+
String.format(
|
203
|
+
"%s/%s_update%s_records.jsonl",
|
204
|
+
test, mode, ignoreNulls ? "_ignore_nulls" : preferNulls ? "_prefer_nulls" : "");
|
115
205
|
String jsonl = existsResource(name) ? readResource(name) : null;
|
116
206
|
return jsonl == null || jsonl.isEmpty()
|
117
207
|
? Collections.emptyList()
|
@@ -15,17 +15,29 @@ public class TestTaskMode extends TestTask {
|
|
15
15
|
public void testInsert() throws Exception {
|
16
16
|
merge(config("mode: insert"));
|
17
17
|
runOutput();
|
18
|
+
merge(config("prefer_nulls: true"));
|
19
|
+
runOutput();
|
20
|
+
merge(config("ignore_nulls: true"));
|
21
|
+
runOutput();
|
18
22
|
}
|
19
23
|
|
20
24
|
@Test
|
21
25
|
public void testUpdate() throws Exception {
|
22
26
|
merge(config("mode: update", "update_key: string_number"));
|
23
27
|
runOutput();
|
28
|
+
merge(config("prefer_nulls: true"));
|
29
|
+
runOutput();
|
30
|
+
merge(config("ignore_nulls: true"));
|
31
|
+
runOutput();
|
24
32
|
}
|
25
33
|
|
26
34
|
@Test
|
27
35
|
public void testUpsert() throws Exception {
|
28
36
|
merge(config("mode: upsert", "update_key: double_single_line_text"));
|
29
37
|
runOutput();
|
38
|
+
merge(config("prefer_nulls: true"));
|
39
|
+
runOutput();
|
40
|
+
merge(config("ignore_nulls: true"));
|
41
|
+
runOutput();
|
30
42
|
}
|
31
43
|
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
package org.embulk.output.kintone;
|
2
|
+
|
3
|
+
import net.jcip.annotations.NotThreadSafe;
|
4
|
+
import org.junit.Test;
|
5
|
+
|
6
|
+
@NotThreadSafe
|
7
|
+
public class TestTaskReduce extends TestTask {
|
8
|
+
@Override
|
9
|
+
public void before() {
|
10
|
+
super.before();
|
11
|
+
merge(config("domain: task/reduce"));
|
12
|
+
}
|
13
|
+
|
14
|
+
@Test
|
15
|
+
public void testInsert() throws Exception {
|
16
|
+
merge(config("mode: insert"));
|
17
|
+
merge(config("reduce_key: timestamp"));
|
18
|
+
runOutput();
|
19
|
+
merge(config("prefer_nulls: true"));
|
20
|
+
runOutput();
|
21
|
+
merge(config("ignore_nulls: true"));
|
22
|
+
runOutput();
|
23
|
+
}
|
24
|
+
|
25
|
+
@Test
|
26
|
+
public void testUpdate() throws Exception {
|
27
|
+
merge(config("mode: update", "update_key: string_number"));
|
28
|
+
merge(config("reduce_key: double_single_line_text"));
|
29
|
+
runOutput();
|
30
|
+
merge(config("prefer_nulls: true"));
|
31
|
+
runOutput();
|
32
|
+
merge(config("ignore_nulls: true"));
|
33
|
+
runOutput();
|
34
|
+
}
|
35
|
+
|
36
|
+
@Test
|
37
|
+
public void testUpsert() throws Exception {
|
38
|
+
merge(config("mode: upsert", "update_key: double_single_line_text"));
|
39
|
+
merge(config("reduce_key: string_number"));
|
40
|
+
runOutput();
|
41
|
+
merge(config("prefer_nulls: true"));
|
42
|
+
runOutput();
|
43
|
+
merge(config("ignore_nulls: true"));
|
44
|
+
runOutput();
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
package org.embulk.output.kintone;
|
2
|
+
|
3
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
4
|
+
import static org.hamcrest.Matchers.instanceOf;
|
5
|
+
import static org.hamcrest.Matchers.is;
|
6
|
+
import static org.junit.Assert.assertThrows;
|
7
|
+
|
8
|
+
import net.jcip.annotations.NotThreadSafe;
|
9
|
+
import org.embulk.exec.PartialExecutionException;
|
10
|
+
import org.embulk.output.kintone.reducer.ReduceException;
|
11
|
+
import org.junit.Test;
|
12
|
+
|
13
|
+
@NotThreadSafe
|
14
|
+
public class TestTaskReduceException extends TestTask {
|
15
|
+
@Override
|
16
|
+
public void before() {
|
17
|
+
super.before();
|
18
|
+
merge(config("domain: task/reduce_exception"));
|
19
|
+
}
|
20
|
+
|
21
|
+
@Test
|
22
|
+
public void test() throws Exception {
|
23
|
+
merge(config("mode: insert"));
|
24
|
+
merge(config("reduce_key: double_single_line_text"));
|
25
|
+
runOutput();
|
26
|
+
merge(config("mode: update", "update_key: double_single_line_text"));
|
27
|
+
merge(config("reduce_key: string_number"));
|
28
|
+
runOutput();
|
29
|
+
merge(config("mode: upsert", "update_key: string_number"));
|
30
|
+
merge(config("reduce_key: json.double_single_line_text"));
|
31
|
+
assertReduceException(
|
32
|
+
"Couldn't reduce because column json.double_single_line_text is not unique to [json, json_subtable]\n[double_single_line_text, string_number] expected [123.0, 456] but actual [456.0, 123]");
|
33
|
+
merge(config("reduce_key: json.string_number"));
|
34
|
+
assertReduceException(
|
35
|
+
"Couldn't reduce because column json.string_number is not unique to [json, json_subtable]\n[double_single_line_text, string_number] expected [123.0, 456] but actual [456.0, 123]");
|
36
|
+
merge(config("reduce_key: json_subtable.double_single_line_text"));
|
37
|
+
assertReduceException(
|
38
|
+
"Couldn't reduce because column json_subtable.double_single_line_text is not unique to [json, json_subtable]\n[double_single_line_text, string_number] expected [123.0, 456] but actual [456.0, 123]");
|
39
|
+
merge(config("reduce_key: json_subtable.string_number"));
|
40
|
+
assertReduceException(
|
41
|
+
"Couldn't reduce because column json_subtable.string_number is not unique to [json, json_subtable]\n[double_single_line_text, string_number] expected [123.0, 456] but actual [456.0, 123]");
|
42
|
+
}
|
43
|
+
|
44
|
+
private void assertReduceException(String message) {
|
45
|
+
Exception e = assertThrows(PartialExecutionException.class, this::runOutput);
|
46
|
+
assertThat(e.getCause(), is(instanceOf(RuntimeException.class)));
|
47
|
+
assertThat(e.getCause().getCause(), is(instanceOf(ReduceException.class)));
|
48
|
+
assertThat(e.getCause().getCause().getMessage(), is(message));
|
49
|
+
}
|
50
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
package org.embulk.output.kintone;
|
2
|
+
|
3
|
+
import net.jcip.annotations.NotThreadSafe;
|
4
|
+
import org.junit.Test;
|
5
|
+
|
6
|
+
@NotThreadSafe
|
7
|
+
public class TestTaskReduceSubtable extends TestTask {
|
8
|
+
@Override
|
9
|
+
public void before() {
|
10
|
+
super.before();
|
11
|
+
merge(config("domain: task/reduce_subtable"));
|
12
|
+
}
|
13
|
+
|
14
|
+
@Test
|
15
|
+
public void testInsert() throws Exception {
|
16
|
+
merge(config("mode: insert"));
|
17
|
+
merge(config("reduce_key: timestamp"));
|
18
|
+
runOutput();
|
19
|
+
merge(config("prefer_nulls: true"));
|
20
|
+
runOutput();
|
21
|
+
merge(config("ignore_nulls: true"));
|
22
|
+
runOutput();
|
23
|
+
}
|
24
|
+
|
25
|
+
@Test
|
26
|
+
public void testUpdate() throws Exception {
|
27
|
+
merge(config("mode: update", "update_key: string_number"));
|
28
|
+
merge(config("reduce_key: string_number"));
|
29
|
+
runOutput();
|
30
|
+
merge(config("prefer_nulls: true"));
|
31
|
+
runOutput();
|
32
|
+
merge(config("ignore_nulls: true"));
|
33
|
+
runOutput();
|
34
|
+
}
|
35
|
+
|
36
|
+
@Test
|
37
|
+
public void testUpsert() throws Exception {
|
38
|
+
merge(config("mode: upsert", "update_key: double_single_line_text"));
|
39
|
+
merge(config("reduce_key: double_single_line_text"));
|
40
|
+
runOutput();
|
41
|
+
merge(config("prefer_nulls: true"));
|
42
|
+
runOutput();
|
43
|
+
merge(config("ignore_nulls: true"));
|
44
|
+
runOutput();
|
45
|
+
}
|
46
|
+
}
|