embulk-output-kintone 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +57 -1
  3. data/build.gradle +1 -0
  4. data/classpath/commons-csv-1.9.0.jar +0 -0
  5. data/classpath/embulk-output-kintone-1.1.0.jar +0 -0
  6. data/classpath/externalsortinginjava-0.6.2.jar +0 -0
  7. data/classpath/{shadow-kintone-java-client-1.0.0-all.jar → shadow-kintone-java-client-1.1.0-all.jar} +0 -0
  8. data/src/main/java/org/embulk/output/kintone/KintoneColumnOption.java +5 -0
  9. data/src/main/java/org/embulk/output/kintone/KintoneColumnType.java +209 -5
  10. data/src/main/java/org/embulk/output/kintone/KintoneColumnVisitor.java +28 -9
  11. data/src/main/java/org/embulk/output/kintone/KintoneOutputPlugin.java +12 -3
  12. data/src/main/java/org/embulk/output/kintone/KintonePageOutput.java +20 -12
  13. data/src/main/java/org/embulk/output/kintone/KintoneSortColumn.java +33 -0
  14. data/src/main/java/org/embulk/output/kintone/PluginTask.java +27 -0
  15. data/src/main/java/org/embulk/output/kintone/deserializer/DeserializeApplier.java +19 -0
  16. data/src/main/java/org/embulk/output/kintone/deserializer/DeserializeException.java +7 -0
  17. data/src/main/java/org/embulk/output/kintone/deserializer/Deserializer.java +279 -0
  18. data/src/main/java/org/embulk/output/kintone/reducer/CSVInputColumnVisitor.java +78 -0
  19. data/src/main/java/org/embulk/output/kintone/reducer/CSVOutputColumnVisitor.java +79 -0
  20. data/src/main/java/org/embulk/output/kintone/reducer/ReduceException.java +11 -0
  21. data/src/main/java/org/embulk/output/kintone/reducer/ReduceType.java +190 -0
  22. data/src/main/java/org/embulk/output/kintone/reducer/ReducedPageOutput.java +100 -0
  23. data/src/main/java/org/embulk/output/kintone/reducer/Reducer.java +355 -0
  24. data/src/test/java/org/embulk/output/kintone/KintoneColumnOptionBuilder.java +7 -0
  25. data/src/test/java/org/embulk/output/kintone/KintoneColumnTypeTest.java +194 -0
  26. data/src/test/java/org/embulk/output/kintone/KintoneColumnVisitorTest.java +153 -34
  27. data/src/test/java/org/embulk/output/kintone/KintoneColumnVisitorVerifier.java +13 -3
  28. data/src/test/java/org/embulk/output/kintone/KintonePageOutputVerifier.java +44 -1
  29. data/src/test/java/org/embulk/output/kintone/TestKintoneOutputPlugin.java +89 -12
  30. data/src/test/java/org/embulk/output/kintone/TestTaskReduce.java +46 -0
  31. data/src/test/java/org/embulk/output/kintone/TestTaskReduceException.java +50 -0
  32. data/src/test/java/org/embulk/output/kintone/TestTaskReduceSubtable.java +46 -0
  33. data/src/test/java/org/embulk/output/kintone/deserializer/DeserializerTest.java +165 -0
  34. data/src/test/java/org/embulk/output/kintone/reducer/ReduceTypeTest.java +154 -0
  35. data/src/test/resources/org/embulk/output/kintone/task/config.yml +1 -1
  36. data/src/test/resources/org/embulk/output/kintone/task/mode/config.yml +6 -0
  37. data/src/test/resources/org/embulk/output/kintone/task/mode/input.csv +7 -7
  38. data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_ignore_nulls_records.jsonl +2 -2
  39. data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_prefer_nulls_records.jsonl +6 -6
  40. data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_records.jsonl +6 -6
  41. data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_ignore_nulls_records.jsonl +2 -2
  42. data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_prefer_nulls_records.jsonl +3 -3
  43. data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_records.jsonl +6 -6
  44. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_add_prefer_nulls_records.jsonl +3 -3
  45. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_add_records.jsonl +2 -2
  46. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_ignore_nulls_records.jsonl +2 -2
  47. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_prefer_nulls_records.jsonl +3 -3
  48. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_records.jsonl +4 -4
  49. data/src/test/resources/org/embulk/output/kintone/task/reduce/config.yml +171 -0
  50. data/src/test/resources/org/embulk/output/kintone/task/reduce/input.csv +7 -0
  51. data/src/test/resources/org/embulk/output/kintone/task/reduce/insert_add_ignore_nulls_records.jsonl +6 -0
  52. data/src/test/resources/org/embulk/output/kintone/task/reduce/insert_add_prefer_nulls_records.jsonl +6 -0
  53. data/src/test/resources/org/embulk/output/kintone/task/reduce/insert_add_records.jsonl +6 -0
  54. data/src/test/resources/org/embulk/output/kintone/task/reduce/update_update_ignore_nulls_records.jsonl +3 -0
  55. data/src/test/resources/org/embulk/output/kintone/task/reduce/update_update_prefer_nulls_records.jsonl +3 -0
  56. data/src/test/resources/org/embulk/output/kintone/task/reduce/update_update_records.jsonl +6 -0
  57. data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_add_ignore_nulls_records.jsonl +3 -0
  58. data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_add_prefer_nulls_records.jsonl +3 -0
  59. data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_add_records.jsonl +2 -0
  60. data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_update_ignore_nulls_records.jsonl +3 -0
  61. data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_update_prefer_nulls_records.jsonl +3 -0
  62. data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_update_records.jsonl +4 -0
  63. data/src/test/resources/org/embulk/output/kintone/task/reduce/values.json +1 -0
  64. data/src/test/resources/org/embulk/output/kintone/task/reduce/values_ignore_nulls.json +1 -0
  65. data/src/test/resources/org/embulk/output/kintone/task/reduce/values_prefer_nulls.json +1 -0
  66. data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/config.yml +36 -0
  67. data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/derived_columns.json +1 -0
  68. data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/input.csv +13 -0
  69. data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/insert_add_records.jsonl +2 -0
  70. data/src/test/resources/org/embulk/output/kintone/task/reduce_exception/update_update_records.jsonl +2 -0
  71. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/config.yml +343 -0
  72. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/derived_columns.json +1 -0
  73. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/input.csv +13 -0
  74. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/insert_add_ignore_nulls_records.jsonl +6 -0
  75. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/insert_add_prefer_nulls_records.jsonl +6 -0
  76. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/insert_add_records.jsonl +6 -0
  77. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/update_update_ignore_nulls_records.jsonl +3 -0
  78. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/update_update_prefer_nulls_records.jsonl +3 -0
  79. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/update_update_records.jsonl +6 -0
  80. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_add_ignore_nulls_records.jsonl +3 -0
  81. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_add_prefer_nulls_records.jsonl +3 -0
  82. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_add_records.jsonl +0 -0
  83. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_update_ignore_nulls_records.jsonl +3 -0
  84. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_update_prefer_nulls_records.jsonl +3 -0
  85. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_update_records.jsonl +6 -0
  86. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/values.json +1 -0
  87. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/values_ignore_nulls.json +1 -0
  88. data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/values_prefer_nulls.json +1 -0
  89. metadata +62 -4
  90. data/classpath/embulk-output-kintone-1.0.0.jar +0 -0
