embulk-filter-json_key_joiner 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/.circleci/config.yml +27 -0
- data/.gitignore +80 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/build.gradle +83 -0
- data/build.sbt +31 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +169 -0
- data/gradlew.bat +84 -0
- data/lib/embulk/filter/json_key_joiner.rb +3 -0
- data/project/build.properties +1 -0
- data/project/plugins.sbt +2 -0
- data/settings.gradle +1 -0
- data/src/main/scala/org/embulk/filter/json_key_joiner/JsonKeyJoinerFilterPlugin.scala +25 -0
- data/src/main/scala/org/embulk/filter/json_key_joiner/PageOutput.scala +38 -0
- data/src/main/scala/org/embulk/filter/json_key_joiner/PluginTask.scala +14 -0
- data/src/main/scala/org/embulk/filter/json_key_joiner/json/JsonParser.scala +15 -0
- data/src/main/scala/org/embulk/filter/json_key_joiner/row/Row.scala +36 -0
- data/src/main/scala/org/embulk/filter/json_key_joiner/row/SetValueColumnVisitor.scala +59 -0
- data/src/main/scala/org/embulk/filter/json_key_joiner/row/ValueHolder.scala +5 -0
- data/src/test/scala/org/embulk/filter/json_key_joiner/json/JsonParserSpec.scala +21 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5ddccf892024f4e6d54e856c3e377f219b94375f
|
4
|
+
data.tar.gz: e907fedb29e6d693c40e4fc6a3c1d03475ea94df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d023b3e3a459eebe9f4ff6fe9cd7c3378d58620d35167e77df18f77296c7642a948095b497365ca36877dd4aa1c02fd7fb68e71cedbd80d316f06037a8da0df
|
7
|
+
data.tar.gz: ad5e45af531531d62ffb267b6f10891075ce4b062dbb39f241b0f4f72e0f61ae32cf2fc14228c84ca3747b61c90949a69d81c39c6c26fa64d9eee18d67d07c58
|
@@ -0,0 +1,27 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
executorType: docker
|
5
|
+
docker:
|
6
|
+
- image: hseeberger/scala-sbt
|
7
|
+
working_directory: /root/embulk-filter-json_key_joiner/
|
8
|
+
steps:
|
9
|
+
- checkout
|
10
|
+
- restore_cache:
|
11
|
+
name: Restoring Cache
|
12
|
+
keys:
|
13
|
+
- sbt
|
14
|
+
- setup_remote_docker
|
15
|
+
- run:
|
16
|
+
name: prepare
|
17
|
+
command: sbt update exit
|
18
|
+
- save_cache:
|
19
|
+
name: Saving Cache sbt
|
20
|
+
key: sbt
|
21
|
+
paths:
|
22
|
+
- "/root/.sbt"
|
23
|
+
- "/root/.ivy2"
|
24
|
+
- run:
|
25
|
+
name: compile
|
26
|
+
command: |
|
27
|
+
sbt compile test scalafmt::test exit
|
data/.gitignore
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
/pkg/
|
2
|
+
/tmp/
|
3
|
+
*.gemspec
|
4
|
+
.gradle/
|
5
|
+
/classpath/
|
6
|
+
build/
|
7
|
+
.idea
|
8
|
+
/.settings/
|
9
|
+
/.metadata/
|
10
|
+
.classpath
|
11
|
+
.project
|
12
|
+
|
13
|
+
.settings
|
14
|
+
.classpath
|
15
|
+
.project
|
16
|
+
*.iml
|
17
|
+
*.ipr
|
18
|
+
*.iws
|
19
|
+
dist/
|
20
|
+
lib_managed/
|
21
|
+
project/boot/
|
22
|
+
project/plugins/project/
|
23
|
+
target/
|
24
|
+
|
25
|
+
# use glob syntax.
|
26
|
+
syntax: glob
|
27
|
+
*.ser
|
28
|
+
*.class
|
29
|
+
*~
|
30
|
+
*.bak
|
31
|
+
#*.off
|
32
|
+
*.old
|
33
|
+
|
34
|
+
# eclipse conf file
|
35
|
+
.settings
|
36
|
+
.classpath
|
37
|
+
.project
|
38
|
+
.manager
|
39
|
+
.scala_dependencies
|
40
|
+
|
41
|
+
# idea
|
42
|
+
.idea
|
43
|
+
*.iml
|
44
|
+
|
45
|
+
# building
|
46
|
+
target
|
47
|
+
build
|
48
|
+
null
|
49
|
+
tmp*
|
50
|
+
temp*
|
51
|
+
!templates/
|
52
|
+
dist
|
53
|
+
test-output
|
54
|
+
build.log
|
55
|
+
|
56
|
+
# other scm
|
57
|
+
.svn
|
58
|
+
.CVS
|
59
|
+
.hg*
|
60
|
+
|
61
|
+
# switch to regexp syntax.
|
62
|
+
# syntax: regexp
|
63
|
+
# ^\.pc/
|
64
|
+
|
65
|
+
#SHITTY output not in target directory
|
66
|
+
build.log
|
67
|
+
.DS_Store
|
68
|
+
derby.log
|
69
|
+
|
70
|
+
*.db
|
71
|
+
|
72
|
+
.lib
|
73
|
+
sbt
|
74
|
+
|
75
|
+
logs
|
76
|
+
sandbox/db
|
77
|
+
|
78
|
+
|
79
|
+
.ensime*⏎
|
80
|
+
project/project/
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Json Key Joiner filter plugin for Embulk
|
2
|
+
|
3
|
+
Join to json default key-value to defined JSON Type column.
|
4
|
+
|
5
|
+
* **Plugin type**: filter
|
6
|
+
|
7
|
+
## Configuration
|
8
|
+
|
9
|
+
- **key_value**: joining key value (hash Map[String,String], required)
|
10
|
+
- **json_column_name**: processing json column (string, required)
|
11
|
+
|
12
|
+
## Example
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
|
16
|
+
filters:
|
17
|
+
- type: json_key_joiner
|
18
|
+
json_column_name: record // JSON Type Column
|
19
|
+
key_value:
|
20
|
+
append_key: append_value
|
21
|
+
```
|
22
|
+
|
23
|
+
- before json
|
24
|
+
```
|
25
|
+
{ "key1":"value1" }
|
26
|
+
```
|
27
|
+
|
28
|
+
- after json
|
29
|
+
```
|
30
|
+
{ "key1":"value1" , "append_key":"append_value" }
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
## Build
|
35
|
+
|
36
|
+
```
|
37
|
+
$ ./gradlew gem
|
38
|
+
```
|
data/build.gradle
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
plugins {
|
2
|
+
id "com.jfrog.bintray" version "1.1"
|
3
|
+
id "com.github.jruby-gradle.base" version "0.1.5"
|
4
|
+
id "java"
|
5
|
+
id "scala"
|
6
|
+
}
|
7
|
+
import com.github.jrubygradle.JRubyExec
|
8
|
+
repositories {
|
9
|
+
mavenCentral()
|
10
|
+
jcenter()
|
11
|
+
}
|
12
|
+
configurations {
|
13
|
+
provided
|
14
|
+
}
|
15
|
+
|
16
|
+
version = "0.1.0"
|
17
|
+
|
18
|
+
sourceCompatibility = 1.7
|
19
|
+
targetCompatibility = 1.7
|
20
|
+
|
21
|
+
dependencies {
|
22
|
+
compile "org.embulk:embulk-core:0.8.29"
|
23
|
+
compile "org.scala-lang:scala-library:2.11.11"
|
24
|
+
compile group: 'io.circe', name: 'circe-core_2.11', version: '0.8.0'
|
25
|
+
compile group: 'io.circe', name: 'circe-generic_2.11', version: '0.8.0'
|
26
|
+
compile group: 'io.circe', name: 'circe-parser_2.11', version: '0.8.0'
|
27
|
+
testCompile group: 'org.scalatest', name: 'scalatest_2.11', version: '3.0.1'
|
28
|
+
provided "org.embulk:embulk-core:0.8.29"
|
29
|
+
testCompile "junit:junit:4.+"
|
30
|
+
}
|
31
|
+
|
32
|
+
task classpath(type: Copy, dependsOn: ["jar"]) {
|
33
|
+
doFirst { file("classpath").deleteDir() }
|
34
|
+
from (configurations.runtime - configurations.provided + files(jar.archivePath))
|
35
|
+
into "classpath"
|
36
|
+
}
|
37
|
+
clean { delete "classpath" }
|
38
|
+
|
39
|
+
task gem(type: JRubyExec, dependsOn: ["gemspec", "classpath"]) {
|
40
|
+
jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "build"
|
41
|
+
script "${project.name}.gemspec"
|
42
|
+
doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
|
43
|
+
}
|
44
|
+
|
45
|
+
task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
|
46
|
+
jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "push"
|
47
|
+
script "pkg/${project.name}-${project.version}.gem"
|
48
|
+
}
|
49
|
+
|
50
|
+
task "package"(dependsOn: ["gemspec", "classpath"]) {
|
51
|
+
doLast {
|
52
|
+
println "> Build succeeded."
|
53
|
+
println "> You can run embulk with '-L ${file(".").absolutePath}' argument."
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
task gemspec {
|
58
|
+
ext.gemspecFile = file("${project.name}.gemspec")
|
59
|
+
inputs.file "build.gradle"
|
60
|
+
outputs.file gemspecFile
|
61
|
+
doLast { gemspecFile.write($/
|
62
|
+
Gem::Specification.new do |spec|
|
63
|
+
spec.name = "${project.name}"
|
64
|
+
spec.version = "${project.version}"
|
65
|
+
spec.authors = ["smdmts"]
|
66
|
+
spec.summary = %[Json Key Joiner filter plugin for Embulk]
|
67
|
+
spec.description = %[Json Key Joiner]
|
68
|
+
spec.email = ["smdmts@gmail.com"]
|
69
|
+
spec.licenses = ["MIT"]
|
70
|
+
spec.homepage = "https://github.com/smdmts/embulk-filter-json_key_joiner"
|
71
|
+
|
72
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
73
|
+
spec.test_files = spec.files.grep(%r"^(test|spec)/")
|
74
|
+
spec.require_paths = ["lib"]
|
75
|
+
|
76
|
+
#spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
|
77
|
+
spec.add_development_dependency 'bundler', ['~> 1.0']
|
78
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
79
|
+
end
|
80
|
+
/$)
|
81
|
+
}
|
82
|
+
}
|
83
|
+
clean { delete "${project.name}.gemspec" }
|
data/build.sbt
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
enablePlugins(ScalafmtPlugin)
|
2
|
+
|
3
|
+
lazy val root = (project in file(".")).settings(
|
4
|
+
inThisBuild(
|
5
|
+
List(
|
6
|
+
organization := "com.example",
|
7
|
+
scalaVersion := "2.11.11",
|
8
|
+
version := "0.1.0-SNAPSHOT"
|
9
|
+
)),
|
10
|
+
name := "embulk-key_to_redis",
|
11
|
+
scalafmtOnCompile in ThisBuild := true,
|
12
|
+
scalafmtTestOnCompile in ThisBuild := true
|
13
|
+
)
|
14
|
+
|
15
|
+
resolvers += Resolver.jcenterRepo
|
16
|
+
resolvers += Resolver.sonatypeRepo("releases")
|
17
|
+
resolvers += "velvia maven" at "http://dl.bintray.com/velvia/maven"
|
18
|
+
|
19
|
+
lazy val circeVersion = "0.8.0"
|
20
|
+
libraryDependencies ++= Seq(
|
21
|
+
"org.jruby" % "jruby-complete" % "1.6.5",
|
22
|
+
"org.embulk" % "embulk-core" % "0.8.29",
|
23
|
+
"com.github.etaty" %% "rediscala" % "1.7.0",
|
24
|
+
"io.circe" %% "circe-core" % circeVersion,
|
25
|
+
"io.circe" %% "circe-generic" % circeVersion,
|
26
|
+
"io.circe" %% "circe-parser" % circeVersion,
|
27
|
+
"org.scalacheck" %% "scalacheck" % "1.13.4" % Test,
|
28
|
+
"org.scalatest" %% "scalatest" % "3.0.1" % Test,
|
29
|
+
"org.scalamock" %% "scalamock-scalatest-support" % "3.6.0" % Test,
|
30
|
+
"com.github.alexarchambault" %% "scalacheck-shapeless_1.13" % "1.1.5" % Test
|
31
|
+
)
|
Binary file
|
data/gradlew
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
#!/usr/bin/env bash
|
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
|
+
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
158
|
+
function splitJvmOpts() {
|
159
|
+
JVM_OPTS=("$@")
|
160
|
+
}
|
161
|
+
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
162
|
+
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
163
|
+
|
164
|
+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
165
|
+
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
|
166
|
+
cd "$(dirname "$0")"
|
167
|
+
fi
|
168
|
+
|
169
|
+
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
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 @@
|
|
1
|
+
sbt.version=0.13.15
|
data/project/plugins.sbt
ADDED
data/settings.gradle
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rootProject.name = 'embulk-filter-json_key_joiner'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
package org.embulk.filter.json_key_joiner
|
2
|
+
|
3
|
+
import org.embulk.config.{ConfigSource, TaskSource}
|
4
|
+
import org.embulk.spi
|
5
|
+
import org.embulk.spi.{FilterPlugin, Schema}
|
6
|
+
|
7
|
+
class JsonKeyJoinerFilterPlugin extends FilterPlugin {
|
8
|
+
|
9
|
+
override def transaction(config: ConfigSource,
|
10
|
+
inputSchema: Schema,
|
11
|
+
control: FilterPlugin.Control): Unit = {
|
12
|
+
val task = config.loadConfig(classOf[PluginTask])
|
13
|
+
val taskSource = task.dump()
|
14
|
+
control.run(taskSource, inputSchema)
|
15
|
+
}
|
16
|
+
|
17
|
+
override def open(taskSource: TaskSource,
|
18
|
+
inputSchema: Schema,
|
19
|
+
outputSchema: Schema,
|
20
|
+
output: spi.PageOutput): PageOutput = {
|
21
|
+
val task = taskSource.loadTask(classOf[PluginTask])
|
22
|
+
PageOutput(task, outputSchema, output)
|
23
|
+
}
|
24
|
+
|
25
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
package org.embulk.filter.json_key_joiner
|
2
|
+
|
3
|
+
import org.embulk.filter.json_key_joiner.row.SetValueColumnVisitor
|
4
|
+
|
5
|
+
import scala.collection.JavaConverters._
|
6
|
+
import org.embulk.spi.{
|
7
|
+
Exec,
|
8
|
+
Page,
|
9
|
+
PageBuilder,
|
10
|
+
PageReader,
|
11
|
+
Schema,
|
12
|
+
PageOutput => EmbulkPageOutput
|
13
|
+
}
|
14
|
+
|
15
|
+
case class PageOutput(task: PluginTask,
|
16
|
+
schema: Schema,
|
17
|
+
output: EmbulkPageOutput)
|
18
|
+
extends EmbulkPageOutput {
|
19
|
+
val pageBuilder = new PageBuilder(Exec.getBufferAllocator, schema, output)
|
20
|
+
override def add(page: Page): Unit = {
|
21
|
+
val baseReader: PageReader = new PageReader(schema)
|
22
|
+
baseReader.setPage(page)
|
23
|
+
while (baseReader.nextRecord()) {
|
24
|
+
val visitor = SetValueColumnVisitor(
|
25
|
+
baseReader,
|
26
|
+
task.getJsonColumnName,
|
27
|
+
task.getKeyWithIndex.asScala.toMap
|
28
|
+
)
|
29
|
+
schema.visitColumns(visitor)
|
30
|
+
visitor.getRow(pageBuilder).addRecord()
|
31
|
+
}
|
32
|
+
baseReader.close()
|
33
|
+
}
|
34
|
+
|
35
|
+
override def finish(): Unit = pageBuilder.finish()
|
36
|
+
|
37
|
+
override def close(): Unit = pageBuilder.close()
|
38
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
package org.embulk.filter.json_key_joiner
|
2
|
+
|
3
|
+
import org.embulk.config.{Config, ConfigDefault, Task}
|
4
|
+
|
5
|
+
trait PluginTask extends Task {
|
6
|
+
|
7
|
+
@Config("key_value")
|
8
|
+
@ConfigDefault("{}")
|
9
|
+
def getKeyWithIndex: java.util.Map[String, String]
|
10
|
+
|
11
|
+
@Config("json_column_name")
|
12
|
+
def getJsonColumnName: String
|
13
|
+
|
14
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
package org.embulk.filter.json_key_joiner.json
|
2
|
+
|
3
|
+
import io.circe._
|
4
|
+
import io.circe.parser._
|
5
|
+
|
6
|
+
object JsonParser {
|
7
|
+
def apply(json: String, joiner: Map[String, String]): Json = {
|
8
|
+
decode[Map[String, Json]](json) match {
|
9
|
+
case Right(v: Map[String, Json]) =>
|
10
|
+
Json.fromFields(v ++ joiner.mapValues(Json.fromString))
|
11
|
+
case _ =>
|
12
|
+
sys.error(s"could not parse json. $json")
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
package org.embulk.filter.json_key_joiner.row
|
2
|
+
|
3
|
+
import org.embulk.spi.PageBuilder
|
4
|
+
import org.embulk.spi.`type`._
|
5
|
+
import org.embulk.spi.time.Timestamp
|
6
|
+
import org.msgpack.value.Value
|
7
|
+
|
8
|
+
import scala.collection.mutable
|
9
|
+
|
10
|
+
case class Row(seq: mutable.Set[ValueHolder[_]], pageBuilder: PageBuilder) {
|
11
|
+
def addRecord(): Unit = {
|
12
|
+
seq.foreach { vh =>
|
13
|
+
vh.value match {
|
14
|
+
case Some(v: Boolean) if vh.column.getType.isInstanceOf[BooleanType] =>
|
15
|
+
pageBuilder.setBoolean(vh.column, v)
|
16
|
+
case Some(v: Long) if vh.column.getType.isInstanceOf[LongType] =>
|
17
|
+
pageBuilder.setLong(vh.column, v)
|
18
|
+
case Some(v: Double) if vh.column.getType.isInstanceOf[DoubleType] =>
|
19
|
+
pageBuilder.setDouble(vh.column, v)
|
20
|
+
case Some(v: String) if vh.column.getType.isInstanceOf[StringType] =>
|
21
|
+
pageBuilder.setString(vh.column, v)
|
22
|
+
case Some(v: Timestamp)
|
23
|
+
if vh.column.getType.isInstanceOf[TimestampType] =>
|
24
|
+
pageBuilder.setTimestamp(vh.column, v)
|
25
|
+
case Some(v: Value) if vh.column.getType.isInstanceOf[JsonType] =>
|
26
|
+
pageBuilder.setJson(vh.column, v)
|
27
|
+
case None =>
|
28
|
+
pageBuilder.setNull(vh.column)
|
29
|
+
case _ =>
|
30
|
+
sys.error("unmatched types.")
|
31
|
+
}
|
32
|
+
}
|
33
|
+
pageBuilder.addRecord()
|
34
|
+
}
|
35
|
+
|
36
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
package org.embulk.filter.json_key_joiner.row
|
2
|
+
|
3
|
+
import org.embulk.spi.{
|
4
|
+
Column,
|
5
|
+
PageBuilder,
|
6
|
+
PageReader,
|
7
|
+
ColumnVisitor => EmbulkColumnVisitor
|
8
|
+
}
|
9
|
+
import org.embulk.filter.json_key_joiner.json.JsonParser
|
10
|
+
|
11
|
+
case class SetValueColumnVisitor(reader: PageReader,
|
12
|
+
columnName: String,
|
13
|
+
joiner: Map[String, String])
|
14
|
+
extends EmbulkColumnVisitor {
|
15
|
+
import scala.collection.mutable
|
16
|
+
private val valueHolderSet = mutable.Set[ValueHolder[_]]()
|
17
|
+
|
18
|
+
val spiParser = new org.embulk.spi.json.JsonParser()
|
19
|
+
|
20
|
+
override def timestampColumn(column: Column): Unit =
|
21
|
+
value(column, reader.getTimestamp)
|
22
|
+
|
23
|
+
override def stringColumn(column: Column): Unit =
|
24
|
+
value(column, reader.getString)
|
25
|
+
|
26
|
+
override def longColumn(column: Column): Unit =
|
27
|
+
value(column, reader.getLong)
|
28
|
+
|
29
|
+
override def doubleColumn(column: Column): Unit =
|
30
|
+
value(column, reader.getDouble)
|
31
|
+
|
32
|
+
override def booleanColumn(column: Column): Unit =
|
33
|
+
value(column, reader.getBoolean)
|
34
|
+
|
35
|
+
val jsonParser = new org.embulk.spi.json.JsonParser()
|
36
|
+
override def jsonColumn(column: Column): Unit = {
|
37
|
+
if (column.getName == columnName) {
|
38
|
+
val json = JsonParser(reader.getJson(column).toJson, joiner)
|
39
|
+
valueHolderSet.add(
|
40
|
+
ValueHolder(column, Some(jsonParser.parse(json.noSpaces))))
|
41
|
+
} else {
|
42
|
+
value(column, reader.getJson)
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
def value[A](column: Column, method: => (Column => A)): Option[A] = {
|
47
|
+
val result = if (reader.isNull(column)) {
|
48
|
+
None
|
49
|
+
} else {
|
50
|
+
Some(method(column))
|
51
|
+
}
|
52
|
+
valueHolderSet.add(ValueHolder(column, result))
|
53
|
+
result
|
54
|
+
}
|
55
|
+
|
56
|
+
def getRow(pageBuilder: PageBuilder): Row =
|
57
|
+
Row(valueHolderSet, pageBuilder)
|
58
|
+
|
59
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
package org.embulk.filter.json_key_joiner.json
|
2
|
+
|
3
|
+
import org.scalatest.Matchers
|
4
|
+
|
5
|
+
class JsonParserSpec extends org.scalatest.FlatSpec with Matchers {
|
6
|
+
|
7
|
+
it should "be parse" in {
|
8
|
+
val appender = Map("abc" -> "efg")
|
9
|
+
val before = """
|
10
|
+
|{
|
11
|
+
| "name" : "John",
|
12
|
+
| "age" : 50
|
13
|
+
|}
|
14
|
+
""".stripMargin
|
15
|
+
val after = JsonParser(before, appender).noSpaces
|
16
|
+
|
17
|
+
after shouldBe """{"name":"John","age":50,"abc":"efg"}"""
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
}
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-filter-json_key_joiner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- smdmts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-31 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: Json Key Joiner
|
42
|
+
email:
|
43
|
+
- smdmts@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .circleci/config.yml
|
49
|
+
- .gitignore
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- build.gradle
|
53
|
+
- build.sbt
|
54
|
+
- gradle/wrapper/gradle-wrapper.jar
|
55
|
+
- gradle/wrapper/gradle-wrapper.properties
|
56
|
+
- gradlew
|
57
|
+
- gradlew.bat
|
58
|
+
- lib/embulk/filter/json_key_joiner.rb
|
59
|
+
- project/build.properties
|
60
|
+
- project/plugins.sbt
|
61
|
+
- settings.gradle
|
62
|
+
- src/main/scala/org/embulk/filter/json_key_joiner/JsonKeyJoinerFilterPlugin.scala
|
63
|
+
- src/main/scala/org/embulk/filter/json_key_joiner/PageOutput.scala
|
64
|
+
- src/main/scala/org/embulk/filter/json_key_joiner/PluginTask.scala
|
65
|
+
- src/main/scala/org/embulk/filter/json_key_joiner/json/JsonParser.scala
|
66
|
+
- src/main/scala/org/embulk/filter/json_key_joiner/row/Row.scala
|
67
|
+
- src/main/scala/org/embulk/filter/json_key_joiner/row/SetValueColumnVisitor.scala
|
68
|
+
- src/main/scala/org/embulk/filter/json_key_joiner/row/ValueHolder.scala
|
69
|
+
- src/test/scala/org/embulk/filter/json_key_joiner/json/JsonParserSpec.scala
|
70
|
+
- classpath/cats-core_2.11-0.9.0.jar
|
71
|
+
- classpath/cats-kernel_2.11-0.9.0.jar
|
72
|
+
- classpath/cats-macros_2.11-0.9.0.jar
|
73
|
+
- classpath/circe-core_2.11-0.8.0.jar
|
74
|
+
- classpath/circe-generic_2.11-0.8.0.jar
|
75
|
+
- classpath/circe-jawn_2.11-0.8.0.jar
|
76
|
+
- classpath/circe-numbers_2.11-0.8.0.jar
|
77
|
+
- classpath/circe-parser_2.11-0.8.0.jar
|
78
|
+
- classpath/embulk-filter-json_key_joiner-0.1.0.jar
|
79
|
+
- classpath/jawn-parser_2.11-0.10.4.jar
|
80
|
+
- classpath/machinist_2.11-0.6.1.jar
|
81
|
+
- classpath/macro-compat_2.11-1.1.1.jar
|
82
|
+
- classpath/scala-library-2.11.11.jar
|
83
|
+
- classpath/scala-reflect-2.11.8.jar
|
84
|
+
- classpath/shapeless_2.11-2.3.2.jar
|
85
|
+
- classpath/simulacrum_2.11-0.10.0.jar
|
86
|
+
homepage: https://github.com/smdmts/embulk-filter-json_key_joiner
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.1.9
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Json Key Joiner filter plugin for Embulk
|
110
|
+
test_files: []
|