embulk-filter-row 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/CHANGELOG.md +6 -0
  4. data/README.md +124 -4
  5. data/build.gradle +15 -4
  6. data/classpath/embulk-filter-row-0.3.0.jar +0 -0
  7. data/example/and.yml +0 -7
  8. data/example/example.yml +0 -7
  9. data/example/where.yml +28 -0
  10. data/script/byaccj.sh +29 -0
  11. data/src/main/java/org/embulk/filter/row/{AbstractColumnVisitor.java → AbstractGuardColumnVisitor.java} +9 -17
  12. data/src/main/java/org/embulk/filter/row/BuildColumnVisitorImpl.java +98 -0
  13. data/src/main/java/org/embulk/filter/row/{ColumnVisitorAndImpl.java → GuardColumnVisitorAndImpl.java} +11 -45
  14. data/src/main/java/org/embulk/filter/row/{ColumnVisitorOrImpl.java → GuardColumnVisitorOrImpl.java} +11 -45
  15. data/src/main/java/org/embulk/filter/row/GuardColumnVisitorWhereImpl.java +28 -0
  16. data/src/main/java/org/embulk/filter/row/RowFilterPlugin.java +49 -16
  17. data/src/main/java/org/embulk/filter/row/where/Parser.java +831 -0
  18. data/src/main/java/org/embulk/filter/row/where/ParserExp.java +290 -0
  19. data/src/main/java/org/embulk/filter/row/where/ParserLiteral.java +277 -0
  20. data/src/main/java/org/embulk/filter/row/where/ParserNode.java +6 -0
  21. data/src/main/java/org/embulk/filter/row/where/ParserVal.java +78 -0
  22. data/src/main/java/org/embulk/filter/row/where/Yylex.java +833 -0
  23. data/src/main/java/org/embulk/filter/row/where/_lexer.l +108 -0
  24. data/src/main/java/org/embulk/filter/row/where/_parser.y +137 -0
  25. data/src/test/java/org/embulk/filter/row/where/TestParser.java +383 -0
  26. data/src/test/java/org/embulk/filter/row/where/TestYylex.java +256 -0
  27. metadata +19 -5
  28. data/classpath/embulk-filter-row-0.2.2.jar +0 -0