@@ -0,0 +1,194 @@
1
+ package org.embulk.output.kintone;
2
+
3
+ import static org.embulk.output.kintone.KintoneColumnType.CHECK_BOX;
4
+ import static org.embulk.output.kintone.KintoneColumnType.DATE;
5
+ import static org.embulk.output.kintone.KintoneColumnType.DATETIME;
6
+ import static org.embulk.output.kintone.KintoneColumnType.DROP_DOWN;
7
+ import static org.embulk.output.kintone.KintoneColumnType.FILE;
8
+ import static org.embulk.output.kintone.KintoneColumnType.GROUP_SELECT;
9
+ import static org.embulk.output.kintone.KintoneColumnType.LINK;
10
+ import static org.embulk.output.kintone.KintoneColumnType.MULTI_LINE_TEXT;
11
+ import static org.embulk.output.kintone.KintoneColumnType.MULTI_SELECT;
12
+ import static org.embulk.output.kintone.KintoneColumnType.NUMBER;
13
+ import static org.embulk.output.kintone.KintoneColumnType.ORGANIZATION_SELECT;
14
+ import static org.embulk.output.kintone.KintoneColumnType.RADIO_BUTTON;
15
+ import static org.embulk.output.kintone.KintoneColumnType.RICH_TEXT;
16
+ import static org.embulk.output.kintone.KintoneColumnType.SINGLE_LINE_TEXT;
17
+ import static org.embulk.output.kintone.KintoneColumnType.SUBTABLE;
18
+ import static org.embulk.output.kintone.KintoneColumnType.TIME;
19
+ import static org.embulk.output.kintone.KintoneColumnType.USER_SELECT;
20
+ import static org.hamcrest.MatcherAssert.assertThat;
21
+ import static org.hamcrest.Matchers.is;
22
+ import static org.junit.Assert.assertThrows;
23
+
24
+ import com.kintone.client.model.record.CheckBoxFieldValue;
25
+ import com.kintone.client.model.record.DateFieldValue;
26
+ import com.kintone.client.model.record.DateTimeFieldValue;
27
+ import com.kintone.client.model.record.DropDownFieldValue;
28
+ import com.kintone.client.model.record.LinkFieldValue;
29
+ import com.kintone.client.model.record.MultiLineTextFieldValue;
30
+ import com.kintone.client.model.record.MultiSelectFieldValue;
31
+ import com.kintone.client.model.record.NumberFieldValue;
32
+ import com.kintone.client.model.record.RadioButtonFieldValue;
33
+ import com.kintone.client.model.record.RichTextFieldValue;
34
+ import com.kintone.client.model.record.SingleLineTextFieldValue;
35
+ import com.kintone.client.model.record.SubtableFieldValue;
36
+ import com.kintone.client.model.record.TableRow;
37
+ import com.kintone.client.model.record.TimeFieldValue;
38
+ import java.math.BigDecimal;
39
+ import java.time.Instant;
40
+ import java.time.LocalDate;
41
+ import java.time.LocalTime;
42
+ import java.time.ZonedDateTime;
43
+ import java.util.Arrays;
44
+ import java.util.List;
45
+ import java.util.stream.Collectors;
46
+ import org.embulk.output.kintone.deserializer.DeserializerTest;
47
+ import org.embulk.spi.time.Timestamp;
48
+ import org.junit.Test;
49
+ import org.msgpack.value.Value;
50
+ import org.msgpack.value.ValueFactory;
51
+
52
+ public class KintoneColumnTypeTest {
53
+ private static final Timestamp EPOCH = Timestamp.ofInstant(Instant.EPOCH);
54
+ private static final Value EMPTY = ValueFactory.newString("");
55
+
56
+ @Test
57
+ public void testSupportedTypes() {
58
+ // spotless:off
59
+ assertThat(((SingleLineTextFieldValue) SINGLE_LINE_TEXT.getFieldValue(false, null)).getValue(), is("false"));
60
+ assertThat(((SingleLineTextFieldValue) SINGLE_LINE_TEXT.getFieldValue(0L, null)).getValue(), is("0"));
61
+ assertThat(((SingleLineTextFieldValue) SINGLE_LINE_TEXT.getFieldValue(0.0d, null)).getValue(), is("0.0"));
62
+ assertThat(((SingleLineTextFieldValue) SINGLE_LINE_TEXT.getFieldValue("", null)).getValue(), is(""));
63
+ assertThat(((SingleLineTextFieldValue) SINGLE_LINE_TEXT.getFieldValue(EPOCH, null)).getValue(), is("1970-01-01T00:00:00Z"));
64
+ assertThat(((SingleLineTextFieldValue) SINGLE_LINE_TEXT.getFieldValue(EMPTY, null)).getValue(), is("\"\""));
65
+ assertThat(((MultiLineTextFieldValue) MULTI_LINE_TEXT.getFieldValue(false, null)).getValue(), is("false"));
66
+ assertThat(((MultiLineTextFieldValue) MULTI_LINE_TEXT.getFieldValue(0L, null)).getValue(), is("0"));
67
+ assertThat(((MultiLineTextFieldValue) MULTI_LINE_TEXT.getFieldValue(0.0d, null)).getValue(), is("0.0"));
68
+ assertThat(((MultiLineTextFieldValue) MULTI_LINE_TEXT.getFieldValue("", null)).getValue(), is(""));
69
+ assertThat(((MultiLineTextFieldValue) MULTI_LINE_TEXT.getFieldValue(EPOCH, null)).getValue(), is("1970-01-01T00:00:00Z"));
70
+ assertThat(((MultiLineTextFieldValue) MULTI_LINE_TEXT.getFieldValue(EMPTY, null)).getValue(), is("\"\""));
71
+ assertThat(((RichTextFieldValue) RICH_TEXT.getFieldValue(false, null)).getValue(), is("false"));
72
+ assertThat(((RichTextFieldValue) RICH_TEXT.getFieldValue(0L, null)).getValue(), is("0"));
73
+ assertThat(((RichTextFieldValue) RICH_TEXT.getFieldValue(0.0d, null)).getValue(), is("0.0"));
74
+ assertThat(((RichTextFieldValue) RICH_TEXT.getFieldValue("", null)).getValue(), is(""));
75
+ assertThat(((RichTextFieldValue) RICH_TEXT.getFieldValue(EPOCH, null)).getValue(), is("1970-01-01T00:00:00Z"));
76
+ assertThat(((RichTextFieldValue) RICH_TEXT.getFieldValue(EMPTY, null)).getValue(), is("\"\""));
77
+ assertThat(((NumberFieldValue) NUMBER.getFieldValue(false, null)).getValue(), is(number("0")));
78
+ assertThat(((NumberFieldValue) NUMBER.getFieldValue(0L, null)).getValue(), is(number("0")));
79
+ assertThat(((NumberFieldValue) NUMBER.getFieldValue(0.0d, null)).getValue(), is(number("0.0")));
80
+ assertThat(((NumberFieldValue) NUMBER.getFieldValue("", null)).getValue(), is(number("0")));
81
+ assertThat(((NumberFieldValue) NUMBER.getFieldValue(EPOCH, null)).getValue(), is(number("0")));
82
+ assertThat(((CheckBoxFieldValue) CHECK_BOX.getFieldValue("", null)).getValues(), is(list()));
83
+ assertThat(((RadioButtonFieldValue) RADIO_BUTTON.getFieldValue("", null)).getValue(), is(""));
84
+ assertThat(((MultiSelectFieldValue) MULTI_SELECT.getFieldValue("", null)).getValues(), is(list()));
85
+ assertThat(((DropDownFieldValue) DROP_DOWN.getFieldValue("", null)).getValue(), is(""));
86
+ assertThat(((DateFieldValue) DATE.getFieldValue(0L, null)).getValue(), is(date("1970-01-01")));
87
+ assertThat(((DateFieldValue) DATE.getFieldValue(0.0d, null)).getValue(), is(date("1970-01-01")));
88
+ assertThat(((DateFieldValue) DATE.getFieldValue("", null)).getValue(), is(date("1970-01-01")));
89
+ assertThat(((DateFieldValue) DATE.getFieldValue(EPOCH, null)).getValue(), is(date("1970-01-01")));
90
+ assertThat(((TimeFieldValue) TIME.getFieldValue(0L, null)).getValue(), is(time("00:00:00")));
91
+ assertThat(((TimeFieldValue) TIME.getFieldValue(0.0d, null)).getValue(), is(time("00:00:00")));
92
+ assertThat(((TimeFieldValue) TIME.getFieldValue("", null)).getValue(), is(time("00:00:00")));
93
+ assertThat(((TimeFieldValue) TIME.getFieldValue(EPOCH, null)).getValue(), is(time("00:00:00")));
94
+ assertThat(((DateTimeFieldValue) DATETIME.getFieldValue(0L, null)).getValue(), is(dateTime("1970-01-01T00:00:00Z")));
95
+ assertThat(((DateTimeFieldValue) DATETIME.getFieldValue(0.0d, null)).getValue(), is(dateTime("1970-01-01T00:00:00Z")));
96
+ assertThat(((DateTimeFieldValue) DATETIME.getFieldValue("", null)).getValue(), is(dateTime("1970-01-01T00:00:00Z")));
97
+ assertThat(((DateTimeFieldValue) DATETIME.getFieldValue(EPOCH, null)).getValue(), is(dateTime("1970-01-01T00:00:00Z")));
98
+ assertThat(((LinkFieldValue) LINK.getFieldValue("", null)).getValue(), is(""));
99
+ assertThat(((SubtableFieldValue) SUBTABLE.getFieldValue("", null)).getRows(), is(rows()));
100
+ assertThat(((SubtableFieldValue) SUBTABLE.getFieldValue(EMPTY, null)).getRows(), is(rows()));
101
+ // spotless:on
102
+ }
103
+
104
+ @Test
105
+ public void testUnsupportedTypes() {
106
+ // spotless:off
107
+ assertThrows(UnsupportedOperationException.class, () -> NUMBER.getFieldValue(EMPTY, null));
108
+ assertThrows(UnsupportedOperationException.class, () -> CHECK_BOX.getFieldValue(false, null));
109
+ assertThrows(UnsupportedOperationException.class, () -> CHECK_BOX.getFieldValue(0L, null));
110
+ assertThrows(UnsupportedOperationException.class, () -> CHECK_BOX.getFieldValue(0.0d, null));
111
+ assertThrows(UnsupportedOperationException.class, () -> CHECK_BOX.getFieldValue(EPOCH, null));
112
+ assertThrows(UnsupportedOperationException.class, () -> CHECK_BOX.getFieldValue(EMPTY, null));
113
+ assertThrows(UnsupportedOperationException.class, () -> RADIO_BUTTON.getFieldValue(false, null));
114
+ assertThrows(UnsupportedOperationException.class, () -> RADIO_BUTTON.getFieldValue(0L, null));
115
+ assertThrows(UnsupportedOperationException.class, () -> RADIO_BUTTON.getFieldValue(0.0d, null));
116
+ assertThrows(UnsupportedOperationException.class, () -> RADIO_BUTTON.getFieldValue(EPOCH, null));
117
+ assertThrows(UnsupportedOperationException.class, () -> RADIO_BUTTON.getFieldValue(EMPTY, null));
118
+ assertThrows(UnsupportedOperationException.class, () -> MULTI_SELECT.getFieldValue(false, null));
119
+ assertThrows(UnsupportedOperationException.class, () -> MULTI_SELECT.getFieldValue(0L, null));
120
+ assertThrows(UnsupportedOperationException.class, () -> MULTI_SELECT.getFieldValue(0.0d, null));
121
+ assertThrows(UnsupportedOperationException.class, () -> MULTI_SELECT.getFieldValue(EPOCH, null));
122
+ assertThrows(UnsupportedOperationException.class, () -> MULTI_SELECT.getFieldValue(EMPTY, null));
123
+ assertThrows(UnsupportedOperationException.class, () -> DROP_DOWN.getFieldValue(false, null));
124
+ assertThrows(UnsupportedOperationException.class, () -> DROP_DOWN.getFieldValue(0L, null));
125
+ assertThrows(UnsupportedOperationException.class, () -> DROP_DOWN.getFieldValue(0.0d, null));
126
+ assertThrows(UnsupportedOperationException.class, () -> DROP_DOWN.getFieldValue(EPOCH, null));
127
+ assertThrows(UnsupportedOperationException.class, () -> DROP_DOWN.getFieldValue(EMPTY, null));
128
+ assertThrows(UnsupportedOperationException.class, () -> USER_SELECT.getFieldValue(false, null));
129
+ assertThrows(UnsupportedOperationException.class, () -> USER_SELECT.getFieldValue(0L, null));
130
+ assertThrows(UnsupportedOperationException.class, () -> USER_SELECT.getFieldValue(0.0d, null));
131
+ assertThrows(UnsupportedOperationException.class, () -> USER_SELECT.getFieldValue("", null));
132
+ assertThrows(UnsupportedOperationException.class, () -> USER_SELECT.getFieldValue(EPOCH, null));
133
+ assertThrows(UnsupportedOperationException.class, () -> USER_SELECT.getFieldValue(EMPTY, null));
134
+ assertThrows(UnsupportedOperationException.class, () -> ORGANIZATION_SELECT.getFieldValue(false, null));
135
+ assertThrows(UnsupportedOperationException.class, () -> ORGANIZATION_SELECT.getFieldValue(0L, null));
136
+ assertThrows(UnsupportedOperationException.class, () -> ORGANIZATION_SELECT.getFieldValue(0.0d, null));
137
+ assertThrows(UnsupportedOperationException.class, () -> ORGANIZATION_SELECT.getFieldValue("", null));
138
+ assertThrows(UnsupportedOperationException.class, () -> ORGANIZATION_SELECT.getFieldValue(EPOCH, null));
139
+ assertThrows(UnsupportedOperationException.class, () -> ORGANIZATION_SELECT.getFieldValue(EMPTY, null));
140
+ assertThrows(UnsupportedOperationException.class, () -> GROUP_SELECT.getFieldValue(false, null));
141
+ assertThrows(UnsupportedOperationException.class, () -> GROUP_SELECT.getFieldValue(0L, null));
142
+ assertThrows(UnsupportedOperationException.class, () -> GROUP_SELECT.getFieldValue(0.0d, null));
143
+ assertThrows(UnsupportedOperationException.class, () -> GROUP_SELECT.getFieldValue("", null));
144
+ assertThrows(UnsupportedOperationException.class, () -> GROUP_SELECT.getFieldValue(EPOCH, null));
145
+ assertThrows(UnsupportedOperationException.class, () -> GROUP_SELECT.getFieldValue(EMPTY, null));
146
+ assertThrows(UnsupportedOperationException.class, () -> DATE.getFieldValue(false, null));
147
+ assertThrows(UnsupportedOperationException.class, () -> DATE.getFieldValue(EMPTY, null));
148
+ assertThrows(UnsupportedOperationException.class, () -> TIME.getFieldValue(false, null));
149
+ assertThrows(UnsupportedOperationException.class, () -> TIME.getFieldValue(EMPTY, null));
150
+ assertThrows(UnsupportedOperationException.class, () -> DATETIME.getFieldValue(false, null));
151
+ assertThrows(UnsupportedOperationException.class, () -> DATETIME.getFieldValue(EMPTY, null));
152
+ assertThrows(UnsupportedOperationException.class, () -> LINK.getFieldValue(false, null));
153
+ assertThrows(UnsupportedOperationException.class, () -> LINK.getFieldValue(0L, null));
154
+ assertThrows(UnsupportedOperationException.class, () -> LINK.getFieldValue(0.0d, null));
155
+ assertThrows(UnsupportedOperationException.class, () -> LINK.getFieldValue(EPOCH, null));
156
+ assertThrows(UnsupportedOperationException.class, () -> LINK.getFieldValue(EMPTY, null));
157
+ assertThrows(UnsupportedOperationException.class, () -> FILE.getFieldValue(false, null));
158
+ assertThrows(UnsupportedOperationException.class, () -> FILE.getFieldValue(0L, null));
159
+ assertThrows(UnsupportedOperationException.class, () -> FILE.getFieldValue(0.0d, null));
160
+ assertThrows(UnsupportedOperationException.class, () -> FILE.getFieldValue("", null));
161
+ assertThrows(UnsupportedOperationException.class, () -> FILE.getFieldValue(EPOCH, null));
162
+ assertThrows(UnsupportedOperationException.class, () -> FILE.getFieldValue(EMPTY, null));
163
+ assertThrows(UnsupportedOperationException.class, () -> SUBTABLE.getFieldValue(false, null));
164
+ assertThrows(UnsupportedOperationException.class, () -> SUBTABLE.getFieldValue(0L, null));
165
+ assertThrows(UnsupportedOperationException.class, () -> SUBTABLE.getFieldValue(0.0d, null));
166
+ assertThrows(UnsupportedOperationException.class, () -> SUBTABLE.getFieldValue(EPOCH, null));
167
+ // spotless:on
168
+ }
169
+
170
+ public static BigDecimal number(String value) {
171
+ return new BigDecimal(value);
172
+ }
173
+
174
+ @SafeVarargs
175
+ public static <T> List<T> list(T... a) {
176
+ return Arrays.asList(a);
177
+ }
178
+
179
+ public static List<TableRow> rows(Long... ids) {
180
+ return Arrays.stream(ids).map(DeserializerTest::tableRow).collect(Collectors.toList());
181
+ }
182
+
183
+ public static LocalDate date(CharSequence text) {
184
+ return LocalDate.parse(text);
185
+ }
186
+
187
+ public static LocalTime time(CharSequence text) {
188
+ return LocalTime.parse(text);
189
+ }
190
+
191
+ public static ZonedDateTime dateTime(CharSequence text) {
192
+ return ZonedDateTime.parse(text);
193
+ }
194
+ }
@@ -1,5 +1,12 @@
1
1
  package org.embulk.output.kintone;
