embulk-filter-query_string 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7259a5d22d2dcfe756e90863aa86e83ee47031cb
|
4
|
+
data.tar.gz: 0b77859eabb7effbc287629bdc0c0848317a1c81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbc77a119f5acdd290d6cc4ff8c82d1db7504ff4802bcfba93aa607713e027a23eda94ea12e029efb7895cd432a5accf5b57c8803401d2b9faba025ee5cc802d
|
7
|
+
data.tar.gz: 8f4eaa31cc2edfc262ebf22a9b920455a2327585afb542e1821c444e8b7c844d58a2f817d7fd3beefc83eda213ded9da9b81158e5caea08204a5eadb375a053d
|
data/build.gradle
CHANGED
@@ -14,14 +14,14 @@ configurations {
|
|
14
14
|
provided
|
15
15
|
}
|
16
16
|
|
17
|
-
version = "0.
|
17
|
+
version = "0.2.0"
|
18
18
|
|
19
19
|
sourceCompatibility = 1.7
|
20
20
|
targetCompatibility = 1.7
|
21
21
|
|
22
22
|
dependencies {
|
23
|
-
compile "org.embulk:embulk-core:0.8.
|
24
|
-
provided "org.embulk:embulk-core:0.8.
|
23
|
+
compile "org.embulk:embulk-core:0.8.13"
|
24
|
+
provided "org.embulk:embulk-core:0.8.13"
|
25
25
|
|
26
26
|
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
|
27
27
|
compile 'org.apache.httpcomponents:httpclient:4.5.1'
|
@@ -79,7 +79,7 @@ task gemspec {
|
|
79
79
|
gemspecFile.write($/
|
80
80
|
Gem::Specification.new do |spec|
|
81
81
|
spec.name = "embulk-filter-query_string"
|
82
|
-
spec.version = "
|
82
|
+
spec.version = "${version}"
|
83
83
|
spec.authors = ["Minnano Wedding Co., Ltd."]
|
84
84
|
spec.summary = %[Query String filter plugin for Embulk]
|
85
85
|
spec.description = %[The query string filter plugin parses the column contents as query string and insert columns from that field.]
|
@@ -40,10 +40,14 @@ import org.slf4j.Logger;
|
|
40
40
|
import java.util.HashMap;
|
41
41
|
import java.util.List;
|
42
42
|
import java.util.Map;
|
43
|
+
import java.util.regex.Matcher;
|
44
|
+
import java.util.regex.Pattern;
|
43
45
|
|
44
46
|
public class QueryStringFilterPlugin
|
45
47
|
implements FilterPlugin
|
46
48
|
{
|
49
|
+
public static final Pattern QUERY_STRING_PATTERN = Pattern.compile("[^\\?]*\\?([a-z0-9=&;*._%+-]+)", Pattern.CASE_INSENSITIVE);
|
50
|
+
|
47
51
|
@Override
|
48
52
|
public void transaction(ConfigSource config, Schema inputSchema, FilterPlugin.Control control)
|
49
53
|
{
|
@@ -173,16 +177,18 @@ public class QueryStringFilterPlugin
|
|
173
177
|
for (Column inputColumn : inputSchema.getColumns()) {
|
174
178
|
if (columnName.equals(inputColumn.getName())) {
|
175
179
|
String path = null;
|
176
|
-
|
180
|
+
String queryString = null;
|
177
181
|
|
178
182
|
if (!reader.isNull(inputColumn)) {
|
179
183
|
path = reader.getString(inputColumn);
|
180
|
-
pos = path.indexOf('?');
|
181
|
-
}
|
182
184
|
|
183
|
-
|
184
|
-
|
185
|
+
Matcher matcher = QUERY_STRING_PATTERN.matcher(path);
|
186
|
+
if (matcher.lookingAt()) {
|
187
|
+
queryString = matcher.group(1);
|
188
|
+
}
|
189
|
+
}
|
185
190
|
|
191
|
+
if (queryString != null) {
|
186
192
|
Map<String, Object> map = new HashMap<>();
|
187
193
|
QueryStringParser.parseQueryString(queryString, callback, map);
|
188
194
|
for (ColumnConfig config : task.getExpandedColumns()) {
|
@@ -45,6 +45,11 @@ import static org.junit.Assert.assertTrue;
|
|
45
45
|
|
46
46
|
public class TestQueryStringFilterPlugin
|
47
47
|
{
|
48
|
+
private static interface AssertionWithPage
|
49
|
+
{
|
50
|
+
void run(PageReader pageReader, TestPageBuilderReader.MockPageOutput pageOutput);
|
51
|
+
}
|
52
|
+
|
48
53
|
@Rule
|
49
54
|
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
|
50
55
|
|
@@ -85,26 +90,39 @@ public class TestQueryStringFilterPlugin
|
|
85
90
|
.add("qs", STRING)
|
86
91
|
.add("qa", STRING)
|
87
92
|
.build();
|
88
|
-
|
89
|
-
final QueryStringFilterPlugin plugin = new QueryStringFilterPlugin();
|
90
|
-
plugin.transaction(configSource, inputSchema, new FilterPlugin.Control()
|
93
|
+
testQueryString(configSource, inputSchema, "/path?q1=1&q2=2#fragment", new AssertionWithPage()
|
91
94
|
{
|
92
95
|
@Override
|
93
|
-
public void run(
|
96
|
+
public void run(PageReader pageReader, TestPageBuilderReader.MockPageOutput pageOutput)
|
94
97
|
{
|
95
|
-
|
96
|
-
|
98
|
+
for (Page page : pageOutput.pages) {
|
99
|
+
pageReader.setPage(page);
|
97
100
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
+
assertThat(pageReader.getString(0), is("before"));
|
102
|
+
assertThat(pageReader.getString(1), is("1"));
|
103
|
+
assertEquals(2L, pageReader.getLong(2));
|
104
|
+
assertThat(pageReader.getString(3), is("after"));
|
101
105
|
}
|
106
|
+
}
|
107
|
+
});
|
108
|
+
}
|
102
109
|
|
103
|
-
|
104
|
-
|
110
|
+
@Test
|
111
|
+
public void testOpenSuccessfullyWithHashbang()
|
112
|
+
{
|
113
|
+
ConfigSource configSource = loadConfigSource("testOpen.yml");
|
114
|
+
final Schema inputSchema = Schema.builder()
|
115
|
+
.add("qb", STRING)
|
116
|
+
.add("qs", STRING)
|
117
|
+
.add("qa", STRING)
|
118
|
+
.build();
|
105
119
|
|
106
|
-
|
107
|
-
|
120
|
+
testQueryString(configSource, inputSchema, "/#!/path?q1=one&q2=2#fragment", new AssertionWithPage()
|
121
|
+
{
|
122
|
+
@Override
|
123
|
+
public void run(PageReader pageReader, TestPageBuilderReader.MockPageOutput pageOutput)
|
124
|
+
{
|
125
|
+
for (Page page : pageOutput.pages) {
|
108
126
|
pageReader.setPage(page);
|
109
127
|
|
110
128
|
assertThat(pageReader.getString(0), is("before"));
|
@@ -152,6 +170,32 @@ public class TestQueryStringFilterPlugin
|
|
152
170
|
});
|
153
171
|
}
|
154
172
|
|
173
|
+
private void testQueryString(ConfigSource configSource, final Schema inputSchema, final String path, final AssertionWithPage assertion)
|
174
|
+
{
|
175
|
+
final QueryStringFilterPlugin plugin = new QueryStringFilterPlugin();
|
176
|
+
plugin.transaction(configSource, inputSchema, new FilterPlugin.Control()
|
177
|
+
{
|
178
|
+
@Override
|
179
|
+
public void run(TaskSource taskSource, Schema outputSchema)
|
180
|
+
{
|
181
|
+
TestPageBuilderReader.MockPageOutput mockPageOutput = new TestPageBuilderReader.MockPageOutput();
|
182
|
+
PageOutput pageOutput = plugin.open(taskSource, inputSchema, outputSchema, mockPageOutput);
|
183
|
+
|
184
|
+
List<Page> pages = PageTestUtils.buildPage(runtime.getBufferAllocator(), inputSchema, "before", path, "after");
|
185
|
+
for (Page page : pages) {
|
186
|
+
pageOutput.add(page);
|
187
|
+
}
|
188
|
+
|
189
|
+
pageOutput.finish();
|
190
|
+
pageOutput.close();
|
191
|
+
|
192
|
+
PageReader pageReader = new PageReader(outputSchema);
|
193
|
+
assertion.run(pageReader, mockPageOutput);
|
194
|
+
;
|
195
|
+
}
|
196
|
+
});
|
197
|
+
}
|
198
|
+
|
155
199
|
private ConfigSource loadConfigSource(String yamlPath)
|
156
200
|
{
|
157
201
|
try {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-filter-query_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minnano Wedding Co., Ltd.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,7 +64,7 @@ files:
|
|
64
64
|
- src/test/resources/testTransaction.yml
|
65
65
|
- classpath/commons-codec-1.9.jar
|
66
66
|
- classpath/commons-logging-1.2.jar
|
67
|
-
- classpath/embulk-filter-query_string-0.
|
67
|
+
- classpath/embulk-filter-query_string-0.2.0.jar
|
68
68
|
- classpath/fastutil-6.2.2.jar
|
69
69
|
- classpath/httpclient-4.5.1.jar
|
70
70
|
- classpath/httpcore-4.4.3.jar
|