embulk-filter-row 0.2.0 → 0.2.1

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.
@@ -1,43 +1,66 @@
1
1
  package org.embulk.filter.row;
2
2
 
3
- import org.embulk.spi.Column;
4
- import org.embulk.spi.type.Type;
5
- import static org.embulk.spi.type.Types.*;
6
- import org.embulk.spi.type.BooleanType;
7
- import org.embulk.spi.type.LongType;
8
- import org.embulk.spi.type.DoubleType;
9
- import org.embulk.spi.type.StringType;
10
- import org.embulk.spi.type.TimestampType;
11
- import org.embulk.spi.time.Timestamp;
3
+ import com.google.common.base.Optional;
4
+
12
5
  import org.embulk.config.ConfigException;
13
6
  import org.embulk.config.TaskSource;
7
+ import org.embulk.spi.Column;
14
8
 
15
- import org.embulk.filter.row.ConditionConfig;
16
- import org.embulk.filter.row.ConditionFactory;
17
- import org.embulk.filter.row.BooleanCondition;
18
- import org.embulk.filter.row.DoubleCondition;
19
- import org.embulk.filter.row.Condition;
20
- import org.embulk.filter.row.StringCondition;
21
- import org.embulk.filter.row.TimestampCondition;
22
-
23
- import com.google.common.base.Optional;
24
9
  import org.jruby.embed.ScriptingContainer;
25
10
  import org.junit.Test;
26
- import static org.junit.Assert.*;
27
- import java.lang.NullPointerException;
11
+
12
+ import static org.embulk.spi.type.Types.BOOLEAN;
13
+ import static org.embulk.spi.type.Types.DOUBLE;
14
+ import static org.embulk.spi.type.Types.LONG;
15
+ import static org.embulk.spi.type.Types.STRING;
16
+ import static org.embulk.spi.type.Types.TIMESTAMP;
17
+
18
+ //import static org.junit.Assert.assertFalse;
19
+ import static org.junit.Assert.assertTrue;
20
+ import static org.junit.Assert.fail;
28
21
 
29
22
  public class TestConditionFactory
30
23
  {
31
24
  public class DefaultConditionConfig implements ConditionConfig
32
25
  {
33
- public String getColumn() { return "column"; }
34
- public Optional<String> getOperator() { return Optional.of("IS NULL"); }
35
- public Optional<Object> getArgument() { return Optional.absent(); }
36
- public Optional<Boolean> getNot() { return Optional.of(false); }
37
- public Optional<String> getFormat() { return Optional.of("%Y-%m-%d"); }
38
- public Optional<String> getTimezone() { return Optional.of("UTC"); }
39
- public TaskSource dump() { return null; }
40
- public void validate() {}
26
+ public String getColumn()
27
+ {
28
+ return "column";
29
+ }
30
+
31
+ public Optional<String> getOperator()
32
+ {
33
+ return Optional.of("IS NULL");
34
+ }
35
+
36
+ public Optional<Object> getArgument()
37
+ {
38
+ return Optional.absent();
39
+ }
40
+
41
+ public Optional<Boolean> getNot()
42
+ {
43
+ return Optional.of(false);
44
+ }
45
+
46
+ public Optional<String> getFormat()
47
+ {
48
+ return Optional.of("%Y-%m-%d");
49
+ }
50
+
51
+ public Optional<String> getTimezone()
52
+ {
53
+ return Optional.of("UTC");
54
+ }
55
+
56
+ public TaskSource dump()
57
+ {
58
+ return null;
59
+ }
60
+
61
+ public void validate()
62
+ {
63
+ }
41
64
  }
42
65
 
43
66
  private final ScriptingContainer jruby;
@@ -48,185 +71,292 @@ public class TestConditionFactory
48
71
  }
49
72
 
50
73
  @Test