2
2
 
3
+ import static org.embulk.output.kintone.KintoneColumnTypeTest.date;
4
+ import static org.embulk.output.kintone.KintoneColumnTypeTest.dateTime;
5
+ import static org.embulk.output.kintone.KintoneColumnTypeTest.list;
6
+ import static org.embulk.output.kintone.KintoneColumnTypeTest.number;
7
+ import static org.embulk.output.kintone.KintoneColumnTypeTest.rows;
8
+ import static org.embulk.output.kintone.KintoneColumnTypeTest.time;
9
+ import static org.embulk.output.kintone.deserializer.DeserializerTest.assertTableRows;
3
10
  import static org.hamcrest.MatcherAssert.assertThat;
4
11
  import static org.hamcrest.Matchers.is;
5
12
  import static org.hamcrest.Matchers.nullValue;
@@ -7,27 +14,35 @@ import static org.junit.Assert.assertThrows;
7
14
 
8
15
  import com.google.common.collect.ImmutableMap;
9
16
  import com.kintone.client.model.record.FieldType;
10
- import java.math.BigDecimal;
11
17
  import java.time.Instant;
12
- import java.time.LocalDate;
13
- import java.time.LocalTime;
14
- import java.time.ZonedDateTime;
15
18
  import java.util.AbstractMap;
