embulk-filter-row 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +20 -0
- data/README.md +79 -0
- data/build.gradle +73 -0
- data/classpath/embulk-filter-row-0.1.0.jar +0 -0
- data/example.yml +37 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +164 -0
- data/gradlew.bat +90 -0
- data/lib/embulk/filter/row.rb +3 -0
- data/src/main/java/org/embulk/filter/RowFilterPlugin.java +231 -0
- data/src/main/java/org/embulk/filter/row/BooleanCondition.java +43 -0
- data/src/main/java/org/embulk/filter/row/Condition.java +5 -0
- data/src/main/java/org/embulk/filter/row/ConditionConfig.java +32 -0
- data/src/main/java/org/embulk/filter/row/ConditionFactory.java +164 -0
- data/src/main/java/org/embulk/filter/row/DoubleCondition.java +63 -0
- data/src/main/java/org/embulk/filter/row/LongCondition.java +63 -0
- data/src/main/java/org/embulk/filter/row/StringCondition.java +58 -0
- data/src/main/java/org/embulk/filter/row/TimestampCondition.java +64 -0
- data/src/test/java/org/embulk/filter/TestRowFilterPlugin.java +5 -0
- data/src/test/java/org/embulk/filter/row/TestBooleanCondition.java +64 -0
- data/src/test/java/org/embulk/filter/row/TestConditionFactory.java +250 -0
- data/src/test/java/org/embulk/filter/row/TestDoubleCondition.java +81 -0
- data/src/test/java/org/embulk/filter/row/TestLongCondition.java +81 -0
- data/src/test/java/org/embulk/filter/row/TestStringCondition.java +73 -0
- data/src/test/java/org/embulk/filter/row/TestTimestampCondition.java +83 -0
- metadata +100 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
package org.embulk.filter.row;
|
2
|
+
import org.embulk.spi.time.Timestamp;
|
3
|
+
|
4
|
+
public class TimestampCondition implements Condition
|
5
|
+
{
|
6
|
+
private TimestampComparator comparator;
|
7
|
+
|
8
|
+
@FunctionalInterface
|
9
|
+
interface TimestampComparator {
|
10
|
+
boolean compare(Timestamp subject);
|
11
|
+
}
|
12
|
+
|
13
|
+
public TimestampCondition(String operator, Timestamp argument, boolean not) {
|
14
|
+
TimestampComparator comparator;
|
15
|
+
switch (operator.toUpperCase()) {
|
16
|
+
case ">":
|
17
|
+
comparator = (Timestamp subject) -> {
|
18
|
+
return subject == null ? false : subject.compareTo(argument) > 0;
|
19
|
+
};
|
20
|
+
break;
|
21
|
+
case ">=":
|
22
|
+
comparator = (Timestamp subject) -> {
|
23
|
+
return subject == null ? false : subject.compareTo(argument) >= 0;
|
24
|
+
};
|
25
|
+
break;
|
26
|
+
case "<":
|
27
|
+
comparator = (Timestamp subject) -> {
|
28
|
+
return subject == null ? false : subject.compareTo(argument) < 0;
|
29
|
+
};
|
30
|
+
break;
|
31
|
+
case "<=":
|
32
|
+
comparator = (Timestamp subject) -> {
|
33
|
+
return subject == null ? false : subject.compareTo(argument) <= 0;
|
34
|
+
};
|
35
|
+
break;
|
36
|
+
case "IS NULL":
|
37
|
+
comparator = (Timestamp subject) -> {
|
38
|
+
return subject == null;
|
39
|
+
};
|
40
|
+
break;
|
41
|
+
case "IS NOT NULL":
|
42
|
+
comparator = (Timestamp subject) -> {
|
43
|
+
return subject != null;
|
44
|
+
};
|
45
|
+
break;
|
46
|
+
case "!=":
|
47
|
+
comparator = (Timestamp subject) -> {
|
48
|
+
return subject == null ? true : !subject.equals(argument);
|
49
|
+
};
|
50
|
+
break;
|
51
|
+
default: // case "==":
|
52
|
+
comparator = (Timestamp subject) -> {
|
53
|
+
return subject == null ? false : subject.equals(argument);
|
54
|
+
};
|
55
|
+
break;
|
56
|
+
}
|
57
|
+
this.comparator = comparator;
|
58
|
+
if (not) this.comparator = (Timestamp subject) -> { return !comparator.compare(subject); };
|
59
|
+
}
|
60
|
+
|
61
|
+
public boolean compare(Timestamp subject) {
|
62
|
+
return this.comparator.compare(subject);
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
package org.embulk.filter.row;
|
2
|
+
|
3
|
+
import org.embulk.filter.row.BooleanCondition;
|
4
|
+
import org.junit.Test;
|
5
|
+
import static org.junit.Assert.*;
|
6
|
+
|
7
|
+
public class TestBooleanCondition
|
8
|
+
{
|
9
|
+
@Test
|
10
|
+
public void testIsNull() {
|
11
|
+
BooleanCondition condition = new BooleanCondition("IS NULL", null, false);
|
12
|
+
assertTrue(condition.compare(null));
|
13
|
+
assertFalse(condition.compare(new Boolean(true)));
|
14
|
+
assertFalse(condition.compare(new Boolean(false)));
|
15
|
+
}
|
16
|
+
|
17
|
+
@Test
|
18
|
+
public void testIsNotNull() {
|
19
|
+
BooleanCondition condition = new BooleanCondition("IS NOT NULL", null, false);
|
20
|
+
assertFalse(condition.compare(null));
|
21
|
+
assertTrue(condition.compare(new Boolean(true)));
|
22
|
+
assertTrue(condition.compare(new Boolean(false)));
|
23
|
+
}
|
24
|
+
|
25
|
+
@Test
|
26
|
+
public void testNot() {
|
27
|
+
BooleanCondition condition = new BooleanCondition("IS NOT NULL", null, true);
|
28
|
+
assertTrue(condition.compare(null));
|
29
|
+
assertFalse(condition.compare(new Boolean(true)));
|
30
|
+
assertFalse(condition.compare(new Boolean(false)));
|
31
|
+
}
|
32
|
+
|
33
|
+
@Test
|
34
|
+
public void testEquals() {
|
35
|
+
BooleanCondition condition = new BooleanCondition("==", new Boolean(true), false);
|
36
|
+
assertTrue(condition.compare(new Boolean(true)));
|
37
|
+
assertFalse(condition.compare(new Boolean(false)));
|
38
|
+
assertFalse(condition.compare(null));
|
39
|
+
|
40
|
+
condition = new BooleanCondition("==", new Boolean(false), false);
|
41
|
+
assertTrue(condition.compare(new Boolean(false)));
|
42
|
+
assertFalse(condition.compare(new Boolean(true)));
|
43
|
+
assertFalse(condition.compare(null));
|
44
|
+
|
45
|
+
// Prohibited by Factory
|
46
|
+
// BooleanCondition condition = new BooleanCondition("==", null, false);
|
47
|
+
}
|
48
|
+
|
49
|
+
@Test
|
50
|
+
public void testNotEquals() {
|
51
|
+
BooleanCondition condition = new BooleanCondition("!=", new Boolean(true), false);
|
52
|
+
assertFalse(condition.compare(new Boolean(true)));
|
53
|
+
assertTrue(condition.compare(new Boolean(false)));
|
54
|
+
assertTrue(condition.compare(null));
|
55
|
+
|
56
|
+
condition = new BooleanCondition("!=", new Boolean(false), false);
|
57
|
+
assertFalse(condition.compare(new Boolean(false)));
|
58
|
+
assertTrue(condition.compare(new Boolean(true)));
|
59
|
+
assertTrue(condition.compare(null));
|
60
|
+
|
61
|
+
// Prohibited by Factory
|
62
|
+
// BooleanCondition condition = new BooleanCondition("!=", null, false);
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,250 @@
|
|
1
|
+
package org.embulk.filter.row;
|
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;
|
12
|
+
import org.embulk.config.ConfigException;
|
13
|
+
import org.embulk.config.TaskSource;
|
14
|
+
|
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
|
+
import org.jruby.embed.ScriptingContainer;
|
25
|
+
import org.junit.Test;
|
26
|
+
import static org.junit.Assert.*;
|
27
|
+
import java.lang.NullPointerException;
|
28
|
+
|
29
|
+
public class TestConditionFactory
|
30
|
+
{
|
31
|
+
public class DefaultConditionConfig implements ConditionConfig
|
32
|
+
{
|
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() {}
|
41
|
+
}
|
42
|
+
|
43
|
+
private final ScriptingContainer jruby;
|
44
|
+
|
45
|
+
public TestConditionFactory()
|
46
|
+
{
|
47
|
+
jruby = new ScriptingContainer();
|
48
|
+
}
|
49
|
+
|
50
|
+
@Test
|
51
|
+
public void testCreateBooleanCondition() {
|
52
|
+
Column column = new Column(0, "column", BOOLEAN);
|
53
|
+
ConditionConfig config;
|
54
|
+
BooleanCondition condition;
|
55
|
+
|
56
|
+
config = new DefaultConditionConfig() {
|
57
|
+
public Optional<String> getOperator() { return Optional.of("IS NULL"); }
|
58
|
+
};
|
59
|
+
condition = (BooleanCondition)new ConditionFactory(jruby, column, config).createCondition();
|
60
|
+
assertTrue(condition.compare(null));
|
61
|
+
|
62
|
+
config = new DefaultConditionConfig() {
|
63
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
64
|
+
public Optional<Object> getArgument() { return Optional.absent(); }
|
65
|
+
};
|
66
|
+
try {
|
67
|
+
condition = (BooleanCondition)new ConditionFactory(jruby, column, config).createCondition();
|
68
|
+
fail("Argument is required");
|
69
|
+
} catch (ConfigException e) {
|
70
|
+
}
|
71
|
+
|
72
|
+
config = new DefaultConditionConfig() {
|
73
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
74
|
+
public Optional<Object> getArgument() { return Optional.of(new Boolean(true)); }
|
75
|
+
};
|
76
|
+
condition = (BooleanCondition)new ConditionFactory(jruby, column, config).createCondition();
|
77
|
+
assertTrue(condition.compare(new Boolean(true)));
|
78
|
+
|
79
|
+
config = new DefaultConditionConfig() {
|
80
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
81
|
+
public Optional<Object> getArgument() { return Optional.of(new Long(10)); }
|
82
|
+
};
|
83
|
+
try {
|
84
|
+
condition = (BooleanCondition)new ConditionFactory(jruby, column, config).createCondition();
|
85
|
+
fail("Argument type mismatch");
|
86
|
+
} catch (ConfigException e) {
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
@Test
|
91
|
+
public void testCreateDoubleCondition() {
|
92
|
+
Column column = new Column(0, "column", DOUBLE);
|
93
|
+
ConditionConfig config;
|
94
|
+
DoubleCondition condition;
|
95
|
+
|
96
|
+
config = new DefaultConditionConfig() {
|
97
|
+
public Optional<String> getOperator() { return Optional.of("IS NULL"); }
|
98
|
+
};
|
99
|
+
condition = (DoubleCondition)new ConditionFactory(jruby, column, config).createCondition();
|
100
|
+
assertTrue(condition.compare(null));
|
101
|
+
|
102
|
+
config = new DefaultConditionConfig() {
|
103
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
104
|
+
public Optional<Object> getArgument() { return Optional.absent(); }
|
105
|
+
};
|
106
|
+
try {
|
107
|
+
condition = (DoubleCondition)new ConditionFactory(jruby, column, config).createCondition();
|
108
|
+
fail("Argument is required");
|
109
|
+
} catch (ConfigException e) {
|
110
|
+
}
|
111
|
+
|
112
|
+
config = new DefaultConditionConfig() {
|
113
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
114
|
+
public Optional<Object> getArgument() { return Optional.of(new Double(10)); }
|
115
|
+
};
|
116
|
+
condition = (DoubleCondition)new ConditionFactory(jruby, column, config).createCondition();
|
117
|
+
assertTrue(condition.compare(new Double(10)));
|
118
|
+
|
119
|
+
config = new DefaultConditionConfig() {
|
120
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
121
|
+
public Optional<Object> getArgument() { return Optional.of(new Boolean(true)); }
|
122
|
+
};
|
123
|
+
try {
|
124
|
+
condition = (DoubleCondition)new ConditionFactory(jruby, column, config).createCondition();
|
125
|
+
fail("Argument type mismatch");
|
126
|
+
} catch (ConfigException e) {
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
@Test
|
131
|
+
public void testCreateLongCondition() {
|
132
|
+
Column column = new Column(0, "column", LONG);
|
133
|
+
ConditionConfig config;
|
134
|
+
LongCondition condition;
|
135
|
+
|
136
|
+
config = new DefaultConditionConfig() {
|
137
|
+
public Optional<String> getOperator() { return Optional.of("IS NULL"); }
|
138
|
+
};
|
139
|
+
condition = (LongCondition)new ConditionFactory(jruby, column, config).createCondition();
|
140
|
+
assertTrue(condition.compare(null));
|
141
|
+
|
142
|
+
config = new DefaultConditionConfig() {
|
143
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
144
|
+
public Optional<Object> getArgument() { return Optional.absent(); }
|
145
|
+
};
|
146
|
+
try {
|
147
|
+
condition = (LongCondition)new ConditionFactory(jruby, column, config).createCondition();
|
148
|
+
fail("Argument is required");
|
149
|
+
} catch (ConfigException e) {
|
150
|
+
}
|
151
|
+
|
152
|
+
config = new DefaultConditionConfig() {
|
153
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
154
|
+
public Optional<Object> getArgument() { return Optional.of(new Long(10)); }
|
155
|
+
};
|
156
|
+
condition = (LongCondition)new ConditionFactory(jruby, column, config).createCondition();
|
157
|
+
assertTrue(condition.compare(new Long(10)));
|
158
|
+
|
159
|
+
config = new DefaultConditionConfig() {
|
160
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
161
|
+
public Optional<Object> getArgument() { return Optional.of(new Boolean(true)); }
|
162
|
+
};
|
163
|
+
try {
|
164
|
+
condition = (LongCondition)new ConditionFactory(jruby, column, config).createCondition();
|
165
|
+
fail("Argument type mismatch");
|
166
|
+
} catch (ConfigException e) {
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
@Test
|
171
|
+
public void testCreateStringCondition() {
|
172
|
+
Column column = new Column(0, "column", STRING);
|
173
|
+
ConditionConfig config;
|
174
|
+
StringCondition condition;
|
175
|
+
|
176
|
+
config = new DefaultConditionConfig() {
|
177
|
+
public Optional<String> getOperator() { return Optional.of("IS NULL"); }
|
178
|
+
};
|
179
|
+
condition = (StringCondition)new ConditionFactory(jruby, column, config).createCondition();
|
180
|
+
assertTrue(condition.compare(null));
|
181
|
+
|
182
|
+
config = new DefaultConditionConfig() {
|
183
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
184
|
+
public Optional<Object> getArgument() { return Optional.absent(); }
|
185
|
+
};
|
186
|
+
try {
|
187
|
+
condition = (StringCondition)new ConditionFactory(jruby, column, config).createCondition();
|
188
|
+
fail("Argument is required");
|
189
|
+
} catch (ConfigException e) {
|
190
|
+
}
|
191
|
+
|
192
|
+
config = new DefaultConditionConfig() {
|
193
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
194
|
+
public Optional<Object> getArgument() { return Optional.of("foo"); }
|
195
|
+
};
|
196
|
+
condition = (StringCondition)new ConditionFactory(jruby, column, config).createCondition();
|
197
|
+
assertTrue(condition.compare("foo"));
|
198
|
+
|
199
|
+
config = new DefaultConditionConfig() {
|
200
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
201
|
+
public Optional<Object> getArgument() { return Optional.of(new Boolean(true)); }
|
202
|
+
};
|
203
|
+
try {
|
204
|
+
condition = (StringCondition)new ConditionFactory(jruby, column, config).createCondition();
|
205
|
+
fail("Argument type mismatch");
|
206
|
+
} catch (ConfigException e) {
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
@Test
|
211
|
+
public void testCreateTimestampCondition() {
|
212
|
+
Column column = new Column(0, "column", TIMESTAMP);
|
213
|
+
ConditionConfig config;
|
214
|
+
TimestampCondition condition;
|
215
|
+
|
216
|
+
config = new DefaultConditionConfig() {
|
217
|
+
public Optional<String> getOperator() { return Optional.of("IS NULL"); }
|
218
|
+
};
|
219
|
+
condition = (TimestampCondition)new ConditionFactory(jruby, column, config).createCondition();
|
220
|
+
assertTrue(condition.compare(null));
|
221
|
+
|
222
|
+
config = new DefaultConditionConfig() {
|
223
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
224
|
+
public Optional<Object> getArgument() { return Optional.absent(); }
|
225
|
+
};
|
226
|
+
try {
|
227
|
+
condition = (TimestampCondition)new ConditionFactory(jruby, column, config).createCondition();
|
228
|
+
fail("Argument is required");
|
229
|
+
} catch (ConfigException e) {
|
230
|
+
}
|
231
|
+
|
232
|
+
//ToDo: How to create jruby object correctly?
|
233
|
+
//config = new DefaultConditionConfig() {
|
234
|
+
// public Optional<String> getOperator() { return Optional.of("=="); }
|
235
|
+
// public Optional<Object> getArgument() { return Optional.of("2015-07-15"); }
|
236
|
+
// public Optional<String> getFormat() { return Optional.of("%Y-%m-%d"); }
|
237
|
+
//};
|
238
|
+
//condition = (TimestampCondition)new ConditionFactory(jruby, column, config).createCondition();
|
239
|
+
|
240
|
+
config = new DefaultConditionConfig() {
|
241
|
+
public Optional<String> getOperator() { return Optional.of("=="); }
|
242
|
+
public Optional<Object> getArgument() { return Optional.of(new Boolean(true)); }
|
243
|
+
};
|
244
|
+
try {
|
245
|
+
condition = (TimestampCondition)new ConditionFactory(jruby, column, config).createCondition();
|
246
|
+
fail("Argument type mismatch");
|
247
|
+
} catch (ConfigException e) {
|
248
|
+
}
|
249
|
+
}
|
250
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
package org.embulk.filter.row;
|
2
|
+
|
3
|
+
import org.embulk.filter.row.DoubleCondition;
|
4
|
+
import org.junit.Test;
|
5
|
+
import static org.junit.Assert.*;
|
6
|
+
|
7
|
+
public class TestDoubleCondition
|
8
|
+
{
|
9
|
+
@Test
|
10
|
+
public void testIsNull() {
|
11
|
+
DoubleCondition condition = new DoubleCondition("IS NULL", null, false);
|
12
|
+
assertTrue(condition.compare(null));
|
13
|
+
assertFalse(condition.compare(new Double(10)));
|
14
|
+
}
|
15
|
+
|
16
|
+
@Test
|
17
|
+
public void testIsNotNull() {
|
18
|
+
DoubleCondition condition = new DoubleCondition("IS NOT NULL", null, false);
|
19
|
+
assertFalse(condition.compare(null));
|
20
|
+
assertTrue(condition.compare(new Double(10)));
|
21
|
+
}
|
22
|
+
|
23
|
+
@Test
|
24
|
+
public void testEquals() {
|
25
|
+
DoubleCondition condition = new DoubleCondition("==", new Double(10), false);
|
26
|
+
assertFalse(condition.compare(null));
|
27
|
+
assertTrue( condition.compare(new Double(10)));
|
28
|
+
assertFalse(condition.compare(new Double(11)));
|
29
|
+
|
30
|
+
// Prohibited by Factory
|
31
|
+
// DoubleCondition condition = new DoubleCondition("==", null, false);
|
32
|
+
}
|
33
|
+
|
34
|
+
@Test
|
35
|
+
public void testNotEquals() {
|
36
|
+
DoubleCondition condition = new DoubleCondition("!=", new Double(10), false);
|
37
|
+
assertTrue( condition.compare(null));
|
38
|
+
assertFalse(condition.compare(new Double(10)));
|
39
|
+
assertTrue( condition.compare(new Double(11)));
|
40
|
+
}
|
41
|
+
|
42
|
+
@Test
|
43
|
+
public void testGreaterThan() {
|
44
|
+
DoubleCondition condition = new DoubleCondition(">", new Double(10), false);
|
45
|
+
assertFalse(condition.compare(null));
|
46
|
+
assertFalse(condition.compare(new Double(10)));
|
47
|
+
assertTrue( condition.compare(new Double(11)));
|
48
|
+
}
|
49
|
+
|
50
|
+
@Test
|
51
|
+
public void testGreaterEqual() {
|
52
|
+
DoubleCondition condition = new DoubleCondition(">=", new Double(11), false);
|
53
|
+
assertFalse(condition.compare(null));
|
54
|
+
assertFalse(condition.compare(new Double(10)));
|
55
|
+
assertTrue( condition.compare(new Double(11)));
|
56
|
+
}
|
57
|
+
|
58
|
+
@Test
|
59
|
+
public void testLessThan() {
|
60
|
+
DoubleCondition condition = new DoubleCondition("<", new Double(11), false);
|
61
|
+
assertFalse(condition.compare(null));
|
62
|
+
assertFalse(condition.compare(new Double(11)));
|
63
|
+
assertTrue( condition.compare(new Double(10)));
|
64
|
+
}
|
65
|
+
|
66
|
+
@Test
|
67
|
+
public void testLessEqual() {
|
68
|
+
DoubleCondition condition = new DoubleCondition("<=", new Double(11), false);
|
69
|
+
assertFalse(condition.compare(null));
|
70
|
+
assertFalse(condition.compare(new Double(12)));
|
71
|
+
assertTrue( condition.compare(new Double(11)));
|
72
|
+
}
|
73
|
+
|
74
|
+
@Test
|
75
|
+
public void testNot() {
|
76
|
+
DoubleCondition condition = new DoubleCondition("<=", new Double(11), true);
|
77
|
+
assertTrue( condition.compare(null));
|
78
|
+
assertTrue( condition.compare(new Double(12)));
|
79
|
+
assertFalse(condition.compare(new Double(11)));
|
80
|
+
}
|
81
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
package org.embulk.filter.row;
|
2
|
+
|
3
|
+
import org.embulk.filter.row.LongCondition;
|
4
|
+
import org.junit.Test;
|
5
|
+
import static org.junit.Assert.*;
|
6
|
+
|
7
|
+
public class TestLongCondition
|
8
|
+
{
|
9
|
+
@Test
|
10
|
+
public void testIsNull() {
|
11
|
+
LongCondition condition = new LongCondition("IS NULL", null, false);
|
12
|
+
assertTrue(condition.compare(null));
|
13
|
+
assertFalse(condition.compare(new Long(10)));
|
14
|
+
}
|
15
|
+
|
16
|
+
@Test
|
17
|
+
public void testIsNotNull() {
|
18
|
+
LongCondition condition = new LongCondition("IS NOT NULL", null, false);
|
19
|
+
assertFalse(condition.compare(null));
|
20
|
+
assertTrue(condition.compare(new Long(10)));
|
21
|
+
}
|
22
|
+
|
23
|
+
@Test
|
24
|
+
public void testEquals() {
|
25
|
+
LongCondition condition = new LongCondition("==", new Long(10), false);
|
26
|
+
assertFalse(condition.compare(null));
|
27
|
+
assertTrue( condition.compare(new Long(10)));
|
28
|
+
assertFalse(condition.compare(new Long(11)));
|
29
|
+
|
30
|
+
// Prohibited by Factory
|
31
|
+
// LongCondition condition = new LongCondition("==", null, false);
|
32
|
+
}
|
33
|
+
|
34
|
+
@Test
|
35
|
+
public void testNotEquals() {
|
36
|
+
LongCondition condition = new LongCondition("!=", new Long(10), false);
|
37
|
+
assertTrue( condition.compare(null));
|
38
|
+
assertFalse(condition.compare(new Long(10)));
|
39
|
+
assertTrue( condition.compare(new Long(11)));
|
40
|
+
}
|
41
|
+
|
42
|
+
@Test
|
43
|
+
public void testGreaterThan() {
|
44
|
+
LongCondition condition = new LongCondition(">", new Long(10), false);
|
45
|
+
assertFalse(condition.compare(null));
|
46
|
+
assertFalse(condition.compare(new Long(10)));
|
47
|
+
assertTrue( condition.compare(new Long(11)));
|
48
|
+
}
|
49
|
+
|
50
|
+
@Test
|
51
|
+
public void testGreaterEqual() {
|
52
|
+
LongCondition condition = new LongCondition(">=", new Long(11), false);
|
53
|
+
assertFalse(condition.compare(null));
|
54
|
+
assertFalse(condition.compare(new Long(10)));
|
55
|
+
assertTrue( condition.compare(new Long(11)));
|
56
|
+
}
|
57
|
+
|
58
|
+
@Test
|
59
|
+
public void testLessThan() {
|
60
|
+
LongCondition condition = new LongCondition("<", new Long(11), false);
|
61
|
+
assertFalse(condition.compare(null));
|
62
|
+
assertFalse(condition.compare(new Long(11)));
|
63
|
+
assertTrue( condition.compare(new Long(10)));
|
64
|
+
}
|
65
|
+
|
66
|
+
@Test
|
67
|
+
public void testLessEqual() {
|
68
|
+
LongCondition condition = new LongCondition("<=", new Long(11), false);
|
69
|
+
assertFalse(condition.compare(null));
|
70
|
+
assertFalse(condition.compare(new Long(12)));
|
71
|
+
assertTrue( condition.compare(new Long(11)));
|
72
|
+
}
|
73
|
+
|
74
|
+
@Test
|
75
|
+
public void testNot() {
|
76
|
+
LongCondition condition = new LongCondition("<=", new Long(11), true);
|
77
|
+
assertTrue( condition.compare(null));
|
78
|
+
assertTrue( condition.compare(new Long(12)));
|
79
|
+
assertFalse(condition.compare(new Long(11)));
|
80
|
+
}
|
81
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
package org.embulk.filter.row;
|
2
|
+
|
3
|
+
import org.embulk.filter.row.StringCondition;
|
4
|
+
import org.junit.Test;
|
5
|
+
import static org.junit.Assert.*;
|
6
|
+
|
7
|
+
public class TestStringCondition
|
8
|
+
{
|
9
|
+
@Test
|
10
|
+
public void testIsNull() {
|
11
|
+
StringCondition condition = new StringCondition("IS NULL", null, false);
|
12
|
+
assertTrue(condition.compare(null));
|
13
|
+
assertFalse(condition.compare("foo"));
|
14
|
+
}
|
15
|
+
|
16
|
+
@Test
|
17
|
+
public void testIsNotNull() {
|
18
|
+
StringCondition condition = new StringCondition("IS NOT NULL", null, false);
|
19
|
+
assertFalse(condition.compare(null));
|
20
|
+
assertTrue(condition.compare("foo"));
|
21
|
+
}
|
22
|
+
|
23
|
+
@Test
|
24
|
+
public void testEquals() {
|
25
|
+
StringCondition condition = new StringCondition("==", "foo", false);
|
26
|
+
assertFalse(condition.compare(null));
|
27
|
+
assertTrue( condition.compare("foo"));
|
28
|
+
assertFalse(condition.compare("bar"));
|
29
|
+
|
30
|
+
// Prohibited by Factory
|
31
|
+
// StringCondition condition = new StringCondition("==", null, false);
|
32
|
+
}
|
33
|
+
|
34
|
+
@Test
|
35
|
+
public void testNotEquals() {
|
36
|
+
StringCondition condition = new StringCondition("!=", "foo", false);
|
37
|
+
assertTrue( condition.compare(null));
|
38
|
+
assertFalse(condition.compare("foo"));
|
39
|
+
assertTrue( condition.compare("bar"));
|
40
|
+
}
|
41
|
+
|
42
|
+
@Test
|
43
|
+
public void testStartWith() {
|
44
|
+
StringCondition condition = new StringCondition("start_with", "f", false);
|
45
|
+
assertFalse(condition.compare(null));
|
46
|
+
assertTrue( condition.compare("foo"));
|
47
|
+
assertFalse(condition.compare("bar"));
|
48
|
+
}
|
49
|
+
|
50
|
+
@Test
|
51
|
+
public void testEndWith() {
|
52
|
+
StringCondition condition = new StringCondition("end_with", "o", false);
|
53
|
+
assertFalse(condition.compare(null));
|
54
|
+
assertTrue( condition.compare("foo"));
|
55
|
+
assertFalse(condition.compare("bar"));
|
56
|
+
}
|
57
|
+
|
58
|
+
@Test
|
59
|
+
public void testInclude() {
|
60
|
+
StringCondition condition = new StringCondition("include", "o", false);
|
61
|
+
assertFalse(condition.compare(null));
|
62
|
+
assertTrue( condition.compare("foo"));
|
63
|
+
assertFalse(condition.compare("bar"));
|
64
|
+
}
|
65
|
+
|
66
|
+
@Test
|
67
|
+
public void testNot() {
|
68
|
+
StringCondition condition = new StringCondition("include", "o", true);
|
69
|
+
assertTrue( condition.compare(null));
|
70
|
+
assertFalse(condition.compare("foo"));
|
71
|
+
assertTrue( condition.compare("bar"));
|
72
|
+
}
|
73
|
+
}
|