51
- public void testCreateBooleanCondition() {
74
+ public void testCreateBooleanCondition()
75
+ {
52
76
  Column column = new Column(0, "column", BOOLEAN);
53
77
  ConditionConfig config;
54
78
  BooleanCondition condition;
55
79
 
56
80
  config = new DefaultConditionConfig() {
57
- public Optional<String> getOperator() { return Optional.of("IS NULL"); }
81
+ public Optional<String> getOperator()
82
+ {
83
+ return Optional.of("IS NULL");
84
+ }
58
85
  };
59
- condition = (BooleanCondition)new ConditionFactory(jruby, column, config).createCondition();
86
+ condition = (BooleanCondition) new ConditionFactory(jruby, column, config).createCondition();
60
87
  assertTrue(condition.compare(null));
61
88
 
62
89
  config = new DefaultConditionConfig() {
63
- public Optional<String> getOperator() { return Optional.of("=="); }
64
- public Optional<Object> getArgument() { return Optional.absent(); }
90
+ public Optional<String> getOperator()
91
+ {
92
+ return Optional.of("==");
93
+ }
94
+ public Optional<Object> getArgument()
95
+ {
96
+ return Optional.absent();
97
+ }
65
98
  };
66
99
  try {
67
- condition = (BooleanCondition)new ConditionFactory(jruby, column, config).createCondition();
100
+ condition = (BooleanCondition) new ConditionFactory(jruby, column, config).createCondition();
68
101
  fail("Argument is required");
69
- } catch (ConfigException e) {
102
+ }
103
+ catch (ConfigException e) {
70
104
  }
71
105
 
72
106
  config = new DefaultConditionConfig() {
73
- public Optional<String> getOperator() { return Optional.of("=="); }
74
- public Optional<Object> getArgument() { return Optional.of((Object)new Boolean(true)); }
107
+ public Optional<String> getOperator()
108
+ {
109
+ return Optional.of("==");
110
+ }
111
+ public Optional<Object> getArgument()
112
+ {
113
+ return Optional.of((Object) new Boolean(true));
114
+ }
75
115
  };
76
- condition = (BooleanCondition)new ConditionFactory(jruby, column, config).createCondition();
116
+ condition = (BooleanCondition) new ConditionFactory(jruby, column, config).createCondition();
77
117
  assertTrue(condition.compare(new Boolean(true)));
78
118
 
79
119
  config = new DefaultConditionConfig() {
80
- public Optional<String> getOperator() { return Optional.of("=="); }
81
- public Optional<Object> getArgument() { return Optional.of((Object)new Long(10)); }
120
+ public Optional<String> getOperator()
121
+ {
122
+ return Optional.of("==");
123
+ }
124
+ public Optional<Object> getArgument()
125
+ {
126
+ return Optional.of((Object) new Long(10));
127
+ }
82
128
  };
83
129
  try {
84
- condition = (BooleanCondition)new ConditionFactory(jruby, column, config).createCondition();
130
+ condition = (BooleanCondition) new ConditionFactory(jruby, column, config).createCondition();
85
131
  fail("Argument type mismatch");
86
- } catch (ConfigException e) {
132
+ }
133
+ catch (ConfigException e) {
87
134
  }
88
135
  }
89
136
 
90
137
  @Test
91
- public void testCreateDoubleCondition() {
138
+ public void testCreateDoubleCondition()
139
+ {
92
140
  Column column = new Column(0, "column", DOUBLE);
93
141
  ConditionConfig config;
94
142
  DoubleCondition condition;
95
143
 
96
144
  config = new DefaultConditionConfig() {
97
- public Optional<String> getOperator() { return Optional.of("IS NULL"); }
145
+ public Optional<String> getOperator()
146
+ {
147
+ return Optional.of("IS NULL");
148
+ }
98
149
  };
99
- condition = (DoubleCondition)new ConditionFactory(jruby, column, config).createCondition();
150
+ condition = (DoubleCondition) new ConditionFactory(jruby, column, config).createCondition();
100
151
  assertTrue(condition.compare(null));
101
152
 
102
153
  config = new DefaultConditionConfig() {
103
- public Optional<String> getOperator() { return Optional.of("=="); }
104
- public Optional<Object> getArgument() { return Optional.absent(); }
154
+ public Optional<String> getOperator()
155
+ {
156
+ return Optional.of("==");
157
+ }
158
+ public Optional<Object> getArgument()
159
+ {
160
+ return Optional.absent();
161
+ }
105
162
  };
106
163
  try {
107
- condition = (DoubleCondition)new ConditionFactory(jruby, column, config).createCondition();
164
+ condition = (DoubleCondition) new ConditionFactory(jruby, column, config).createCondition();
108
165
  fail("Argument is required");
109
- } catch (ConfigException e) {
166
+ }
167
+ catch (ConfigException e) {
110
168
  }
111
169
 
112
170
  config = new DefaultConditionConfig() {
113
- public Optional<String> getOperator() { return Optional.of("=="); }
114
- public Optional<Object> getArgument() { return Optional.of((Object)new Double(10)); }
171
+ public Optional<String> getOperator()
172
+ {
173
+ return Optional.of("==");
174
+ }
175
+ public Optional<Object> getArgument()
176
+ {
177
+ return Optional.of((Object) new Double(10));
178
+ }
115
179
  };
116
- condition = (DoubleCondition)new ConditionFactory(jruby, column, config).createCondition();
180
+ condition = (DoubleCondition) new ConditionFactory(jruby, column, config).createCondition();
117
181
  assertTrue(condition.compare(new Double(10)));
118
182
 
119
183
  config = new DefaultConditionConfig() {
120
- public Optional<String> getOperator() { return Optional.of("=="); }
121
- public Optional<Object> getArgument() { return Optional.of((Object)new Boolean(true)); }
184
+ public Optional<String> getOperator()
185
+ {
186
+ return Optional.of("==");
187
+ }
188
+ public Optional<Object> getArgument()
189
+ {
190
+ return Optional.of((Object) new Boolean(true));
191
+ }
122
192
  };
123
193
  try {
124
- condition = (DoubleCondition)new ConditionFactory(jruby, column, config).createCondition();
194
+ condition = (DoubleCondition) new ConditionFactory(jruby, column, config).createCondition();
125
195
  fail("Argument type mismatch");
126
- } catch (ConfigException e) {
196
+ }
197
+ catch (ConfigException e) {
127
198
  }
128
199
  }
129
200
 
130
201
  @Test
131
- public void testCreateLongCondition() {
202
+ public void testCreateLongCondition()
203
+ {
132
204
  Column column = new Column(0, "column", LONG);
133
205
  ConditionConfig config;
134
206
  LongCondition condition;
135
207
 
136
208
  config = new DefaultConditionConfig() {
137
- public Optional<String> getOperator() { return Optional.of("IS NULL"); }
209
+ public Optional<String> getOperator()
210
+ {
211
+ return Optional.of("IS NULL");
212
+ }
138
213
  };
139
- condition = (LongCondition)new ConditionFactory(jruby, column, config).createCondition();
214
+ condition = (LongCondition) new ConditionFactory(jruby, column, config).createCondition();
140
215
  assertTrue(condition.compare(null));
141
216
 
142
217
  config = new DefaultConditionConfig() {
143
- public Optional<String> getOperator() { return Optional.of("=="); }
144
- public Optional<Object> getArgument() { return Optional.absent(); }
218
+ public Optional<String> getOperator()
219
+ {
220
+ return Optional.of("==");
221
+ }
222
+ public Optional<Object> getArgument()
223
+ {
224
+ return Optional.absent();
225
+ }
145
226
  };
146
227
  try {
147
- condition = (LongCondition)new ConditionFactory(jruby, column, config).createCondition();
228
+ condition = (LongCondition) new ConditionFactory(jruby, column, config).createCondition();
148
229
  fail("Argument is required");
149
- } catch (ConfigException e) {
230
+ }
231
+ catch (ConfigException e) {
150
232
  }
151
233
 
152
234
  config = new DefaultConditionConfig() {
153
- public Optional<String> getOperator() { return Optional.of("=="); }
154
- public Optional<Object> getArgument() { return Optional.of((Object)new Long(10)); }
235
+ public Optional<String> getOperator()
236
+ {
237
+ return Optional.of("==");
238
+ }
239
+ public Optional<Object> getArgument()
240
+ {
241
+ return Optional.of((Object) new Long(10));
242
+ }
155
243
  };
156
- condition = (LongCondition)new ConditionFactory(jruby, column, config).createCondition();
244
+ condition = (LongCondition) new ConditionFactory(jruby, column, config).createCondition();
157
245
  assertTrue(condition.compare(new Long(10)));
158
246
 
159
247
  config = new DefaultConditionConfig() {
160
- public Optional<String> getOperator() { return Optional.of("=="); }
161
- public Optional<Object> getArgument() { return Optional.of((Object)new Boolean(true)); }
248
+ public Optional<String> getOperator()
249
+ {
250
+ return Optional.of("==");
251
+ }
252
+ public Optional<Object> getArgument()
253
+ {
254
+ return Optional.of((Object) new Boolean(true));
255
+ }
162
256
  };
163
257
  try {
164
- condition = (LongCondition)new ConditionFactory(jruby, column, config).createCondition();
258
+ condition = (LongCondition) new ConditionFactory(jruby, column, config).createCondition();
165
259
  fail("Argument type mismatch");
166
- } catch (ConfigException e) {
260
+ }
261
+ catch (ConfigException e) {
167
262
  }
168
263
  }
169
264
 
170
265
  @Test
171
- public void testCreateStringCondition() {
266
+ public void testCreateStringCondition()
267
+ {
172
268
  Column column = new Column(0, "column", STRING);
173
269
  ConditionConfig config;
174
270
  StringCondition condition;
175
271
 
176
272
  config = new DefaultConditionConfig() {
177
- public Optional<String> getOperator() { return Optional.of("IS NULL"); }
273
+ public Optional<String> getOperator()
274
+ {
275
+ return Optional.of("IS NULL");
276
+ }
178
277
  };
179
- condition = (StringCondition)new ConditionFactory(jruby, column, config).createCondition();
278
+ condition = (StringCondition) new ConditionFactory(jruby, column, config).createCondition();
180
279
  assertTrue(condition.compare(null));
181
280
 
182
281
  config = new DefaultConditionConfig() {
183
- public Optional<String> getOperator() { return Optional.of("=="); }
184
- public Optional<Object> getArgument() { return Optional.absent(); }
282
+ public Optional<String> getOperator()
283
+ {
284
+ return Optional.of("==");
285
+ }
286
+ public Optional<Object> getArgument()
287
+ {
288
+ return Optional.absent();
289
+ }
185
290
  };
186
291
  try {
187
- condition = (StringCondition)new ConditionFactory(jruby, column, config).createCondition();
292
+ condition = (StringCondition) new ConditionFactory(jruby, column, config).createCondition();
188
293
  fail("Argument is required");
189
- } catch (ConfigException e) {
294
+ }
295
+ catch (ConfigException e) {
190
296
  }
191
297
 
192
298
  config = new DefaultConditionConfig() {
193
- public Optional<String> getOperator() { return Optional.of("=="); }
194
- public Optional<Object> getArgument() { return Optional.of((Object)"foo"); }
299
+ public Optional<String> getOperator()
300
+ {
301
+ return Optional.of("==");
302
+ }
303
+ public Optional<Object> getArgument()
304
+ {
305
+ return Optional.of((Object) "foo");
306
+ }
195
307
  };
196
- condition = (StringCondition)new ConditionFactory(jruby, column, config).createCondition();
308
+ condition = (StringCondition) new ConditionFactory(jruby, column, config).createCondition();
197
309
  assertTrue(condition.compare("foo"));
198
310
 
199
311
  config = new DefaultConditionConfig() {
200
- public Optional<String> getOperator() { return Optional.of("=="); }
201
- public Optional<Object> getArgument() { return Optional.of((Object)new Boolean(true)); }
312
+ public Optional<String> getOperator()
313
+ {
314
+ return Optional.of("==");
315
+ }
316
+ public Optional<Object> getArgument()
317
+ {
318
+ return Optional.of((Object) new Boolean(true));
319
+ }
202
320
  };
203
321
  try {
204
- condition = (StringCondition)new ConditionFactory(jruby, column, config).createCondition();
322
+ condition = (StringCondition) new ConditionFactory(jruby, column, config).createCondition();
205
323
  fail("Argument type mismatch");
206
- } catch (ConfigException e) {
324
+ }
325
+ catch (ConfigException e) {
207
326
  }
208
327
  }
209
328
 
210
329
  @Test
211
- public void testCreateTimestampCondition() {
330
+ public void testCreateTimestampCondition()
331
+ {
212
332
  Column column = new Column(0, "column", TIMESTAMP);
213
333
  ConditionConfig config;
214
334
  TimestampCondition condition;
215
335
 
216
336
  config = new DefaultConditionConfig() {
217
- public Optional<String> getOperator() { return Optional.of("IS NULL"); }
337
+ public Optional<String> getOperator()
338
+ {
339
+ return Optional.of("IS NULL");
340
+ }
218
341
  };
219
- condition = (TimestampCondition)new ConditionFactory(jruby, column, config).createCondition();
342
+ condition = (TimestampCondition) new ConditionFactory(jruby, column, config).createCondition();
220
343
  assertTrue(condition.compare(null));
221
344
 
222
345
  config = new DefaultConditionConfig() {
223
- public Optional<String> getOperator() { return Optional.of("=="); }
224
- public Optional<Object> getArgument() { return Optional.absent(); }
346
+ public Optional<String> getOperator()
347
+ {
348
+ return Optional.of("==");
349
+ }
350
+ public Optional<Object> getArgument()
351
+ {
352
+ return Optional.absent();
353
+ }
225
354
  };
226
355
  try {
227
- condition = (TimestampCondition)new ConditionFactory(jruby, column, config).createCondition();
356
+ condition = (TimestampCondition) new ConditionFactory(jruby, column, config).createCondition();
228
357
  fail("Argument is required");
229
- } catch (ConfigException e) {
358
+ }
359
+ catch (ConfigException e) {
230
360
  }
231
361
 
232
362
  //ToDo: How to create jruby object correctly?
@@ -238,13 +368,20 @@ public class TestConditionFactory
238
368
  //condition = (TimestampCondition)new ConditionFactory(jruby, column, config).createCondition();
239
369
 
240
370
  config = new DefaultConditionConfig() {
241
- public Optional<String> getOperator() { return Optional.of("=="); }
242
- public Optional<Object> getArgument() { return Optional.of((Object)new Boolean(true)); }
371
+ public Optional<String> getOperator()
372
+ {
373
+ return Optional.of("==");
374
+ }
375
+ public Optional<Object> getArgument()
376
+ {
377
+ return Optional.of((Object) new Boolean(true));
378
+ }
243
379
  };
244
380
  try {
245
- condition = (TimestampCondition)new ConditionFactory(jruby, column, config).createCondition();
381
+ condition = (TimestampCondition) new ConditionFactory(jruby, column, config).createCondition();
246
382
  fail("Argument type mismatch");
247
- } catch (ConfigException e) {
383
+ }
384
+ catch (ConfigException e) {
248
385
  }
249
386
  }
250
387
  }
@@ -1,81 +1,105 @@
1
1
  package org.embulk.filter.row;
2
2
 
3
- import org.embulk.filter.row.DoubleCondition;
4
3
  import org.junit.Test;
5
- import static org.junit.Assert.*;
4
+
5
+ import static org.junit.Assert.assertFalse;
6
+ import static org.junit.Assert.assertTrue;
6
7
 
7
8
  public class TestDoubleCondition
8
9
  {
9
10
  @Test
10
- public void testIsNull() {
11
+ public void testIsNull()
12
+ {
11
13
  DoubleCondition condition = new DoubleCondition("IS NULL", null, false);
12
14
  assertTrue(condition.compare(null));
13
15
  assertFalse(condition.compare(new Double(10)));
14
16
  }
15
17
 
16
18
  @Test
17
- public void testIsNotNull() {
19
+ public void testIsNotNull()
20
+ {
18
21
  DoubleCondition condition = new DoubleCondition("IS NOT NULL", null, false);
19
22
  assertFalse(condition.compare(null));
20
23
  assertTrue(condition.compare(new Double(10)));
21
24
  }
22
25
 
23
26
  @Test
24
- public void testEquals() {
27
+ public void testEquals()
28
+ {
25
29
  DoubleCondition condition = new DoubleCondition("==", new Double(10), false);
26
30
  assertFalse(condition.compare(null));
27
- assertTrue( condition.compare(new Double(10)));
31
+ assertTrue(condition.compare(new Double(10)));
28
32
  assertFalse(condition.compare(new Double(11)));
33
+ assertTrue(condition.compare(new Double(10.0)));
34
+ assertFalse(condition.compare(new Double(11.0)));
29
35
 
30
36
  // Prohibited by Factory
31
37
  // DoubleCondition condition = new DoubleCondition("==", null, false);
32
38
  }
33
39
 
34
40
  @Test
35
- public void testNotEquals() {
41
+ public void testNotEquals()
42
+ {
36
43
  DoubleCondition condition = new DoubleCondition("!=", new Double(10), false);
37
- assertTrue( condition.compare(null));
44
+ assertTrue(condition.compare(null));
38
45
  assertFalse(condition.compare(new Double(10)));
39
- assertTrue( condition.compare(new Double(11)));
46
+ assertTrue(condition.compare(new Double(11)));
47
+ assertFalse(condition.compare(new Double(10.0)));
48
+ assertTrue(condition.compare(new Double(11.0)));
40
49
  }
41
50
 
42
51
  @Test
43
- public void testGreaterThan() {
52
+ public void testGreaterThan()
53
+ {
44
54
  DoubleCondition condition = new DoubleCondition(">", new Double(10), false);
45
55
  assertFalse(condition.compare(null));
46
56
  assertFalse(condition.compare(new Double(10)));
47
- assertTrue( condition.compare(new Double(11)));
57
+ assertTrue(condition.compare(new Double(11)));
58
+ assertFalse(condition.compare(new Double(10.0)));
59
+ assertTrue(condition.compare(new Double(11.0)));
48
60
  }
49
61
 
50
62
  @Test
51
- public void testGreaterEqual() {
63
+ public void testGreaterEqual()
64
+ {
52
65
  DoubleCondition condition = new DoubleCondition(">=", new Double(11), false);
53
66
  assertFalse(condition.compare(null));
54
67
  assertFalse(condition.compare(new Double(10)));
55
- assertTrue( condition.compare(new Double(11)));
68
+ assertTrue(condition.compare(new Double(11)));
69
+ assertFalse(condition.compare(new Double(10.0)));
70
+ assertTrue(condition.compare(new Double(11.0)));
56
71
  }
57
72
 
58
73
  @Test
59
- public void testLessThan() {
74
+ public void testLessThan()
75
+ {
60
76
  DoubleCondition condition = new DoubleCondition("<", new Double(11), false);
61
77
  assertFalse(condition.compare(null));
62
78
  assertFalse(condition.compare(new Double(11)));
63
- assertTrue( condition.compare(new Double(10)));
79
+ assertTrue(condition.compare(new Double(10)));
80
+ assertFalse(condition.compare(new Double(11.0)));
81
+ assertTrue(condition.compare(new Double(10.0)));
64
82
  }
65
83
 
66
84
  @Test
67
- public void testLessEqual() {
85
+ public void testLessEqual()
86
+ {
68
87
  DoubleCondition condition = new DoubleCondition("<=", new Double(11), false);
69
88
  assertFalse(condition.compare(null));
70
89
  assertFalse(condition.compare(new Double(12)));
71
- assertTrue( condition.compare(new Double(11)));
90
+ assertTrue(condition.compare(new Double(11)));
91
+ assertFalse(condition.compare(new Double(12.0)));
92
+ assertTrue(condition.compare(new Double(11.0)));
72
93
  }
73
94
 
74
95
  @Test
75
- public void testNot() {
96
+ public void testNot()
97
+ {
76
98
  DoubleCondition condition = new DoubleCondition("<=", new Double(11), true);
77
- assertTrue( condition.compare(null));
78
- assertTrue( condition.compare(new Double(12)));
99
+ assertTrue(condition.compare(null));
100
+ assertTrue(condition.compare(new Double(12)));
79
101
  assertFalse(condition.compare(new Double(11)));
102
+ assertTrue(condition.compare(new Double(12.0)));
103
+ assertFalse(condition.compare(new Double(11.0)));
80
104
  }
81
105
  }