16
- import java.util.Arrays;
17
- import java.util.List;
19
+ import java.util.Collections;
18
20
  import java.util.Map;
19
21
  import java.util.function.Function;
22
+ import org.embulk.output.kintone.deserializer.DeserializerTest;
20
23
  import org.embulk.spi.Page;
21
24
  import org.embulk.spi.Schema;
25
+ import org.embulk.spi.json.JsonParser;
22
26
  import org.embulk.spi.time.Timestamp;
23
27
  import org.embulk.spi.type.Types;
24
28
  import org.junit.Test;
29
+ import org.msgpack.value.Value;
25
30
  import org.msgpack.value.ValueFactory;
26
31
 
27
32
  public class KintoneColumnVisitorTest {
33
+ private static final JsonParser PARSER = new JsonParser();
34
+ private static final String[] ROWS = {
35
+ DeserializerTest.TABLE_ROW.apply(0L),
36
+ DeserializerTest.TABLE_ROW.apply(1L),
37
+ DeserializerTest.TABLE_ROW.apply(2L),
38
+ DeserializerTest.TABLE_ROW.apply(3L),
39
+ DeserializerTest.TABLE_ROW.apply(4L),
40
+ DeserializerTest.TABLE_ROW.apply(5L),
41
+ };
42
+
28
43
  @Test
29
44
  public void test() {
30
- KintoneColumnVisitorVerifier verifier = verifier("STRING|SINGLE_LINE_TEXT");
45
+ KintoneColumnVisitorVerifier verifier = verifier(null, "STRING|SINGLE_LINE_TEXT");
31
46
  verifier.verify(
32
47
  (record, updateKey) -> {
33
48
  assertThat(record.getSingleLineTextFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), is("false"));
@@ -71,6 +86,7 @@ public class KintoneColumnVisitorTest {
71
86
  record.getDateTimeFieldValue("STRING|DATETIME"),
72
87
  is(dateTime("1970-01-01T00:00:00Z")));
73
88
  assertThat(record.getLinkFieldValue("STRING|LINK"), is(""));
89
+ assertThat(record.getSubtableFieldValue("STRING|SUBTABLE"), is(list()));
74
90
  assertThat(
75
91
  record.getSingleLineTextFieldValue("TIMESTAMP|SINGLE_LINE_TEXT"),
76
92
  is("1970-01-01T00:00:00Z"));
@@ -85,6 +101,9 @@ public class KintoneColumnVisitorTest {
85
101
  record.getDateTimeFieldValue("TIMESTAMP"), is(dateTime("1970-01-01T00:00:00Z")));
86
102
  assertThat(record.getSingleLineTextFieldValue("JSON|SINGLE_LINE_TEXT"), is("\"\""));
87
103
  assertThat(record.getMultiLineTextFieldValue("JSON"), is("\"\""));
104
+ assertThat(record.getSubtableFieldValue("JSON|SUBTABLE"), is(list()));
105
+ assertThat(
106
+ record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), is("\"\""));
88
107
  assertThat(updateKey.getField(), is("STRING|SINGLE_LINE_TEXT"));
89
108
  assertThat(updateKey.getValue(), is(""));
90
109
  });