@@ -0,0 +1,256 @@
1
+ package org.embulk.filter.row.where;
2
+
3
+ import org.embulk.spi.Schema;
4
+ import org.embulk.spi.SchemaConfigException;
5
+ import org.embulk.spi.time.Timestamp;
6
+ import org.junit.Before;
7
+ import org.junit.Test;
8
+
9
+ import java.io.IOException;
10
+
11
+ import static org.embulk.spi.type.Types.BOOLEAN;
12
+ import static org.junit.Assert.assertEquals;
13
+ import static org.junit.Assert.assertTrue;
14
+
15
+ public class TestYylex
16
+ {
17
+ Parser yyparser;
18
+ Yylex lexer;
19
+
20
+ @Before
21
+ public void setUp()
22
+ {
23
+ yyparser = new Parser(Schema.builder().build());
24
+ }
25
+
26
+ void assertNextToken(int token)
27
+ {
28
+ try {
29
+ assertEquals(token, lexer.yylex());
30
+ }
31
+ catch (IOException e) {
32
+ e.printStackTrace();
33
+ }
34
+ }
35
+
36
+ ParserNode currentNode()
37
+ {
38
+ return (ParserNode)(yyparser.yylval.obj);
39
+ }
40
+
41
+ @Test
42
+ public void testOperator()
43
+ {
44
+ lexer = new Yylex("START_WITH", yyparser);
45
+ assertNextToken(Parser.START_WITH);
46
+
47
+ lexer = new Yylex("(", yyparser);
48
+ assertNextToken('(');
49
+
50
+ lexer = new Yylex(" = ", yyparser);
51
+ assertNextToken(Parser.EQ);
52
+ }
53
+
54
+ void assertIdentifier(String name)
55
+ {
56
+ assertEquals("IdentifierLiteral", currentNode().getClass().getSimpleName());
57
+ assertEquals(name, ((IdentifierLiteral)currentNode()).name);
58
+ }
59
+
60
+ @Test
61
+ public void testIdentifier()
62
+ {
63
+ Schema schema = Schema.builder()
64
+ .add("foobar", BOOLEAN)
65
+ .add("foo bar", BOOLEAN)
66
+ .add("foo\"bar", BOOLEAN)
67
+ .add("$.foo.bar", BOOLEAN) // Support JSONPath someday
68
+ .add("$['foo'][0:4][*]", BOOLEAN) // Support JSONPath someday
69
+ .build();
70
+ yyparser = new Parser(schema);
71
+
72
+ lexer = new Yylex("foobar", yyparser);
73
+ assertNextToken(Parser.IDENTIFIER);
74
+ assertIdentifier("foobar");
75
+
76
+ lexer = new Yylex(" foobar ", yyparser);
77
+ assertNextToken(Parser.IDENTIFIER);
78
+ assertIdentifier("foobar");
79
+
80
+ lexer = new Yylex("\"foobar\"", yyparser);
81
+ assertNextToken(Parser.IDENTIFIER);
82
+ assertIdentifier("foobar");
83
+
84
+ lexer = new Yylex(" \"foo bar\" ", yyparser);
85
+ assertNextToken(Parser.IDENTIFIER);
86
+ assertIdentifier("foo bar");
87
+
88
+ lexer = new Yylex(" \"foo\\\"bar\" ", yyparser);
89
+ assertNextToken(Parser.IDENTIFIER);
90
+ assertIdentifier("foo\"bar");
91
+
92
+ lexer = new Yylex("$.foo.bar", yyparser);
93
+ assertNextToken(Parser.IDENTIFIER);
94
+ assertIdentifier("$.foo.bar");
95
+
96
+ lexer = new Yylex("\"$['foo'][0:4][*]\"", yyparser);
97
+ assertNextToken(Parser.IDENTIFIER);
98
+ assertIdentifier("$['foo'][0:4][*]");
99
+
100
+ try {
101
+ lexer = new Yylex("$['foo'][0:4][*]", yyparser);
102
+ assertNextToken(Parser.IDENTIFIER);
103
+ assertTrue(false);
104
+ }
105
+ catch (SchemaConfigException e) {
106
+ }
107
+
108
+ try {
109
+ lexer = new Yylex("unknown", yyparser);
110
+ assertNextToken(Parser.IDENTIFIER);
111
+ assertTrue(false);
112
+ }
113
+ catch (SchemaConfigException e) {
114
+ }
115
+ }
116
+
117
+ void assertBoolean(boolean val)
118
+ {
119
+ assertEquals("BooleanLiteral", currentNode().getClass().getSimpleName());
120
+ assertEquals(val, ((BooleanLiteral)currentNode()).val);
121
+ }
122
+
123
+ @Test
124
+ public void testBoolean()
125
+ {
126
+ lexer = new Yylex("true", yyparser);
127
+ assertNextToken(Parser.BOOLEAN);
128
+ assertBoolean(true);
129
+
130
+ lexer = new Yylex("false", yyparser);
131
+ assertNextToken(Parser.BOOLEAN);
132
+ assertBoolean(false);
133
+
134
+ lexer = new Yylex("TRUE", yyparser);
135
+ assertNextToken(Parser.BOOLEAN);
136
+ assertBoolean(true);
137
+
138
+ lexer = new Yylex("FALSE", yyparser);
139
+ assertNextToken(Parser.BOOLEAN);
140
+ assertBoolean(false);
141
+
142
+ lexer = new Yylex(" true ", yyparser);
143
+ assertNextToken(Parser.BOOLEAN);
144
+ assertBoolean(true);
145
+ }
146
+
147
+ void assertNumber(double val)
148
+ {
149
+ assertEquals("NumberLiteral", currentNode().getClass().getSimpleName());
150
+ assertEquals(val, ((NumberLiteral)currentNode()).val, 0.0);
151
+ }
152
+
153
+ @Test
154
+ public void testNumber()
155
+ {
156
+ lexer = new Yylex("1.5", yyparser);
157
+ assertNextToken(Parser.NUMBER);
158
+ assertNumber(1.5);
159
+
160
+ lexer = new Yylex("1", yyparser);
161
+ assertNextToken(Parser.NUMBER);
162
+ assertNumber(1);
163
+
164
+ lexer = new Yylex("-1.5", yyparser);
165
+ assertNextToken(Parser.NUMBER);
166
+ assertNumber(-1.5);
167
+
168
+ lexer = new Yylex(" -1.5 ", yyparser);
169
+ assertNextToken(Parser.NUMBER);
170
+ assertNumber(-1.5);
171
+ }
172
+
173
+ void assertString(String val)
174
+ {
175
+ assertEquals("StringLiteral", currentNode().getClass().getSimpleName());
176
+ assertEquals(val, ((StringLiteral)currentNode()).val);
177
+ }
178
+
179
+ @Test
180
+ public void testString()
181
+ {
182
+ lexer = new Yylex("'foobar'", yyparser);
183
+ assertNextToken(Parser.STRING);
184
+ assertString("foobar");
185
+
186
+ lexer = new Yylex("'foo bar'", yyparser);
187
+ assertNextToken(Parser.STRING);
188
+ assertString("foo bar");
189
+
190
+ lexer = new Yylex("'foo\\'bar'", yyparser);
191
+ assertNextToken(Parser.STRING);
192
+ assertString("foo\'bar");
193
+ }
194
+
195
+ @Test
196
+ public void testTimestamp()
197
+ {
198
+ lexer = new Yylex("TIMESTAMP 1.5", yyparser);
199
+ assertNextToken(Parser.TIMESTAMP);
200
+ assertNextToken(Parser.NUMBER);
201
+ assertNumber(1.5);
202
+
203
+ lexer = new Yylex("TIMESTAMP '2015-01-01'", yyparser);
204
+ assertNextToken(Parser.TIMESTAMP);
205
+ assertNextToken(Parser.STRING);
206
+ assertString("2015-01-01");
207
+ }
208
+
209
+ @Test
210
+ public void testComplex()
211
+ {
212
+ Schema schema = Schema.builder()
213
+ .add("true", BOOLEAN)
214
+ .add("foobar", BOOLEAN)
215
+ .build();
216
+ yyparser = new Parser(schema);
217
+
218
+ lexer = new Yylex("( \"true\" = true OR \"true\" = false ) AND foobar = false", yyparser);
219
+ assertNextToken('(');
220
+ assertNextToken(Parser.IDENTIFIER);
221
+ assertNextToken(Parser.EQ);
222
+ assertNextToken(Parser.BOOLEAN);
223
+ assertNextToken(Parser.OR);
224
+ assertNextToken(Parser.IDENTIFIER);
225
+ assertNextToken(Parser.EQ);
226
+ assertNextToken(Parser.BOOLEAN);
227
+ assertNextToken(')');
228
+ assertNextToken(Parser.AND);
229
+ assertNextToken(Parser.IDENTIFIER);
230
+ assertNextToken(Parser.EQ);
231
+ assertNextToken(Parser.BOOLEAN);
232
+
233
+ lexer = new Yylex("(\"true\"=true OR\"true\"=false)AND foobar=false", yyparser);
234
+ assertNextToken('(');
235
+ assertNextToken(Parser.IDENTIFIER);
236
+ assertNextToken(Parser.EQ);
237
+ assertNextToken(Parser.BOOLEAN);
238
+ assertNextToken(Parser.OR);
239
+ assertNextToken(Parser.IDENTIFIER);
240
+ assertNextToken(Parser.EQ);
241
+ assertNextToken(Parser.BOOLEAN);
242
+ assertNextToken(')');
243
+ assertNextToken(Parser.AND);
244
+ assertNextToken(Parser.IDENTIFIER);
245
+ assertNextToken(Parser.EQ);
246
+ assertNextToken(Parser.BOOLEAN);
247
+
248
+ lexer = new Yylex("NOT(true=\"true\")", yyparser);
249
+ assertNextToken(Parser.NOT);
250
+ assertNextToken('(');
251
+ assertNextToken(Parser.BOOLEAN);
252
+ assertNextToken(Parser.EQ);
253
+ assertNextToken(Parser.IDENTIFIER);
254
+ assertNextToken(')');
255
+ }
256
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-filter-row
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
@@ -56,15 +56,19 @@ files:
56
56
  - example/example.csv
57
57
  - example/example.yml
58
58
  - example/or.yml
59
+ - example/where.yml
59
60
  - gradle/wrapper/gradle-wrapper.jar
60
61
  - gradle/wrapper/gradle-wrapper.properties
61
62
  - gradlew
62
63
  - gradlew.bat
63
64
  - lib/embulk/filter/row.rb
65
+ - script/byaccj.sh
64
66
  - settings.gradle
65
- - src/main/java/org/embulk/filter/row/AbstractColumnVisitor.java
66
- - src/main/java/org/embulk/filter/row/ColumnVisitorAndImpl.java
67
- - src/main/java/org/embulk/filter/row/ColumnVisitorOrImpl.java
67
+ - src/main/java/org/embulk/filter/row/AbstractGuardColumnVisitor.java
68
+ - src/main/java/org/embulk/filter/row/BuildColumnVisitorImpl.java
69
+ - src/main/java/org/embulk/filter/row/GuardColumnVisitorAndImpl.java
70
+ - src/main/java/org/embulk/filter/row/GuardColumnVisitorOrImpl.java
71
+ - src/main/java/org/embulk/filter/row/GuardColumnVisitorWhereImpl.java
68
72
  - src/main/java/org/embulk/filter/row/RowFilterPlugin.java
69
73
  - src/main/java/org/embulk/filter/row/condition/BooleanCondition.java
70
74
  - src/main/java/org/embulk/filter/row/condition/Condition.java
@@ -74,13 +78,23 @@ files:
74
78
  - src/main/java/org/embulk/filter/row/condition/LongCondition.java
75
79
  - src/main/java/org/embulk/filter/row/condition/StringCondition.java
76
80
  - src/main/java/org/embulk/filter/row/condition/TimestampCondition.java
81
+ - src/main/java/org/embulk/filter/row/where/Parser.java
82
+ - src/main/java/org/embulk/filter/row/where/ParserExp.java
83
+ - src/main/java/org/embulk/filter/row/where/ParserLiteral.java
84
+ - src/main/java/org/embulk/filter/row/where/ParserNode.java
85
+ - src/main/java/org/embulk/filter/row/where/ParserVal.java
86
+ - src/main/java/org/embulk/filter/row/where/Yylex.java
87
+ - src/main/java/org/embulk/filter/row/where/_lexer.l
88
+ - src/main/java/org/embulk/filter/row/where/_parser.y
77
89
  - src/test/java/org/embulk/filter/row/condition/TestBooleanCondition.java
78
90
  - src/test/java/org/embulk/filter/row/condition/TestConditionFactory.java
79
91
  - src/test/java/org/embulk/filter/row/condition/TestDoubleCondition.java
80
92
  - src/test/java/org/embulk/filter/row/condition/TestLongCondition.java
81
93
  - src/test/java/org/embulk/filter/row/condition/TestStringCondition.java
82
94
  - src/test/java/org/embulk/filter/row/condition/TestTimestampCondition.java
83
- - classpath/embulk-filter-row-0.2.2.jar
95
+ - src/test/java/org/embulk/filter/row/where/TestParser.java
96
+ - src/test/java/org/embulk/filter/row/where/TestYylex.java
97
+ - classpath/embulk-filter-row-0.3.0.jar
84
98
  homepage: https://github.com/sonots/embulk-filter-row
85
99
  licenses:
86
100
  - MIT
Binary file