embulk-filter-query_string 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ /*
2
+ * Copyright 2016 Minnano Wedding Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package org.embulk.filter.query_string;
18
+
19
+ import com.google.common.base.Throwables;
20
+ import org.embulk.EmbulkTestRuntime;
21
+ import org.embulk.config.ConfigLoader;
22
+ import org.embulk.config.ConfigSource;
23
+ import org.embulk.config.TaskSource;
24
+ import org.embulk.spi.Exec;
25
+ import org.embulk.spi.FilterPlugin;
26
+ import org.embulk.spi.Page;
27
+ import org.embulk.spi.PageOutput;
28
+ import org.embulk.spi.PageReader;
29
+ import org.embulk.spi.PageTestUtils;
30
+ import org.embulk.spi.Schema;
31
+ import org.embulk.spi.TestPageBuilderReader;
32
+ import org.junit.Rule;
33
+ import org.junit.Test;
34
+
35
+ import java.io.IOException;
36
+ import java.io.InputStream;
37
+ import java.util.List;
38
+
39
+ import static org.embulk.spi.type.Types.STRING;
40
+ import static org.hamcrest.CoreMatchers.is;
41
+ import static org.junit.Assert.assertThat;
42
+
43
+ public class TestQueryStringFilterPlugin
44
+ {
45
+ @Rule
46
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
47
+
48
+ @Test
49
+ public void testTransaction()
50
+ {
51
+ ConfigSource configSource = loadConfigSource("testTransaction.yml");
52
+ final Schema inputSchema = Schema.builder()
53
+ .add("qb", STRING)
54
+ .add("qs", STRING)
55
+ .add("qa", STRING)
56
+ .build();
57
+
58
+ final QueryStringFilterPlugin plugin = new QueryStringFilterPlugin();
59
+
60
+ plugin.transaction(configSource, inputSchema, new FilterPlugin.Control()
61
+ {
62
+ @Override
63
+ public void run(TaskSource taskSource, Schema outputSchema)
64
+ {
65
+ assertThat(outputSchema.getColumnCount(), is(5));
66
+
67
+ assertThat(outputSchema.getColumn(0).getName(), is("qb"));
68
+ assertThat(outputSchema.getColumn(1).getName(), is("q1"));
69
+ assertThat(outputSchema.getColumn(2).getName(), is("q2"));
70
+ assertThat(outputSchema.getColumn(3).getName(), is("q3"));
71
+ assertThat(outputSchema.getColumn(4).getName(), is("qa"));
72
+ }
73
+ });
74
+ }
75
+
76
+ @Test
77
+ public void testOpenSuccessfully()
78
+ {
79
+ ConfigSource configSource = loadConfigSource("testOpen.yml");
80
+ final Schema inputSchema = Schema.builder()
81
+ .add("qb", STRING)
82
+ .add("qs", STRING)
83
+ .add("qa", STRING)
84
+ .build();
85
+
86
+ final QueryStringFilterPlugin plugin = new QueryStringFilterPlugin();
87
+ plugin.transaction(configSource, inputSchema, new FilterPlugin.Control()
88
+ {
89
+ @Override
90
+ public void run(TaskSource taskSource, Schema outputSchema)
91
+ {
92
+ TestPageBuilderReader.MockPageOutput mockPageOutput = new TestPageBuilderReader.MockPageOutput();
93
+ PageOutput pageOutput = plugin.open(taskSource, inputSchema, outputSchema, mockPageOutput);
94
+
95
+ List<Page> pages = PageTestUtils.buildPage(runtime.getBufferAllocator(), inputSchema, "before", "/path?q1=one&q2=2", "after");
96
+ for (Page page : pages) {
97
+ pageOutput.add(page);
98
+ }
99
+
100
+ pageOutput.finish();
101
+ pageOutput.close();
102
+
103
+ PageReader pageReader = new PageReader(outputSchema);
104
+ for (Page page : mockPageOutput.pages) {
105
+ pageReader.setPage(page);
106
+
107
+ assertThat(pageReader.getString(0), is("before"));
108
+ assertThat(pageReader.getString(1), is("one"));
109
+ assertThat(pageReader.getLong(2), is(Long.valueOf(2L)));
110
+ assertThat(pageReader.getString(3), is("after"));
111
+ }
112
+ }
113
+ });
114
+ }
115
+
116
+ private ConfigSource loadConfigSource(String yamlPath)
117
+ {
118
+ try {
119
+ ConfigLoader loader = new ConfigLoader(Exec.getModelManager());
120
+ InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(yamlPath);
121
+
122
+ return loader.fromYaml(stream);
123
+ }
124
+ catch (IOException e) {
125
+ throw Throwables.propagate(e);
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,5 @@
1
+ type: query_string
2
+ query_string_column_name: qs
3
+ expanded_columns:
4
+ - {name: q1, type: string}
5
+ - {name: q2, type: long}
@@ -0,0 +1,6 @@
1
+ type: query_string
2
+ query_string_column_name: qs
3
+ expanded_columns:
4
+ - {name: q1, type: boolean}
5
+ - {name: q2, type: long}
6
+ - {name: q3, type: string}
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-filter-query_string
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Minnano Wedding Co., Ltd.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ name: bundler
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '10.0'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: The query string filter plugin parses the column contents as query string and insert columns from that field.
42
+ email:
43
+ - takai.naoto@mwed.co.jp
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - LICENSE.txt
50
+ - README.md
51
+ - build.gradle
52
+ - config/checkstyle/checkstyle.xml
53
+ - config/checkstyle/default.xml
54
+ - gradle/wrapper/gradle-wrapper.jar
55
+ - gradle/wrapper/gradle-wrapper.properties
56
+ - gradlew
57
+ - gradlew.bat
58
+ - lib/embulk/filter/query_string.rb
59
+ - src/main/java/org/embulk/filter/query_string/QueryStringFilterPlugin.java
60
+ - src/test/java/org/embulk/filter/query_string/TestQueryStringFilterPlugin.java
61
+ - src/test/resources/testOpen.yml
62
+ - src/test/resources/testTransaction.yml
63
+ - classpath/commons-codec-1.9.jar
64
+ - classpath/commons-logging-1.2.jar
65
+ - classpath/embulk-filter-query_string-0.1.0.jar
66
+ - classpath/fastutil-6.2.2.jar
67
+ - classpath/httpclient-4.5.1.jar
68
+ - classpath/httpcore-4.4.3.jar
69
+ - classpath/log4j-1.2.17.jar
70
+ - classpath/util-urlparsing-1.0.15.jar
71
+ homepage: https://github.com/mwed/embulk-filter-query_string
72
+ licenses:
73
+ - Apache License, Version 2.0
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.1.9
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Query String filter plugin for Embulk
95
+ test_files: []