@@ -131,6 +150,7 @@ public class KintoneColumnVisitorTest {
131
150
  record.getDateTimeFieldValue("STRING|DATETIME"),
132
151
  is(dateTime("1970-01-01T00:00:00Z")));
133
152
  assertThat(record.getLinkFieldValue("STRING|LINK"), is(""));
153
+ assertThat(record.getSubtableFieldValue("STRING|SUBTABLE"), is(list()));
134
154
  assertThat(
135
155
  record.getSingleLineTextFieldValue("TIMESTAMP|SINGLE_LINE_TEXT"),
136
156
  is("1970-01-01T00:00:00Z"));
@@ -145,6 +165,9 @@ public class KintoneColumnVisitorTest {
145
165
  record.getDateTimeFieldValue("TIMESTAMP"), is(dateTime("1970-01-01T00:00:00Z")));
146
166
  assertThat(record.getSingleLineTextFieldValue("JSON|SINGLE_LINE_TEXT"), is("\"\""));
147
167
  assertThat(record.getMultiLineTextFieldValue("JSON"), is("\"\""));
168
+ assertThat(record.getSubtableFieldValue("JSON|SUBTABLE"), is(list()));
169
+ assertThat(
170
+ record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), is("\"\""));
148
171
  assertThat(updateKey.getField(), is("STRING|SINGLE_LINE_TEXT"));
149
172
  assertThat(updateKey.getValue(), is(""));
150
173
  });
@@ -192,6 +215,7 @@ public class KintoneColumnVisitorTest {
192
215
  record.getDateTimeFieldValue("STRING|DATETIME"),
193
216
  is(dateTime("1999-12-31T23:59:59Z")));
194
217
  assertThat(record.getLinkFieldValue("STRING|LINK"), is("abc"));
218
+ assertTableRows(record.getSubtableFieldValue("STRING|SUBTABLE"), rows(0L, 1L, 2L));
195
219
  assertThat(
196
220
  record.getSingleLineTextFieldValue("TIMESTAMP|SINGLE_LINE_TEXT"),
197
221
  is("1999-12-31T23:59:59Z"));
@@ -206,6 +230,9 @@ public class KintoneColumnVisitorTest {
206
230
  record.getDateTimeFieldValue("TIMESTAMP"), is(dateTime("1999-12-31T23:59:59Z")));
207
231
  assertThat(record.getSingleLineTextFieldValue("JSON|SINGLE_LINE_TEXT"), is("\"abc\""));
208
232
  assertThat(record.getMultiLineTextFieldValue("JSON"), is("\"abc\""));
233
+ assertTableRows(record.getSubtableFieldValue("JSON|SUBTABLE"), rows(0L, 1L, 2L));
234
+ assertThat(
235
+ record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), is("\"abc\""));
209
236
  assertThat(updateKey.getField(), is("STRING|SINGLE_LINE_TEXT"));
210
237
  assertThat(updateKey.getValue(), is("abc"));
211
238
  });
@@ -253,6 +280,7 @@ public class KintoneColumnVisitorTest {
253
280
  record.getDateTimeFieldValue("STRING|DATETIME"),
254
281
  is(dateTime("2000-01-01T00:00:00Z")));
255
282
  assertThat(record.getLinkFieldValue("STRING|LINK"), is("def"));
283
+ assertTableRows(record.getSubtableFieldValue("STRING|SUBTABLE"), rows(3L, 4L, 5L));
256
284
  assertThat(
257
285
  record.getSingleLineTextFieldValue("TIMESTAMP|SINGLE_LINE_TEXT"),
258
286
  is("2000-01-01T00:00:00Z"));
@@ -267,6 +295,9 @@ public class KintoneColumnVisitorTest {
267
295
  record.getDateTimeFieldValue("TIMESTAMP"), is(dateTime("2000-01-01T00:00:00Z")));
268
296
  assertThat(record.getSingleLineTextFieldValue("JSON|SINGLE_LINE_TEXT"), is("\"def\""));
269
297
  assertThat(record.getMultiLineTextFieldValue("JSON"), is("\"def\""));
298
+ assertTableRows(record.getSubtableFieldValue("JSON|SUBTABLE"), rows(3L, 4L, 5L));
299
+ assertThat(
300
+ record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), is("\"def\""));
270
301
  assertThat(updateKey.getField(), is("STRING|SINGLE_LINE_TEXT"));
271
302
  assertThat(updateKey.getValue(), is("def"));
272
303
  });
