embulk-filter-mysql_lookup 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +133 -0
- data/build.gradle +98 -0
- data/classpath/embulk-filter-mysql_lookup-0.1.1.jar +0 -0
- data/classpath/mysql-connector-java-8.0.19.jar +0 -0
- data/classpath/protobuf-java-3.6.1.jar +0 -0
- data/config/checkstyle/checkstyle.xml +128 -0
- data/config/checkstyle/default.xml +108 -0
- data/example/config.yml +45 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +5 -0
- data/gradlew +172 -0
- data/gradlew.bat +84 -0
- data/lib/embulk/filter/mysql_lookup.rb +3 -0
- data/src/main/java/org/embulk/filter/mysql_lookup/DatabaseConnection.java +38 -0
- data/src/main/java/org/embulk/filter/mysql_lookup/MysqlLookupFilterPlugin.java +360 -0
- data/src/test/java/org/embulk/filter/mysql_lookup/TestMysqlLookupFilterPlugin.java +5 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1edcd96e9f045d65422c89365d9cc96dcc2a07be1eb8b2621649ab4b7ec536cb
|
4
|
+
data.tar.gz: dc11321041d2742c1fb16049f2c30eba9713afa4c3bb0b493c80dabce28d0cf7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edbed44e7896c2386ad927cfefa776d00d604833a299449b2b6f9c4fdfe108b62b7974b08fc6c69cc5d1c46264b90821c5e4501a0b0f7e0808a6a16f9cefdcce
|
7
|
+
data.tar.gz: 26c97994a36265efd1f80dee4b6cd647cbacc8580a2badc04bd60964f63600702debca3f558bfe43e52b6dac1ec744028cb9beaf1c70360b814850e3d4420640
|
data/.gitignore
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 InfoObjects Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# MYSQL lookup filter plugin for Embulk
|
2
|
+
|
3
|
+
An Embulk filter plugin for Lookup Transformation with MySQL database
|
4
|
+
|
5
|
+
## Configuration
|
6
|
+
|
7
|
+
- **mysql_lookup**: Required attributes for the LookUp Filter Plugin -
|
8
|
+
- **host**: database host (example `localhost`) (required)
|
9
|
+
- **port**: database port (example port for mssql `1433`) (required
|
10
|
+
- **database**: database name (required)
|
11
|
+
- **tablename**: table name of your database (required)
|
12
|
+
- **username**: username for your database (required)
|
13
|
+
- **password**: password for database (required)
|
14
|
+
- **mapping_from**: (Name of columns to be matched with table 2 columns) (required)
|
15
|
+
- **Name of column-1**: column name-1 from input file
|
16
|
+
- **Name of column-2**: column name-2 from input file etc ...
|
17
|
+
- **mapping_to**: (Name of columns to be matched with table 1 columns) (required)
|
18
|
+
- **Name of column-1**: column name-1 from input file
|
19
|
+
- **Name of column-2**: column name-2 from input file
|
20
|
+
- **new_columns**: (New generated column names) (required)
|
21
|
+
- **Name-1,Type-1**: Any Name, Type of the name (name: country_name, type: string)
|
22
|
+
- **Name-2,Type-2**: Any Name, Type of the name (name: country_address, type: string) etc ...
|
23
|
+
## Example - columns
|
24
|
+
|
25
|
+
Input1 for table 1 is as follows :-
|
26
|
+
|
27
|
+
```
|
28
|
+
year country_code country_name literacy_rate
|
29
|
+
|
30
|
+
1990 1 India 80%
|
31
|
+
1993 2 USA 83%
|
32
|
+
1997 3 JAPAN
|
33
|
+
1999 4 China 72%
|
34
|
+
2000 5 Ukraine 68%
|
35
|
+
2002 6 Italy 79%
|
36
|
+
2004 7 UK 75%
|
37
|
+
2011 8 NULL 42%
|
38
|
+
```
|
39
|
+
|
40
|
+
Input2 for table 2 is as follows :-
|
41
|
+
|
42
|
+
```
|
43
|
+
id country_population country_address country_GDP
|
44
|
+
|
45
|
+
1 11.3 India 1.67
|
46
|
+
2 18.2 USA 16.72
|
47
|
+
3 30 JAPAN 5.00
|
48
|
+
4 4 China 9.33
|
49
|
+
5 57 Ukraine 1.08
|
50
|
+
6 63 Italy 2.068
|
51
|
+
7 17 UK 2.49
|
52
|
+
8 28 UAE 1.18
|
53
|
+
|
54
|
+
|
55
|
+
Note: country_population is calculated in Billion and country_GDP is calculated in $USD Trillion
|
56
|
+
```
|
57
|
+
|
58
|
+
As shown in yaml below, columns mentioned in mapping_from will be mapped with columns mentioned in mapping_to
|
59
|
+
ie:
|
60
|
+
|
61
|
+
|
62
|
+
country_code : id
|
63
|
+
country_name : country_address
|
64
|
+
|
65
|
+
After successful mapping an Output.csv file containing the columns mentioned in new_columns will be generated
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Output File generated :-
|
70
|
+
|
71
|
+
```
|
72
|
+
year country_code country_name literacy_rate country_GDP country_population
|
73
|
+
|
74
|
+
1990 1 India 80% 1.67 11.3
|
75
|
+
1993 2 USA 83% 16.72 18.2
|
76
|
+
1997 3 JAPAN 5.00 30
|
77
|
+
1999 4 China 72% 9.33 4
|
78
|
+
2000 5 Ukraine 68% 1.08 57
|
79
|
+
2002 6 Italy 79% 2.068 63
|
80
|
+
2004 7 UK 75% 2.49 17
|
81
|
+
2011 8 NULL 42%
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
```yaml
|
87
|
+
- type: mysql_lookup
|
88
|
+
host: localhost
|
89
|
+
port: 1433
|
90
|
+
database: test
|
91
|
+
tablename: country_details
|
92
|
+
username: root
|
93
|
+
password: root
|
94
|
+
mapping_from:
|
95
|
+
- country_code
|
96
|
+
- country_name
|
97
|
+
mapping_to:
|
98
|
+
- id
|
99
|
+
- country_address
|
100
|
+
new_columns:
|
101
|
+
- { name: country_GDP, type: string }
|
102
|
+
- { name: country_population, type: string }
|
103
|
+
```
|
104
|
+
|
105
|
+
Notes:
|
106
|
+
1. mapping_from attribute should be in same order as mentioned in input file.
|
107
|
+
|
108
|
+
## Development
|
109
|
+
|
110
|
+
Run example:
|
111
|
+
|
112
|
+
```
|
113
|
+
$ ./gradlew package
|
114
|
+
$ embulk run -I ./lib seed.yml
|
115
|
+
```
|
116
|
+
|
117
|
+
Deployment Steps:
|
118
|
+
|
119
|
+
```
|
120
|
+
Install ruby in your machine
|
121
|
+
$ gem install gemcutter (For windows OS)
|
122
|
+
|
123
|
+
$ ./gradlew gemPush
|
124
|
+
$ gem build NameOfYourPlugins (example: embulk-filter-mssql_lookup)
|
125
|
+
$ gem push embulk-filter-mssql_lookup-0.1.0.gem (You will get this name after running above command)
|
126
|
+
```
|
127
|
+
|
128
|
+
|
129
|
+
Release gem:
|
130
|
+
|
131
|
+
```
|
132
|
+
$ ./gradlew gemPush
|
133
|
+
```
|
data/build.gradle
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
plugins {
|
2
|
+
id "com.jfrog.bintray" version "1.1"
|
3
|
+
id "com.github.jruby-gradle.base" version "1.5.0"
|
4
|
+
id "java"
|
5
|
+
id "checkstyle"
|
6
|
+
}
|
7
|
+
import com.github.jrubygradle.JRubyExec
|
8
|
+
repositories {
|
9
|
+
mavenCentral()
|
10
|
+
jcenter()
|
11
|
+
}
|
12
|
+
configurations {
|
13
|
+
provided
|
14
|
+
}
|
15
|
+
|
16
|
+
version = "0.1.1"
|
17
|
+
|
18
|
+
sourceCompatibility = 1.8
|
19
|
+
targetCompatibility = 1.8
|
20
|
+
|
21
|
+
dependencies {
|
22
|
+
compile "org.embulk:embulk-core:0.9.+"
|
23
|
+
provided "org.embulk:embulk-core:0.9.+"
|
24
|
+
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
|
25
|
+
testCompile "junit:junit:4.+"
|
26
|
+
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.19'
|
27
|
+
}
|
28
|
+
|
29
|
+
task classpath(type: Copy, dependsOn: ["jar"]) {
|
30
|
+
doFirst { file("classpath").deleteDir() }
|
31
|
+
from (configurations.runtime - configurations.provided + files(jar.archivePath))
|
32
|
+
into "classpath"
|
33
|
+
}
|
34
|
+
clean { delete "classpath" }
|
35
|
+
|
36
|
+
checkstyle {
|
37
|
+
configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml")
|
38
|
+
toolVersion = '6.14.1'
|
39
|
+
}
|
40
|
+
checkstyleMain {
|
41
|
+
configFile = file("${project.rootDir}/config/checkstyle/default.xml")
|
42
|
+
ignoreFailures = true
|
43
|
+
}
|
44
|
+
checkstyleTest {
|
45
|
+
configFile = file("${project.rootDir}/config/checkstyle/default.xml")
|
46
|
+
ignoreFailures = true
|
47
|
+
}
|
48
|
+
task checkstyle(type: Checkstyle) {
|
49
|
+
classpath = sourceSets.main.output + sourceSets.test.output
|
50
|
+
source = sourceSets.main.allJava + sourceSets.test.allJava
|
51
|
+
}
|
52
|
+
|
53
|
+
task gem(type: JRubyExec, dependsOn: ["gemspec", "classpath"]) {
|
54
|
+
jrubyArgs "-S"
|
55
|
+
script "gem"
|
56
|
+
scriptArgs "build", "${project.name}.gemspec"
|
57
|
+
doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
|
58
|
+
}
|
59
|
+
|
60
|
+
task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
|
61
|
+
jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "push"
|
62
|
+
script "pkg/${project.name}-${project.version}.gem"
|
63
|
+
}
|
64
|
+
|
65
|
+
task "package"(dependsOn: ["gemspec", "classpath"]) {
|
66
|
+
doLast {
|
67
|
+
println "> Build succeeded."
|
68
|
+
println "> You can run embulk with '-L ${file(".").absolutePath}' argument."
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
task gemspec {
|
73
|
+
ext.gemspecFile = file("${project.name}.gemspec")
|
74
|
+
inputs.file "build.gradle"
|
75
|
+
outputs.file gemspecFile
|
76
|
+
doLast { gemspecFile.write($/
|
77
|
+
Gem::Specification.new do |spec|
|
78
|
+
spec.name = "${project.name}"
|
79
|
+
spec.version = "${project.version}"
|
80
|
+
spec.authors = ["InfoObjects Inc."]
|
81
|
+
spec.summary = %[An Embulk filter plugin for Lookup Transformation with MySQL database]
|
82
|
+
spec.description = %[Mysql Lookup filter]
|
83
|
+
spec.email = ["utkarsh@infoobjects.com"]
|
84
|
+
spec.licenses = ["MIT"]
|
85
|
+
spec.homepage = "https://github.com/InfoObjects/embulk-filter-mysql_lookup"
|
86
|
+
|
87
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
88
|
+
spec.test_files = spec.files.grep(%r"^(test|spec)/")
|
89
|
+
spec.require_paths = ["lib"]
|
90
|
+
|
91
|
+
spec.add_development_dependency 'bundler', ['~> 1.0']
|
92
|
+
spec.add_development_dependency 'rake', ['~> 12.0']
|
93
|
+
end
|
94
|
+
/$)
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
clean { delete "${project.name}.gemspec" }
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,128 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE module PUBLIC
|
3
|
+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
4
|
+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
5
|
+
<module name="Checker">
|
6
|
+
<!-- https://github.com/facebook/presto/blob/master/src/checkstyle/checks.xml -->
|
7
|
+
<module name="FileTabCharacter"/>
|
8
|
+
<module name="NewlineAtEndOfFile">
|
9
|
+
<property name="lineSeparator" value="lf"/>
|
10
|
+
</module>
|
11
|
+
<module name="RegexpMultiline">
|
12
|
+
<property name="format" value="\r"/>
|
13
|
+
<property name="message" value="Line contains carriage return"/>
|
14
|
+
</module>
|
15
|
+
<module name="RegexpMultiline">
|
16
|
+
<property name="format" value=" \n"/>
|
17
|
+
<property name="message" value="Line has trailing whitespace"/>
|
18
|
+
</module>
|
19
|
+
<module name="RegexpMultiline">
|
20
|
+
<property name="format" value="\{\n\n"/>
|
21
|
+
<property name="message" value="Blank line after opening brace"/>
|
22
|
+
</module>
|
23
|
+
<module name="RegexpMultiline">
|
24
|
+
<property name="format" value="\n\n\s*\}"/>
|
25
|
+
<property name="message" value="Blank line before closing brace"/>
|
26
|
+
</module>
|
27
|
+
<module name="RegexpMultiline">
|
28
|
+
<property name="format" value="\n\n\n"/>
|
29
|
+
<property name="message" value="Multiple consecutive blank lines"/>
|
30
|
+
</module>
|
31
|
+
<module name="RegexpMultiline">
|
32
|
+
<property name="format" value="\n\n\Z"/>
|
33
|
+
<property name="message" value="Blank line before end of file"/>
|
34
|
+
</module>
|
35
|
+
<module name="RegexpMultiline">
|
36
|
+
<property name="format" value="Preconditions\.checkNotNull"/>
|
37
|
+
<property name="message" value="Use of checkNotNull"/>
|
38
|
+
</module>
|
39
|
+
|
40
|
+
<module name="TreeWalker">
|
41
|
+
<module name="EmptyBlock">
|
42
|
+
<property name="option" value="text"/>
|
43
|
+
<property name="tokens" value="
|
44
|
+
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
|
45
|
+
LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, INSTANCE_INIT, STATIC_INIT"/>
|
46
|
+
</module>
|
47
|
+
<module name="EmptyStatement"/>
|
48
|
+
<module name="EmptyForInitializerPad"/>
|
49
|
+
<module name="EmptyForIteratorPad">
|
50
|
+
<property name="option" value="space"/>
|
51
|
+
</module>
|
52
|
+
<module name="MethodParamPad">
|
53
|
+
<property name="allowLineBreaks" value="true"/>
|
54
|
+
<property name="option" value="nospace"/>
|
55
|
+
</module>
|
56
|
+
<module name="ParenPad"/>
|
57
|
+
<module name="TypecastParenPad"/>
|
58
|
+
<module name="NeedBraces"/>
|
59
|
+
<module name="LeftCurly">
|
60
|
+
<property name="option" value="nl"/>
|
61
|
+
<property name="tokens" value="CLASS_DEF, CTOR_DEF, INTERFACE_DEF, METHOD_DEF"/>
|
62
|
+
</module>
|
63
|
+
<module name="LeftCurly">
|
64
|
+
<property name="option" value="eol"/>
|
65
|
+
<property name="tokens" value="
|
66
|
+
LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR,
|
67
|
+
LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE"/>
|
68
|
+
</module>
|
69
|
+
<module name="RightCurly">
|
70
|
+
<property name="option" value="alone"/>
|
71
|
+
</module>
|
72
|
+
<module name="GenericWhitespace"/>
|
73
|
+
<module name="WhitespaceAfter"/>
|
74
|
+
<module name="NoWhitespaceBefore"/>
|
75
|
+
|
76
|
+
<module name="UpperEll"/>
|
77
|
+
<module name="DefaultComesLast"/>
|
78
|
+
<module name="ArrayTypeStyle"/>
|
79
|
+
<module name="MultipleVariableDeclarations"/>
|
80
|
+
<module name="ModifierOrder"/>
|
81
|
+
<module name="OneStatementPerLine"/>
|
82
|
+
<module name="StringLiteralEquality"/>
|
83
|
+
<module name="MutableException"/>
|
84
|
+
<module name="EqualsHashCode"/>
|
85
|
+
<module name="InnerAssignment"/>
|
86
|
+
<module name="InterfaceIsType"/>
|
87
|
+
<module name="HideUtilityClassConstructor"/>
|
88
|
+
|
89
|
+
<module name="MemberName"/>
|
90
|
+
<module name="LocalVariableName"/>
|
91
|
+
<module name="LocalFinalVariableName"/>
|
92
|
+
<module name="TypeName"/>
|
93
|
+
<module name="PackageName"/>
|
94
|
+
<module name="ParameterName"/>
|
95
|
+
<module name="StaticVariableName"/>
|
96
|
+
<module name="ClassTypeParameterName">
|
97
|
+
<property name="format" value="^[A-Z][0-9]?$"/>
|
98
|
+
</module>
|
99
|
+
<module name="MethodTypeParameterName">
|
100
|
+
<property name="format" value="^[A-Z][0-9]?$"/>
|
101
|
+
</module>
|
102
|
+
|
103
|
+
<module name="AvoidStarImport"/>
|
104
|
+
<module name="RedundantImport"/>
|
105
|
+
<module name="UnusedImports"/>
|
106
|
+
<module name="ImportOrder">
|
107
|
+
<property name="groups" value="*,javax,java"/>
|
108
|
+
<property name="separated" value="true"/>
|
109
|
+
<property name="option" value="bottom"/>
|
110
|
+
<property name="sortStaticImportsAlphabetically" value="true"/>
|
111
|
+
</module>
|
112
|
+
|
113
|
+
<module name="WhitespaceAround">
|
114
|
+
<property name="allowEmptyConstructors" value="true"/>
|
115
|
+
<property name="allowEmptyMethods" value="true"/>
|
116
|
+
<property name="ignoreEnhancedForColon" value="false"/>
|
117
|
+
<property name="tokens" value="
|
118
|
+
ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN,
|
119
|
+
BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE,
|
120
|
+
LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
121
|
+
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
122
|
+
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE,
|
123
|
+
LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL,
|
124
|
+
PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN,
|
125
|
+
STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
|
126
|
+
</module>
|
127
|
+
</module>
|
128
|
+
</module>
|
@@ -0,0 +1,108 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE module PUBLIC
|
3
|
+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
4
|
+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
5
|
+
<!--
|
6
|
+
This is a subset of ./checkstyle.xml which allows some loose styles
|
7
|
+
-->
|
8
|
+
<module name="Checker">
|
9
|
+
<module name="FileTabCharacter"/>
|
10
|
+
<module name="NewlineAtEndOfFile">
|
11
|
+
<property name="lineSeparator" value="lf"/>
|
12
|
+
</module>
|
13
|
+
<module name="RegexpMultiline">
|
14
|
+
<property name="format" value="\r"/>
|
15
|
+
<property name="message" value="Line contains carriage return"/>
|
16
|
+
</module>
|
17
|
+
<module name="RegexpMultiline">
|
18
|
+
<property name="format" value=" \n"/>
|
19
|
+
<property name="message" value="Line has trailing whitespace"/>
|
20
|
+
</module>
|
21
|
+
<module name="RegexpMultiline">
|
22
|
+
<property name="format" value="\n\n\n"/>
|
23
|
+
<property name="message" value="Multiple consecutive blank lines"/>
|
24
|
+
</module>
|
25
|
+
<module name="RegexpMultiline">
|
26
|
+
<property name="format" value="\n\n\Z"/>
|
27
|
+
<property name="message" value="Blank line before end of file"/>
|
28
|
+
</module>
|
29
|
+
|
30
|
+
<module name="TreeWalker">
|
31
|
+
<module name="EmptyBlock">
|
32
|
+
<property name="option" value="text"/>
|
33
|
+
<property name="tokens" value="
|
34
|
+
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
|
35
|
+
LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, INSTANCE_INIT, STATIC_INIT"/>
|
36
|
+
</module>
|
37
|
+
<module name="EmptyStatement"/>
|
38
|
+
<module name="EmptyForInitializerPad"/>
|
39
|
+
<module name="EmptyForIteratorPad">
|
40
|
+
<property name="option" value="space"/>
|
41
|
+
</module>
|
42
|
+
<module name="MethodParamPad">
|
43
|
+
<property name="allowLineBreaks" value="true"/>
|
44
|
+
<property name="option" value="nospace"/>
|
45
|
+
</module>
|
46
|
+
<module name="ParenPad"/>
|
47
|
+
<module name="TypecastParenPad"/>
|
48
|
+
<module name="NeedBraces"/>
|
49
|
+
<module name="LeftCurly">
|
50
|
+
<property name="option" value="nl"/>
|
51
|
+
<property name="tokens" value="CLASS_DEF, CTOR_DEF, INTERFACE_DEF, METHOD_DEF"/>
|
52
|
+
</module>
|
53
|
+
<module name="LeftCurly">
|
54
|
+
<property name="option" value="eol"/>
|
55
|
+
<property name="tokens" value="
|
56
|
+
LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR,
|
57
|
+
LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE"/>
|
58
|
+
</module>
|
59
|
+
<module name="RightCurly">
|
60
|
+
<property name="option" value="alone"/>
|
61
|
+
</module>
|
62
|
+
<module name="GenericWhitespace"/>
|
63
|
+
<module name="WhitespaceAfter"/>
|
64
|
+
<module name="NoWhitespaceBefore"/>
|
65
|
+
|
66
|
+
<module name="UpperEll"/>
|
67
|
+
<module name="DefaultComesLast"/>
|
68
|
+
<module name="ArrayTypeStyle"/>
|
69
|
+
<module name="MultipleVariableDeclarations"/>
|
70
|
+
<module name="ModifierOrder"/>
|
71
|
+
<module name="OneStatementPerLine"/>
|
72
|
+
<module name="StringLiteralEquality"/>
|
73
|
+
<module name="MutableException"/>
|
74
|
+
<module name="EqualsHashCode"/>
|
75
|
+
<module name="InnerAssignment"/>
|
76
|
+
<module name="InterfaceIsType"/>
|
77
|
+
<module name="HideUtilityClassConstructor"/>
|
78
|
+
|
79
|
+
<module name="MemberName"/>
|
80
|
+
<module name="LocalVariableName"/>
|
81
|
+
<module name="LocalFinalVariableName"/>
|
82
|
+
<module name="TypeName"/>
|
83
|
+
<module name="PackageName"/>
|
84
|
+
<module name="ParameterName"/>
|
85
|
+
<module name="StaticVariableName"/>
|
86
|
+
<module name="ClassTypeParameterName">
|
87
|
+
<property name="format" value="^[A-Z][0-9]?$"/>
|
88
|
+
</module>
|
89
|
+
<module name="MethodTypeParameterName">
|
90
|
+
<property name="format" value="^[A-Z][0-9]?$"/>
|
91
|
+
</module>
|
92
|
+
|
93
|
+
<module name="WhitespaceAround">
|
94
|
+
<property name="allowEmptyConstructors" value="true"/>
|
95
|
+
<property name="allowEmptyMethods" value="true"/>
|
96
|
+
<property name="ignoreEnhancedForColon" value="false"/>
|
97
|
+
<property name="tokens" value="
|
98
|
+
ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN,
|
99
|
+
BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE,
|
100
|
+
LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
101
|
+
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
102
|
+
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE,
|
103
|
+
LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL,
|
104
|
+
PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN,
|
105
|
+
STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
|
106
|
+
</module>
|
107
|
+
</module>
|
108
|
+
</module>
|
data/example/config.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
exec:
|
2
|
+
max_threads: 2
|
3
|
+
min_output_tasks: 1
|
4
|
+
in:
|
5
|
+
type: file
|
6
|
+
path_prefix: C:\Users\AnkitKumar\Desktop\embulk-filter-mysqllookup\calendar.csv
|
7
|
+
parser:
|
8
|
+
type: csv
|
9
|
+
columns:
|
10
|
+
- { name: dim_calendar_key, type: long }
|
11
|
+
- { name: year_number, type: long }
|
12
|
+
- { name: quarter_number, type: long }
|
13
|
+
- { name: attr_1, type: string }
|
14
|
+
filters:
|
15
|
+
- type: mysql_lookup
|
16
|
+
host: localhost
|
17
|
+
port: 3306
|
18
|
+
database: information
|
19
|
+
tablename: country
|
20
|
+
username: root
|
21
|
+
password: root
|
22
|
+
mapping_from:
|
23
|
+
- quarter_number
|
24
|
+
- attr_1
|
25
|
+
mapping_to:
|
26
|
+
- id
|
27
|
+
- country_code
|
28
|
+
new_columns:
|
29
|
+
- { name: country_address, type: string }
|
30
|
+
- { name: country_code,type: double}
|
31
|
+
out:
|
32
|
+
type: file
|
33
|
+
path_prefix: C:/Users/AnkitKumar/Desktop/embulk-files/sample/output.csv
|
34
|
+
file_ext: csv
|
35
|
+
formatter:
|
36
|
+
type: csv
|
37
|
+
delimiter: "\t"
|
38
|
+
newline: CRLF
|
39
|
+
newline_in_field: LF
|
40
|
+
charset: UTF-8
|
41
|
+
quote_policy: MINIMAL
|
42
|
+
quote: '"'
|
43
|
+
escape: "\\"
|
44
|
+
null_string: "\\N"
|
45
|
+
default_timezone: 'UTC'
|
Binary file
|
data/gradlew
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
#!/usr/bin/env sh
|
2
|
+
|
3
|
+
##############################################################################
|
4
|
+
##
|
5
|
+
## Gradle start up script for UN*X
|
6
|
+
##
|
7
|
+
##############################################################################
|
8
|
+
|
9
|
+
# Attempt to set APP_HOME
|
10
|
+
# Resolve links: $0 may be a link
|
11
|
+
PRG="$0"
|
12
|
+
# Need this for relative symlinks.
|
13
|
+
while [ -h "$PRG" ] ; do
|
14
|
+
ls=`ls -ld "$PRG"`
|
15
|
+
link=`expr "$ls" : '.*-> \(.*\)$'`
|
16
|
+
if expr "$link" : '/.*' > /dev/null; then
|
17
|
+
PRG="$link"
|
18
|
+
else
|
19
|
+
PRG=`dirname "$PRG"`"/$link"
|
20
|
+
fi
|
21
|
+
done
|
22
|
+
SAVED="`pwd`"
|
23
|
+
cd "`dirname \"$PRG\"`/" >/dev/null
|
24
|
+
APP_HOME="`pwd -P`"
|
25
|
+
cd "$SAVED" >/dev/null
|
26
|
+
|
27
|
+
APP_NAME="Gradle"
|
28
|
+
APP_BASE_NAME=`basename "$0"`
|
29
|
+
|
30
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
31
|
+
DEFAULT_JVM_OPTS=""
|
32
|
+
|
33
|
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
34
|
+
MAX_FD="maximum"
|
35
|
+
|
36
|
+
warn () {
|
37
|
+
echo "$*"
|
38
|
+
}
|
39
|
+
|
40
|
+
die () {
|
41
|
+
echo
|
42
|
+
echo "$*"
|
43
|
+
echo
|
44
|
+
exit 1
|
45
|
+
}
|
46
|
+
|
47
|
+
# OS specific support (must be 'true' or 'false').
|
48
|
+
cygwin=false
|
49
|
+
msys=false
|
50
|
+
darwin=false
|
51
|
+
nonstop=false
|
52
|
+
case "`uname`" in
|
53
|
+
CYGWIN* )
|
54
|
+
cygwin=true
|
55
|
+
;;
|
56
|
+
Darwin* )
|
57
|
+
darwin=true
|
58
|
+
;;
|
59
|
+
MINGW* )
|
60
|
+
msys=true
|
61
|
+
;;
|
62
|
+
NONSTOP* )
|
63
|
+
nonstop=true
|
64
|
+
;;
|
65
|
+
esac
|
66
|
+
|
67
|
+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
68
|
+
|
69
|
+
# Determine the Java command to use to start the JVM.
|
70
|
+
if [ -n "$JAVA_HOME" ] ; then
|
71
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
72
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
73
|
+
JAVACMD="$JAVA_HOME/jre/sh/java"
|
74
|
+
else
|
75
|
+
JAVACMD="$JAVA_HOME/bin/java"
|
76
|
+
fi
|
77
|
+
if [ ! -x "$JAVACMD" ] ; then
|
78
|
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
79
|
+
|
80
|
+
Please set the JAVA_HOME variable in your environment to match the
|
81
|
+
location of your Java installation."
|
82
|
+
fi
|
83
|
+
else
|
84
|
+
JAVACMD="java"
|
85
|
+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
86
|
+
|
87
|
+
Please set the JAVA_HOME variable in your environment to match the
|
88
|
+
location of your Java installation."
|
89
|
+
fi
|
90
|
+
|
91
|
+
# Increase the maximum file descriptors if we can.
|
92
|
+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
93
|
+
MAX_FD_LIMIT=`ulimit -H -n`
|
94
|
+
if [ $? -eq 0 ] ; then
|
95
|
+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
96
|
+
MAX_FD="$MAX_FD_LIMIT"
|
97
|
+
fi
|
98
|
+
ulimit -n $MAX_FD
|
99
|
+
if [ $? -ne 0 ] ; then
|
100
|
+
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
101
|
+
fi
|
102
|
+
else
|
103
|
+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
104
|
+
fi
|
105
|
+
fi
|
106
|
+
|
107
|
+
# For Darwin, add options to specify how the application appears in the dock
|
108
|
+
if $darwin; then
|
109
|
+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
110
|
+
fi
|
111
|
+
|
112
|
+
# For Cygwin, switch paths to Windows format before running java
|
113
|
+
if $cygwin ; then
|
114
|
+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
115
|
+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
116
|
+
JAVACMD=`cygpath --unix "$JAVACMD"`
|
117
|
+
|
118
|
+
# We build the pattern for arguments to be converted via cygpath
|
119
|
+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
120
|
+
SEP=""
|
121
|
+
for dir in $ROOTDIRSRAW ; do
|
122
|
+
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
123
|
+
SEP="|"
|
124
|
+
done
|
125
|
+
OURCYGPATTERN="(^($ROOTDIRS))"
|
126
|
+
# Add a user-defined pattern to the cygpath arguments
|
127
|
+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
128
|
+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
129
|
+
fi
|
130
|
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
131
|
+
i=0
|
132
|
+
for arg in "$@" ; do
|
133
|
+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
134
|
+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
135
|
+
|
136
|
+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
137
|
+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
138
|
+
else
|
139
|
+
eval `echo args$i`="\"$arg\""
|
140
|
+
fi
|
141
|
+
i=$((i+1))
|
142
|
+
done
|
143
|
+
case $i in
|
144
|
+
(0) set -- ;;
|
145
|
+
(1) set -- "$args0" ;;
|
146
|
+
(2) set -- "$args0" "$args1" ;;
|
147
|
+
(3) set -- "$args0" "$args1" "$args2" ;;
|
148
|
+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
149
|
+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
150
|
+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
151
|
+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
152
|
+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
153
|
+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
154
|
+
esac
|
155
|
+
fi
|
156
|
+
|
157
|
+
# Escape application args
|
158
|
+
save () {
|
159
|
+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
160
|
+
echo " "
|
161
|
+
}
|
162
|
+
APP_ARGS=$(save "$@")
|
163
|
+
|
164
|
+
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
165
|
+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
166
|
+
|
167
|
+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
168
|
+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
169
|
+
cd "$(dirname "$0")"
|
170
|
+
fi
|
171
|
+
|
172
|
+
exec "$JAVACMD" "$@"
|
data/gradlew.bat
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
@if "%DEBUG%" == "" @echo off
|
2
|
+
@rem ##########################################################################
|
3
|
+
@rem
|
4
|
+
@rem Gradle startup script for Windows
|
5
|
+
@rem
|
6
|
+
@rem ##########################################################################
|
7
|
+
|
8
|
+
@rem Set local scope for the variables with windows NT shell
|
9
|
+
if "%OS%"=="Windows_NT" setlocal
|
10
|
+
|
11
|
+
set DIRNAME=%~dp0
|
12
|
+
if "%DIRNAME%" == "" set DIRNAME=.
|
13
|
+
set APP_BASE_NAME=%~n0
|
14
|
+
set APP_HOME=%DIRNAME%
|
15
|
+
|
16
|
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
17
|
+
set DEFAULT_JVM_OPTS=
|
18
|
+
|
19
|
+
@rem Find java.exe
|
20
|
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
21
|
+
|
22
|
+
set JAVA_EXE=java.exe
|
23
|
+
%JAVA_EXE% -version >NUL 2>&1
|
24
|
+
if "%ERRORLEVEL%" == "0" goto init
|
25
|
+
|
26
|
+
echo.
|
27
|
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
28
|
+
echo.
|
29
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
30
|
+
echo location of your Java installation.
|
31
|
+
|
32
|
+
goto fail
|
33
|
+
|
34
|
+
:findJavaFromJavaHome
|
35
|
+
set JAVA_HOME=%JAVA_HOME:"=%
|
36
|
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
37
|
+
|
38
|
+
if exist "%JAVA_EXE%" goto init
|
39
|
+
|
40
|
+
echo.
|
41
|
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
42
|
+
echo.
|
43
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
44
|
+
echo location of your Java installation.
|
45
|
+
|
46
|
+
goto fail
|
47
|
+
|
48
|
+
:init
|
49
|
+
@rem Get command-line arguments, handling Windows variants
|
50
|
+
|
51
|
+
if not "%OS%" == "Windows_NT" goto win9xME_args
|
52
|
+
|
53
|
+
:win9xME_args
|
54
|
+
@rem Slurp the command line arguments.
|
55
|
+
set CMD_LINE_ARGS=
|
56
|
+
set _SKIP=2
|
57
|
+
|
58
|
+
:win9xME_args_slurp
|
59
|
+
if "x%~1" == "x" goto execute
|
60
|
+
|
61
|
+
set CMD_LINE_ARGS=%*
|
62
|
+
|
63
|
+
:execute
|
64
|
+
@rem Setup the command line
|
65
|
+
|
66
|
+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
67
|
+
|
68
|
+
@rem Execute Gradle
|
69
|
+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
70
|
+
|
71
|
+
:end
|
72
|
+
@rem End local scope for the variables with windows NT shell
|
73
|
+
if "%ERRORLEVEL%"=="0" goto mainEnd
|
74
|
+
|
75
|
+
:fail
|
76
|
+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
77
|
+
rem the _cmd.exe /c_ return code!
|
78
|
+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
79
|
+
exit /b 1
|
80
|
+
|
81
|
+
:mainEnd
|
82
|
+
if "%OS%"=="Windows_NT" endlocal
|
83
|
+
|
84
|
+
:omega
|
@@ -0,0 +1,38 @@
|
|
1
|
+
package org.embulk.filter.mysql_lookup;
|
2
|
+
|
3
|
+
import java.sql.Connection;
|
4
|
+
import java.sql.DriverManager;
|
5
|
+
|
6
|
+
public class DatabaseConnection {
|
7
|
+
private static Connection connection=null;
|
8
|
+
|
9
|
+
private DatabaseConnection(MysqlLookupFilterPlugin.PluginTask task) throws Exception {
|
10
|
+
try{
|
11
|
+
Class.forName("com.mysql.cj.jdbc.Driver");
|
12
|
+
String url = "jdbc:mysql://" + task.getHost() + ":"+task.getPort()+"/"+task.getDatabase();
|
13
|
+
connection= DriverManager.getConnection(url, task.getUserName(), task.getPassword());
|
14
|
+
}catch (Exception e){
|
15
|
+
e.printStackTrace();
|
16
|
+
throw new Exception(e);
|
17
|
+
}
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
public static Connection getConnection(MysqlLookupFilterPlugin.PluginTask task){
|
22
|
+
try {
|
23
|
+
if(connection==null || connection.isClosed()){
|
24
|
+
try {
|
25
|
+
new DatabaseConnection(task);
|
26
|
+
return connection;
|
27
|
+
} catch (Exception e) {
|
28
|
+
e.printStackTrace();
|
29
|
+
throw new RuntimeException();
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}catch (Exception e){
|
33
|
+
throw new RuntimeException(e);
|
34
|
+
}
|
35
|
+
|
36
|
+
return connection;
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,360 @@
|
|
1
|
+
package org.embulk.filter.mysql_lookup;
|
2
|
+
import com.google.common.collect.ImmutableList;
|
3
|
+
import org.embulk.config.Config;
|
4
|
+
import org.embulk.config.ConfigSource;
|
5
|
+
import org.embulk.config.Task;
|
6
|
+
import org.embulk.config.TaskSource;
|
7
|
+
import org.embulk.spi.*;
|
8
|
+
import org.embulk.spi.time.Timestamp;
|
9
|
+
import org.embulk.spi.type.Types;
|
10
|
+
import java.sql.Connection;
|
11
|
+
import java.sql.ResultSet;
|
12
|
+
import java.sql.SQLException;
|
13
|
+
import java.sql.Statement;
|
14
|
+
import java.time.Instant;
|
15
|
+
import java.util.ArrayList;
|
16
|
+
import java.util.HashMap;
|
17
|
+
import java.util.List;
|
18
|
+
import java.util.Map;
|
19
|
+
|
20
|
+
public class MysqlLookupFilterPlugin
|
21
|
+
implements FilterPlugin {
|
22
|
+
public interface PluginTask
|
23
|
+
extends Task {
|
24
|
+
@Config("host")
|
25
|
+
public String getHost();
|
26
|
+
|
27
|
+
@Config("port")
|
28
|
+
public String getPort();
|
29
|
+
|
30
|
+
@Config("database")
|
31
|
+
public String getDatabase();
|
32
|
+
|
33
|
+
@Config("tablename")
|
34
|
+
public String getTableName();
|
35
|
+
|
36
|
+
@Config("username")
|
37
|
+
public String getUserName();
|
38
|
+
|
39
|
+
@Config("password")
|
40
|
+
public String getPassword();
|
41
|
+
|
42
|
+
@Config("mapping_from")
|
43
|
+
public List<String> getMappingFrom();
|
44
|
+
|
45
|
+
@Config("mapping_to")
|
46
|
+
public List<String> getMappingTo();
|
47
|
+
|
48
|
+
@Config("new_columns")
|
49
|
+
public SchemaConfig getNewColumns();
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
@Override
|
54
|
+
public void transaction(ConfigSource config, Schema inputSchema,
|
55
|
+
FilterPlugin.Control control) {
|
56
|
+
PluginTask task = config.loadConfig(PluginTask.class);
|
57
|
+
|
58
|
+
List<String> inputColumns = task.getMappingFrom();
|
59
|
+
List<String> keyColumns = task.getMappingTo();
|
60
|
+
if (inputColumns.size() != keyColumns.size()) {
|
61
|
+
throw new RuntimeException("Number of mapping_from columns must be exactly equals to number of mapping_to columns");
|
62
|
+
}
|
63
|
+
|
64
|
+
Schema outputSchema = inputSchema;
|
65
|
+
|
66
|
+
ImmutableList.Builder<Column> builder = ImmutableList.builder();
|
67
|
+
int i = 0;
|
68
|
+
for (Column inputColumn : inputSchema.getColumns()) {
|
69
|
+
Column outputColumn = new Column(i++, inputColumn.getName(), inputColumn.getType());
|
70
|
+
builder.add(outputColumn);
|
71
|
+
}
|
72
|
+
|
73
|
+
for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
|
74
|
+
builder.add(columnConfig.toColumn(i++));
|
75
|
+
}
|
76
|
+
outputSchema = new Schema(builder.build());
|
77
|
+
|
78
|
+
control.run(task.dump(), outputSchema);
|
79
|
+
}
|
80
|
+
|
81
|
+
@Override
|
82
|
+
public PageOutput open(TaskSource taskSource, Schema inputSchema,
|
83
|
+
Schema outputSchema, PageOutput output) {
|
84
|
+
PluginTask task = taskSource.loadTask(PluginTask.class);
|
85
|
+
Map<String, List<String>> map = new HashMap<>();
|
86
|
+
try {
|
87
|
+
map = getKeyValueMap(task);
|
88
|
+
} catch (SQLException e) {
|
89
|
+
e.printStackTrace();
|
90
|
+
}
|
91
|
+
PageReader pageReader = new PageReader(inputSchema);
|
92
|
+
return new MyOutput(pageReader, inputSchema, outputSchema, output, task, map);
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
private Map<String, List<String>> getKeyValueMap(PluginTask task) throws SQLException {
|
97
|
+
Map<String, List<String>> map = new HashMap<>();
|
98
|
+
Connection con = DatabaseConnection.getConnection(task);
|
99
|
+
try {
|
100
|
+
|
101
|
+
List<String> targetColumns = task.getMappingTo();
|
102
|
+
List<String> newColumns = new ArrayList<>();
|
103
|
+
|
104
|
+
for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
|
105
|
+
newColumns.add(columnConfig.getName());
|
106
|
+
}
|
107
|
+
|
108
|
+
String query = "select ";
|
109
|
+
String columnNeedsToBeFetched = "";
|
110
|
+
for (int i = 0; i < targetColumns.size(); i++) {
|
111
|
+
columnNeedsToBeFetched += targetColumns.get(i) + ",";
|
112
|
+
}
|
113
|
+
for (int i = 0; i < newColumns.size(); i++) {
|
114
|
+
if (i != newColumns.size() - 1) {
|
115
|
+
columnNeedsToBeFetched += newColumns.get(i) + ",";
|
116
|
+
} else {
|
117
|
+
columnNeedsToBeFetched += newColumns.get(i);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
query += columnNeedsToBeFetched + " from " + task.getTableName();
|
121
|
+
|
122
|
+
Statement stmt = con.createStatement();
|
123
|
+
ResultSet rs = stmt.executeQuery(query);
|
124
|
+
|
125
|
+
while (rs.next()) {
|
126
|
+
|
127
|
+
//for key
|
128
|
+
String key = "";
|
129
|
+
String comp = "";
|
130
|
+
for (int i = 0; i < targetColumns.size(); i++) {
|
131
|
+
comp = "" + rs.getString(targetColumns.get(i));
|
132
|
+
if (comp.equalsIgnoreCase("null")) {
|
133
|
+
key += "";
|
134
|
+
} else {
|
135
|
+
key += rs.getString(targetColumns.get(i));
|
136
|
+
}
|
137
|
+
if (i != targetColumns.size() - 1) {
|
138
|
+
key += ",";
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
//for values
|
143
|
+
List<String> keyArray = new ArrayList<>();
|
144
|
+
for (int i = 0; i < newColumns.size(); i++) {
|
145
|
+
comp = "" + rs.getString(newColumns.get(i));
|
146
|
+
if (comp.equalsIgnoreCase("null")) {
|
147
|
+
keyArray.add("");
|
148
|
+
} else {
|
149
|
+
keyArray.add(rs.getString(newColumns.get(i)));
|
150
|
+
}
|
151
|
+
}
|
152
|
+
map.put(key, keyArray);
|
153
|
+
|
154
|
+
}
|
155
|
+
} catch (Exception e) {
|
156
|
+
e.printStackTrace();
|
157
|
+
} finally {
|
158
|
+
con.close();
|
159
|
+
}
|
160
|
+
return map;
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
public static class MyOutput implements PageOutput {
|
165
|
+
private PageReader reader;
|
166
|
+
private PageBuilder builder;
|
167
|
+
private PluginTask task;
|
168
|
+
private Schema inputSchema;
|
169
|
+
private Map<String, List<String>> keyValuePair;
|
170
|
+
|
171
|
+
public MyOutput(PageReader pageReader, Schema inputSchema, Schema outputSchema, PageOutput pageOutput, PluginTask task, Map<String, List<String>> keyValuePair) {
|
172
|
+
this.reader = pageReader;
|
173
|
+
this.builder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, pageOutput);
|
174
|
+
this.task = task;
|
175
|
+
this.inputSchema = inputSchema;
|
176
|
+
this.keyValuePair = keyValuePair;
|
177
|
+
}
|
178
|
+
|
179
|
+
@Override
|
180
|
+
public void add(Page page) {
|
181
|
+
reader.setPage(page);
|
182
|
+
List<ColumnConfig> columnConfigList = new ArrayList<>();
|
183
|
+
for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
|
184
|
+
columnConfigList.add(columnConfig);
|
185
|
+
}
|
186
|
+
|
187
|
+
while (reader.nextRecord()) {
|
188
|
+
|
189
|
+
int colNum = 0;
|
190
|
+
List<String> inputColumns = task.getMappingFrom();
|
191
|
+
List<String> searchingKeyData = new ArrayList<>();
|
192
|
+
Map<String, Integer> keyMap = new HashMap<>();
|
193
|
+
keyMap.put("Key", 0);
|
194
|
+
|
195
|
+
for (Column column : inputSchema.getColumns()) {
|
196
|
+
if (reader.isNull(column)) {
|
197
|
+
if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
|
198
|
+
searchingKeyData.add("");
|
199
|
+
int key = keyMap.get("Key");
|
200
|
+
keyMap.put("Key", ++key);
|
201
|
+
}
|
202
|
+
builder.setNull(colNum++);
|
203
|
+
} else {
|
204
|
+
add_builder(colNum++, column, searchingKeyData, inputColumns, keyMap);
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
String key = "";
|
209
|
+
for (int k = 0; k < searchingKeyData.size(); k++) {
|
210
|
+
key += searchingKeyData.get(k);
|
211
|
+
if (k != searchingKeyData.size() - 1) {
|
212
|
+
key += ",";
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
List<String> matchedData = new ArrayList<>();
|
217
|
+
if (keyValuePair.containsKey(key)) {
|
218
|
+
matchedData = keyValuePair.get(key);
|
219
|
+
}
|
220
|
+
|
221
|
+
if (matchedData.size() == 0) {
|
222
|
+
for (int k = 0; k < columnConfigList.size(); k++) {
|
223
|
+
add_builder_for_new_column(colNum, columnConfigList.get(k).getType().getName(), "", false);
|
224
|
+
colNum++;
|
225
|
+
}
|
226
|
+
} else {
|
227
|
+
for (int k = 0; k < columnConfigList.size(); k++) {
|
228
|
+
add_builder_for_new_column(colNum, columnConfigList.get(k).getType().getName(), matchedData.get(k), true);
|
229
|
+
colNum++;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
builder.addRecord();
|
233
|
+
}
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
@Override
|
239
|
+
public void finish() {
|
240
|
+
builder.finish();
|
241
|
+
}
|
242
|
+
|
243
|
+
@Override
|
244
|
+
public void close() {
|
245
|
+
builder.close();
|
246
|
+
}
|
247
|
+
|
248
|
+
private void add_builder(int colNum, Column column, List<String> searchingKeyData, List<String> inputColumns, Map<String, Integer> keyMap) {
|
249
|
+
if (Types.STRING.equals(column.getType())) {
|
250
|
+
if (keyMap.get("Key") < inputColumns.size()) {
|
251
|
+
if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
|
252
|
+
searchingKeyData.add(reader.getString(column));
|
253
|
+
int key = keyMap.get("Key");
|
254
|
+
keyMap.put("Key", ++key);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
builder.setString(colNum, reader.getString(column));
|
258
|
+
} else if (Types.BOOLEAN.equals(column.getType())) {
|
259
|
+
if (keyMap.get("Key") < inputColumns.size()) {
|
260
|
+
if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
|
261
|
+
searchingKeyData.add(String.valueOf(reader.getBoolean(column)));
|
262
|
+
int key = keyMap.get("Key");
|
263
|
+
keyMap.put("Key", ++key);
|
264
|
+
}
|
265
|
+
}
|
266
|
+
builder.setBoolean(colNum, reader.getBoolean(column));
|
267
|
+
} else if (Types.DOUBLE.equals(column.getType())) {
|
268
|
+
if (keyMap.get("Key") < inputColumns.size()) {
|
269
|
+
if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
|
270
|
+
searchingKeyData.add(String.valueOf(reader.getDouble(column)));
|
271
|
+
int key = keyMap.get("Key");
|
272
|
+
keyMap.put("Key", ++key);
|
273
|
+
}
|
274
|
+
}
|
275
|
+
builder.setDouble(colNum, reader.getDouble(column));
|
276
|
+
} else if (Types.LONG.equals(column.getType())) {
|
277
|
+
if (keyMap.get("Key") < inputColumns.size()) {
|
278
|
+
if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
|
279
|
+
searchingKeyData.add(String.valueOf(reader.getLong(column)));
|
280
|
+
int key = keyMap.get("Key");
|
281
|
+
keyMap.put("Key", ++key);
|
282
|
+
}
|
283
|
+
}
|
284
|
+
|
285
|
+
builder.setLong(colNum, reader.getLong(column));
|
286
|
+
} else if (Types.TIMESTAMP.equals(column.getType())) {
|
287
|
+
if (keyMap.get("Key") < inputColumns.size()) {
|
288
|
+
if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
|
289
|
+
searchingKeyData.add(String.valueOf(reader.getTimestamp(column)));
|
290
|
+
int key = keyMap.get("Key");
|
291
|
+
keyMap.put("Key", ++key);
|
292
|
+
}
|
293
|
+
}
|
294
|
+
builder.setTimestamp(colNum, reader.getTimestamp(column));
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
private void add_builder_for_new_column(int colNum, String newlyAddedColumnType, String matchedData, Boolean isDataMatched) {
|
299
|
+
try {
|
300
|
+
if (newlyAddedColumnType.equalsIgnoreCase("string")) {
|
301
|
+
if (isDataMatched) {
|
302
|
+
builder.setString(colNum, matchedData);
|
303
|
+
} else {
|
304
|
+
builder.setString(colNum, "");
|
305
|
+
}
|
306
|
+
|
307
|
+
} else if (newlyAddedColumnType.equalsIgnoreCase("long")) {
|
308
|
+
if (isDataMatched) {
|
309
|
+
if (matchedData.length() == 0) {
|
310
|
+
builder.setLong(colNum, 0);
|
311
|
+
} else {
|
312
|
+
builder.setLong(colNum, Long.parseLong(matchedData));
|
313
|
+
}
|
314
|
+
} else {
|
315
|
+
builder.setLong(colNum, 0);
|
316
|
+
}
|
317
|
+
|
318
|
+
} else if (newlyAddedColumnType.equalsIgnoreCase("double")) {
|
319
|
+
if (isDataMatched) {
|
320
|
+
if (matchedData.length() == 0) {
|
321
|
+
builder.setDouble(colNum, 0.0);
|
322
|
+
} else {
|
323
|
+
builder.setDouble(colNum, Double.parseDouble(matchedData));
|
324
|
+
}
|
325
|
+
} else {
|
326
|
+
builder.setDouble(colNum, 0.0);
|
327
|
+
}
|
328
|
+
} else if (newlyAddedColumnType.equalsIgnoreCase("boolean")) {
|
329
|
+
if (isDataMatched) {
|
330
|
+
if (matchedData.length() == 0) {
|
331
|
+
builder.setNull(colNum);
|
332
|
+
} else {
|
333
|
+
builder.setBoolean(colNum, Boolean.parseBoolean(matchedData));
|
334
|
+
}
|
335
|
+
} else {
|
336
|
+
builder.setNull(colNum);
|
337
|
+
}
|
338
|
+
} else if (newlyAddedColumnType.equalsIgnoreCase("timestamp")) {
|
339
|
+
if (isDataMatched) {
|
340
|
+
if (matchedData.length() == 0) {
|
341
|
+
builder.setNull(colNum);
|
342
|
+
} else {
|
343
|
+
java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf(matchedData);
|
344
|
+
Instant instant = timestamp.toInstant();
|
345
|
+
Timestamp spiTimeStamp = Timestamp.ofInstant(instant);
|
346
|
+
builder.setTimestamp(colNum, spiTimeStamp);
|
347
|
+
}
|
348
|
+
} else {
|
349
|
+
builder.setNull(colNum);
|
350
|
+
}
|
351
|
+
|
352
|
+
}
|
353
|
+
} catch (Exception e) {
|
354
|
+
e.printStackTrace();
|
355
|
+
throw new RuntimeException("Data type could not be cast due to wrong data or issue in typecasting timestamp", e);
|
356
|
+
}
|
357
|
+
|
358
|
+
}
|
359
|
+
}
|
360
|
+
}
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-filter-mysql_lookup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- InfoObjects Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
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
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
description: Mysql Lookup filter
|
42
|
+
email:
|
43
|
+
- utkarsh@infoobjects.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- build.gradle
|
52
|
+
- classpath/embulk-filter-mysql_lookup-0.1.1.jar
|
53
|
+
- classpath/mysql-connector-java-8.0.19.jar
|
54
|
+
- classpath/protobuf-java-3.6.1.jar
|
55
|
+
- config/checkstyle/checkstyle.xml
|
56
|
+
- config/checkstyle/default.xml
|
57
|
+
- example/config.yml
|
58
|
+
- gradle/wrapper/gradle-wrapper.jar
|
59
|
+
- gradle/wrapper/gradle-wrapper.properties
|
60
|
+
- gradlew
|
61
|
+
- gradlew.bat
|
62
|
+
- lib/embulk/filter/mysql_lookup.rb
|
63
|
+
- src/main/java/org/embulk/filter/mysql_lookup/DatabaseConnection.java
|
64
|
+
- src/main/java/org/embulk/filter/mysql_lookup/MysqlLookupFilterPlugin.java
|
65
|
+
- src/test/java/org/embulk/filter/mysql_lookup/TestMysqlLookupFilterPlugin.java
|
66
|
+
homepage: https://github.com/InfoObjects/embulk-filter-mysql_lookup
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.2.33
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: An Embulk filter plugin for Lookup Transformation with MySQL database
|
89
|
+
test_files: []
|