@@ -274,7 +305,7 @@ public class KintoneColumnVisitorTest {
274
305
 
275
306
  @Test
276
307
  public void testPreferNulls() {
277
- KintoneColumnVisitorVerifier verifier = verifier("LONG", true, false);
308
+ KintoneColumnVisitorVerifier verifier = verifier(null, "LONG", true, false);
278
309
  verifier.verify(
279
310
  (record, updateKey) -> {
280
311
  assertThat(
@@ -316,6 +347,7 @@ public class KintoneColumnVisitorTest {
316
347
  assertThat(record.getFieldType("STRING|TIME|PST"), is(FieldType.TIME));
317
348
  assertThat(record.getFieldType("STRING|DATETIME"), is(FieldType.DATETIME));
318
349
  assertThat(record.getFieldType("STRING|LINK"), is(FieldType.LINK));
350
+ assertThat(record.getFieldType("STRING|SUBTABLE"), is(FieldType.SUBTABLE));
319
351
  assertThat(
320
352
  record.getFieldType("TIMESTAMP|SINGLE_LINE_TEXT"), is(FieldType.SINGLE_LINE_TEXT));
321
353
  assertThat(record.getFieldType("TIMESTAMP|NUMBER"), is(FieldType.NUMBER));
@@ -328,6 +360,10 @@ public class KintoneColumnVisitorTest {
328
360
  assertThat(record.getFieldType("TIMESTAMP"), is(FieldType.DATETIME));
329
361
  assertThat(record.getFieldType("JSON|SINGLE_LINE_TEXT"), is(FieldType.SINGLE_LINE_TEXT));
330
362
  assertThat(record.getFieldType("JSON"), is(FieldType.MULTI_LINE_TEXT));
363
+ assertThat(record.getFieldType("JSON|SUBTABLE"), is(FieldType.SUBTABLE));
364
+ assertThat(
365
+ record.getFieldType("JSON|SUBTABLE.SINGLE_LINE_TEXT"),
366
+ is(FieldType.SINGLE_LINE_TEXT));
331
367
  assertThat(record.getSingleLineTextFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), nullValue());
332
368
  assertThat(record.getNumberFieldValue("BOOLEAN"), nullValue());
333
369
  assertThat(record.getSingleLineTextFieldValue("LONG|SINGLE_LINE_TEXT"), nullValue());
@@ -364,6 +400,7 @@ public class KintoneColumnVisitorTest {
364
400
  assertThat(record.getTimeFieldValue("STRING|TIME|PST"), nullValue());
365
401
  assertThat(record.getDateTimeFieldValue("STRING|DATETIME"), nullValue());
366
402
  assertThat(record.getLinkFieldValue("STRING|LINK"), nullValue());
403
+ assertThat(record.getSubtableFieldValue("STRING|SUBTABLE"), is(list()));
367
404
  assertThat(record.getSingleLineTextFieldValue("TIMESTAMP|SINGLE_LINE_TEXT"), nullValue());
368
405
  assertThat(record.getNumberFieldValue("TIMESTAMP|NUMBER"), nullValue());
369
406
  assertThat(record.getDateFieldValue("TIMESTAMP|DATE"), nullValue());
@@ -375,6 +412,9 @@ public class KintoneColumnVisitorTest {
375
412
  assertThat(record.getDateTimeFieldValue("TIMESTAMP"), nullValue());
376
413
  assertThat(record.getSingleLineTextFieldValue("JSON|SINGLE_LINE_TEXT"), nullValue());
377
414
  assertThat(record.getMultiLineTextFieldValue("JSON"), nullValue());
415
+ assertThat(record.getSubtableFieldValue("JSON|SUBTABLE"), is(list()));
416
+ assertThat(
417
+ record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), nullValue());
378
418
  assertThat(updateKey.getField(), is("LONG"));
379
419
  assertThat(updateKey.getValue(), nullValue());
380
420
  });
@@ -382,7 +422,7 @@ public class KintoneColumnVisitorTest {
382
422
 
383
423
  @Test
384
424
  public void testIgnoreNulls() {
385
- KintoneColumnVisitorVerifier verifier = verifier("JSON", false, true);
425
+ KintoneColumnVisitorVerifier verifier = verifier("JSON", "JSON", false, true);
386
426
  verifier.verify(
387
427
  (record, updateKey) -> {
388
428
  assertThat(record.getFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), nullValue());
@@ -421,6 +461,7 @@ public class KintoneColumnVisitorTest {
421
461
  assertThat(record.getFieldValue("STRING|TIME|PST"), nullValue());
422
462
  assertThat(record.getFieldValue("STRING|DATETIME"), nullValue());
423
463
  assertThat(record.getFieldValue("STRING|LINK"), nullValue());
464
+ assertThat(record.getFieldValue("STRING|SUBTABLE"), nullValue());
424
465
  assertThat(record.getFieldValue("TIMESTAMP|SINGLE_LINE_TEXT"), nullValue());
425
466
  assertThat(record.getFieldValue("TIMESTAMP|NUMBER"), nullValue());
426
467
  assertThat(record.getFieldValue("TIMESTAMP|DATE"), nullValue());
@@ -432,6 +473,77 @@ public class KintoneColumnVisitorTest {
432
473
  assertThat(record.getFieldValue("TIMESTAMP"), nullValue());
433
474
  assertThat(record.getFieldValue("JSON|SINGLE_LINE_TEXT"), nullValue());
434
475
  assertThat(record.getFieldValue("JSON"), nullValue());
476
+ assertThat(record.getFieldValue("JSON|SUBTABLE"), nullValue());
477
+ assertThat(record.getFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), nullValue());
478
+ assertThat(updateKey.getField(), nullValue());
479
+ assertThat(updateKey.getValue(), nullValue());
480
+ },
481
+ true);
482
+ }
483
+
484
+ @Test
485
+ public void testReduceKey() {
486
+ KintoneColumnVisitorVerifier verifier = verifier("JSON|SUBTABLE", null);
487
+ verifier.verify(
488
+ (record, updateKey) -> {
489
+ assertThat(record.getSingleLineTextFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), is("false"));
490
+ assertThat(record.getNumberFieldValue("BOOLEAN"), is(number("0")));
491
+ assertThat(record.getSingleLineTextFieldValue("LONG|SINGLE_LINE_TEXT"), is("0"));
492
+ assertThat(record.getNumberFieldValue("LONG"), is(number("0")));
493
+ assertThat(record.getDateFieldValue("LONG|DATE"), is(date("1970-01-01")));
494
+ assertThat(record.getDateFieldValue("LONG|DATE|JST"), is(date("1970-01-01")));
495
+ assertThat(record.getDateFieldValue("LONG|DATE|PST"), is(date("1969-12-31")));
496
+ assertThat(record.getTimeFieldValue("LONG|TIME"), is(time("00:00:00")));
497
+ assertThat(record.getTimeFieldValue("LONG|TIME|JST"), is(time("09:00:00")));
498
+ assertThat(record.getTimeFieldValue("LONG|TIME|PST"), is(time("16:00:00")));
499
+ assertThat(
500
+ record.getDateTimeFieldValue("LONG|DATETIME"), is(dateTime("1970-01-01T00:00:00Z")));
501
+ assertThat(record.getSingleLineTextFieldValue("DOUBLE|SINGLE_LINE_TEXT"), is("0.0"));
502
+ assertThat(record.getNumberFieldValue("DOUBLE"), is(number("0.0")));
503
+ assertThat(record.getDateFieldValue("DOUBLE|DATE"), is(date("1970-01-01")));
504
+ assertThat(record.getDateFieldValue("DOUBLE|DATE|JST"), is(date("1970-01-01")));
505
+ assertThat(record.getDateFieldValue("DOUBLE|DATE|PST"), is(date("1969-12-31")));
506
+ assertThat(record.getTimeFieldValue("DOUBLE|TIME"), is(time("00:00:00")));
507
+ assertThat(record.getTimeFieldValue("DOUBLE|TIME|JST"), is(time("09:00:00")));
508
+ assertThat(record.getTimeFieldValue("DOUBLE|TIME|PST"), is(time("16:00:00")));
509
+ assertThat(
510
+ record.getDateTimeFieldValue("DOUBLE|DATETIME"),
511
+ is(dateTime("1970-01-01T00:00:00Z")));
512
+ assertThat(record.getSingleLineTextFieldValue("STRING|SINGLE_LINE_TEXT"), is(""));
513
+ assertThat(record.getMultiLineTextFieldValue("STRING"), is(""));
514
+ assertThat(record.getRichTextFieldValue("STRING|RICH_TEXT"), is(""));
515
+ assertThat(record.getNumberFieldValue("STRING|NUMBER"), is(number("0")));
516
+ assertThat(record.getCheckBoxFieldValue("STRING|CHECK_BOX"), is(list()));
517
+ assertThat(record.getRadioButtonFieldValue("STRING|RADIO_BUTTON"), is(""));
518
+ assertThat(record.getMultiSelectFieldValue("STRING|MULTI_SELECT"), is(list()));
519
+ assertThat(record.getDropDownFieldValue("STRING|DROP_DOWN"), is(""));
520
+ assertThat(record.getDateFieldValue("STRING|DATE"), is(date("1970-01-01")));
521
+ assertThat(record.getDateFieldValue("STRING|DATE|JST"), is(date("1970-01-01")));
522
+ assertThat(record.getDateFieldValue("STRING|DATE|PST"), is(date("1969-12-31")));
523
+ assertThat(record.getTimeFieldValue("STRING|TIME"), is(time("00:00:00")));
524
+ assertThat(record.getTimeFieldValue("STRING|TIME|JST"), is(time("09:00:00")));
525
+ assertThat(record.getTimeFieldValue("STRING|TIME|PST"), is(time("16:00:00")));
526
+ assertThat(
527
+ record.getDateTimeFieldValue("STRING|DATETIME"),
528
+ is(dateTime("1970-01-01T00:00:00Z")));
529
+ assertThat(record.getLinkFieldValue("STRING|LINK"), is(""));
530
+ assertThat(record.getSubtableFieldValue("STRING|SUBTABLE"), is(list()));
531
+ assertThat(
532
+ record.getSingleLineTextFieldValue("TIMESTAMP|SINGLE_LINE_TEXT"),
533
+ is("1970-01-01T00:00:00Z"));
534
+ assertThat(record.getNumberFieldValue("TIMESTAMP|NUMBER"), is(number("0")));
535
+ assertThat(record.getDateFieldValue("TIMESTAMP|DATE"), is(date("1970-01-01")));
536
+ assertThat(record.getDateFieldValue("TIMESTAMP|DATE|JST"), is(date("1970-01-01")));
537
+ assertThat(record.getDateFieldValue("TIMESTAMP|DATE|PST"), is(date("1969-12-31")));
538
+ assertThat(record.getTimeFieldValue("TIMESTAMP|TIME"), is(time("00:00:00")));
539
+ assertThat(record.getTimeFieldValue("TIMESTAMP|TIME|JST"), is(time("09:00:00")));
540
+ assertThat(record.getTimeFieldValue("TIMESTAMP|TIME|PST"), is(time("16:00:00")));
541
+ assertThat(
542
+ record.getDateTimeFieldValue("TIMESTAMP"), is(dateTime("1970-01-01T00:00:00Z")));
543
+ assertThat(record.getSingleLineTextFieldValue("JSON|SINGLE_LINE_TEXT"), is("\"\""));
544
+ assertThat(record.getMultiLineTextFieldValue("JSON"), is("\"\""));
545
+ assertThat(record.getSubtableFieldValue("JSON|SUBTABLE"), is(list()));
546
+ assertThat(record.getFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), nullValue());
435
547
  assertThat(updateKey.getField(), nullValue());
436
548
  assertThat(updateKey.getValue(), nullValue());
437
549
  },
@@ -440,8 +552,8 @@ public class KintoneColumnVisitorTest {
440
552
 
441
553
  @Test
442
554
  public void testUpdateKey() {
443
- assertThrows(UnsupportedOperationException.class, () -> verifier("TIMESTAMP").verify());
444
- KintoneColumnVisitorVerifier verifier = verifier("TIMESTAMP|NUMBER");
555
+ assertThrows(UnsupportedOperationException.class, () -> verifier(null, "TIMESTAMP").verify());
556
+ KintoneColumnVisitorVerifier verifier = verifier(null, "TIMESTAMP|NUMBER");
445
557
  verifier.verify(
446
558
  (record, updateKey) -> {
447
559
  assertThat(updateKey.getField(), is("TIMESTAMP|NUMBER"));
@@ -464,23 +576,27 @@ public class KintoneColumnVisitorTest {
464
576
  });
465
577
  }
466
578
 
467
- private static KintoneColumnVisitorVerifier verifier(String updateKeyName) {
579
+ private static KintoneColumnVisitorVerifier verifier(String reduceKeyName, String updateKeyName) {
468
580
  Schema schema = build(Schema.builder());
469
581
  return new KintoneColumnVisitorVerifier(
470
582
  schema,
583
+ Collections.emptySet(),
471
584
  build(ImmutableMap.builder()),
585
+ reduceKeyName,
472
586
  updateKeyName,
473
587
  OutputPageBuilder.build(schema, KintoneColumnVisitorTest::build));
474
588
  }
475
589
 
476
590
  private static KintoneColumnVisitorVerifier verifier(
477
- String updateKeyName, boolean preferNulls, boolean ignoreNulls) {
591
+ String reduceKeyName, String updateKeyName, boolean preferNulls, boolean ignoreNulls) {
478
592
  Schema schema = build(Schema.builder());
479
593
  return new KintoneColumnVisitorVerifier(
480
594
  schema,
595
+ Collections.emptySet(),
481
596
  build(ImmutableMap.builder()),
482
597
  preferNulls,
483
598
  ignoreNulls,
599
+ reduceKeyName,
484
600
  updateKeyName,
485
601
  OutputPageBuilder.build(schema, KintoneColumnVisitorTest::build));
486
602
  }
@@ -523,6 +639,7 @@ public class KintoneColumnVisitorTest {
523
639
  .add("STRING|TIME|PST", Types.STRING)
524
640
  .add("STRING|DATETIME", Types.STRING)
525
641
  .add("STRING|LINK", Types.STRING)
642
+ .add("STRING|SUBTABLE", Types.STRING)
526
643
  .add("TIMESTAMP|SINGLE_LINE_TEXT", Types.TIMESTAMP)
527
644
  .add("TIMESTAMP|NUMBER", Types.TIMESTAMP)
528
645
  .add("TIMESTAMP|DATE", Types.TIMESTAMP)
@@ -534,6 +651,8 @@ public class KintoneColumnVisitorTest {
534
651
  .add("TIMESTAMP", Types.TIMESTAMP)
535
652
  .add("JSON|SINGLE_LINE_TEXT", Types.JSON)
536
653
  .add("JSON", Types.JSON)
654
+ .add("JSON|SUBTABLE", Types.JSON)
655
+ .add("JSON|SUBTABLE.SINGLE_LINE_TEXT", Types.JSON)
537
656
  .build();
538
657
  }
539
658
 
@@ -576,6 +695,7 @@ public class KintoneColumnVisitorTest {
576
695
  .put(build("STRING|TIME|PST", it -> it.setType("TIME").setTimezone("US/Pacific")))
577
696
  .put(build("STRING|DATETIME", it -> it.setType("DATETIME")))
578
697
  .put(build("STRING|LINK", it -> it.setType("LINK")))
698
+ .put(build("STRING|SUBTABLE", it -> it.setType("SUBTABLE")))
579
699
  .put(build("TIMESTAMP|SINGLE_LINE_TEXT", it -> it.setType("SINGLE_LINE_TEXT")))
580
700
  .put(build("TIMESTAMP|NUMBER", it -> it.setType("NUMBER")))
581
701
  .put(build("TIMESTAMP|DATE", it -> it.setType("DATE").setTimezone("UTC")))
@@ -587,6 +707,8 @@ public class KintoneColumnVisitorTest {
587
707
  .put(build("TIMESTAMP", it -> it.setType("DATETIME")))
588
708
  .put(build("JSON|SINGLE_LINE_TEXT", it -> it.setType("SINGLE_LINE_TEXT")))
589
709
  .put(build("JSON", it -> it.setType("MULTI_LINE_TEXT")))
710
+ .put(build("JSON|SUBTABLE", it -> it.setType("SUBTABLE")))
711
+ .put(build("JSON|SUBTABLE.SINGLE_LINE_TEXT", it -> it.setType("SINGLE_LINE_TEXT")))
590
712
  .build();
591
713
  }
592
714
 
@@ -634,6 +756,7 @@ public class KintoneColumnVisitorTest {
634
756
  .setNull("STRING|TIME|PST")
635
757
  .setNull("STRING|DATETIME")
636
758
  .setNull("STRING|LINK")
759
+ .setNull("STRING|SUBTABLE")
637
760
  .setNull("TIMESTAMP|SINGLE_LINE_TEXT")
638
761
  .setNull("TIMESTAMP|NUMBER")
639
762
  .setNull("TIMESTAMP|DATE")
@@ -645,6 +768,8 @@ public class KintoneColumnVisitorTest {
645
768
  .setNull("TIMESTAMP")
646
769
  .setNull("JSON|SINGLE_LINE_TEXT")
647
770
  .setNull("JSON")
771
+ .setNull("JSON|SUBTABLE")
772
+ .setNull("JSON|SUBTABLE.SINGLE_LINE_TEXT")
648
773
  .addRecord()
649
774
  .setBoolean("BOOLEAN|SINGLE_LINE_TEXT", false)
650
775
  .setBoolean("BOOLEAN", false)
@@ -682,6 +807,7 @@ public class KintoneColumnVisitorTest {
682
807
  .setString("STRING|TIME|PST", "")
683
808
  .setString("STRING|DATETIME", "")
684
809
  .setString("STRING|LINK", "")
810
+ .setString("STRING|SUBTABLE", "")
685
811
  .setTimestamp("TIMESTAMP|SINGLE_LINE_TEXT", Timestamp.ofInstant(Instant.EPOCH))
686
812
  .setTimestamp("TIMESTAMP|NUMBER", Timestamp.ofInstant(Instant.EPOCH))
687
813
  .setTimestamp("TIMESTAMP|DATE", Timestamp.ofInstant(Instant.EPOCH))
@@ -693,6 +819,8 @@ public class KintoneColumnVisitorTest {
693
819
  .setTimestamp("TIMESTAMP", Timestamp.ofInstant(Instant.EPOCH))
694
820
  .setJson("JSON|SINGLE_LINE_TEXT", ValueFactory.newString(""))
695
821
  .setJson("JSON", ValueFactory.newString(""))
822
+ .setJson("JSON|SUBTABLE", ValueFactory.newString(""))
823
+ .setJson("JSON|SUBTABLE.SINGLE_LINE_TEXT", ValueFactory.newString(""))
696
824
  .addRecord()
697
825
  .setBoolean("BOOLEAN|SINGLE_LINE_TEXT", true)
698
826
  .setBoolean("BOOLEAN", true)
@@ -730,6 +858,7 @@ public class KintoneColumnVisitorTest {
730
858
  .setString("STRING|TIME|PST", "23:59:59")
731
859
  .setString("STRING|DATETIME", "1999-12-31T23:59:59Z")
732
860
  .setString("STRING|LINK", "abc")
861
+ .setString("STRING|SUBTABLE", String.format("[%s,%s,%s]", ROWS[0], ROWS[1], ROWS[2]))
733
862
  .setTimestamp("TIMESTAMP|SINGLE_LINE_TEXT", timestamp("1999-12-31T23:59:59Z"))
734
863
  .setTimestamp("TIMESTAMP|NUMBER", timestamp("1999-12-31T23:59:59Z"))
735
864
  .setTimestamp("TIMESTAMP|DATE", timestamp("1999-12-31T23:59:59Z"))
@@ -741,6 +870,9 @@ public class KintoneColumnVisitorTest {
741
870
  .setTimestamp("TIMESTAMP", timestamp("1999-12-31T23:59:59Z"))
742
871
  .setJson("JSON|SINGLE_LINE_TEXT", ValueFactory.newString("abc"))
743
872
  .setJson("JSON", ValueFactory.newString("abc"))
873
+ .setJson(
874
+ "JSON|SUBTABLE", ValueFactory.newArray(value(ROWS[0]), value(ROWS[1]), value(ROWS[2])))
875
+ .setJson("JSON|SUBTABLE.SINGLE_LINE_TEXT", ValueFactory.newString("abc"))
744
876
  .addRecord()
745
877
  .setBoolean("BOOLEAN|SINGLE_LINE_TEXT", false)
746
878
  .setBoolean("BOOLEAN", false)
@@ -778,6 +910,7 @@ public class KintoneColumnVisitorTest {
778
910
  .setString("STRING|TIME|PST", "00:00:00")
779
911
  .setString("STRING|DATETIME", "2000-01-01T00:00:00Z")
780
912
  .setString("STRING|LINK", "def")
913
+ .setString("STRING|SUBTABLE", String.format("[%s,%s,%s]", ROWS[3], ROWS[4], ROWS[5]))
781
914
  .setTimestamp("TIMESTAMP|SINGLE_LINE_TEXT", timestamp("2000-01-01T00:00:00Z"))
782
915
  .setTimestamp("TIMESTAMP|NUMBER", timestamp("2000-01-01T00:00:00Z"))
783
916
  .setTimestamp("TIMESTAMP|DATE", timestamp("2000-01-01T00:00:00Z"))
@@ -789,32 +922,18 @@ public class KintoneColumnVisitorTest {
789
922
  .setTimestamp("TIMESTAMP", timestamp("2000-01-01T00:00:00Z"))
790
923
  .setJson("JSON|SINGLE_LINE_TEXT", ValueFactory.newString("def"))
791
924
  .setJson("JSON", ValueFactory.newString("def"))
925
+ .setJson(
926
+ "JSON|SUBTABLE", ValueFactory.newArray(value(ROWS[3]), value(ROWS[4]), value(ROWS[5])))
927
+ .setJson("JSON|SUBTABLE.SINGLE_LINE_TEXT", ValueFactory.newString("def"))
792
928
  .addRecord()
793
929
  .build();
794
930
  }
795
931
 
796
- private static BigDecimal number(String value) {
797
- return new BigDecimal(value);
798
- }
799
-
800
- @SafeVarargs
801
- private static <T> List<T> list(T... a) {
802
- return Arrays.asList(a);
803
- }
804
-
805
- private static LocalDate date(CharSequence text) {
806
- return LocalDate.parse(text);
807
- }
808
-
809
- private static LocalTime time(CharSequence text) {
810
- return LocalTime.parse(text);
811
- }
812
-
813
- private static ZonedDateTime dateTime(CharSequence text) {
814
- return ZonedDateTime.parse(text);
815
- }
816
-
817
932
  private static Timestamp timestamp(CharSequence text) {
818
933
  return Timestamp.ofInstant(Instant.parse(text));
819
934
  }
935
+
936
+ private static Value value(String json) {
937
+ return PARSER.parse(json);
938
+ }
820
939
  }