embulk-filter-concat 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.idea/compiler.xml +26 -0
  3. data/.idea/copyright/profiles_settings.xml +3 -0
  4. data/.idea/gradle.xml +19 -0
  5. data/.idea/libraries/Gradle__aopalliance_aopalliance_1_0.xml +11 -0
  6. data/.idea/libraries/Gradle__ch_qos_logback_logback_classic_1_1_3.xml +11 -0
  7. data/.idea/libraries/Gradle__ch_qos_logback_logback_core_1_1_3.xml +11 -0
  8. data/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_annotations_2_5_3.xml +11 -0
  9. data/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_core_2_5_3.xml +11 -0
  10. data/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_databind_2_5_3.xml +11 -0
  11. data/.idea/libraries/Gradle__com_fasterxml_jackson_datatype_jackson_datatype_guava_2_5_3.xml +11 -0
  12. data/.idea/libraries/Gradle__com_fasterxml_jackson_datatype_jackson_datatype_joda_2_5_3.xml +11 -0
  13. data/.idea/libraries/Gradle__com_fasterxml_jackson_module_jackson_module_guice_2_5_3.xml +11 -0
  14. data/.idea/libraries/Gradle__com_google_code_findbugs_annotations_3_0_0.xml +11 -0
  15. data/.idea/libraries/Gradle__com_google_guava_guava_18_0.xml +11 -0
  16. data/.idea/libraries/Gradle__com_google_inject_extensions_guice_multibindings_4_0.xml +11 -0
  17. data/.idea/libraries/Gradle__com_google_inject_guice_4_0.xml +11 -0
  18. data/.idea/libraries/Gradle__com_ibm_icu_icu4j_54_1_1.xml +11 -0
  19. data/.idea/libraries/Gradle__commons_beanutils_commons_beanutils_core_1_8_3.xml +9 -0
  20. data/.idea/libraries/Gradle__io_airlift_slice_0_9.xml +11 -0
  21. data/.idea/libraries/Gradle__io_netty_netty_buffer_5_0_0_Alpha1.xml +11 -0
  22. data/.idea/libraries/Gradle__io_netty_netty_common_5_0_0_Alpha1.xml +11 -0
  23. data/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +11 -0
  24. data/.idea/libraries/Gradle__javax_validation_validation_api_1_1_0_Final.xml +11 -0
  25. data/.idea/libraries/Gradle__joda_time_joda_time_2_9_2.xml +11 -0
  26. data/.idea/libraries/Gradle__junit_junit_4_12.xml +11 -0
  27. data/.idea/libraries/Gradle__org_apache_bval_bval_core_0_5.xml +11 -0
  28. data/.idea/libraries/Gradle__org_apache_bval_bval_jsr303_0_5.xml +11 -0
  29. data/.idea/libraries/Gradle__org_apache_commons_commons_lang3_3_1.xml +11 -0
  30. data/.idea/libraries/Gradle__org_embulk_embulk_core_0_8_9.xml +11 -0
  31. data/.idea/libraries/Gradle__org_embulk_guice_bootstrap_0_1_1.xml +11 -0
  32. data/.idea/libraries/Gradle__org_fusesource_jansi_jansi_1_11.xml +11 -0
  33. data/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml +11 -0
  34. data/.idea/libraries/Gradle__org_jruby_jruby_complete_9_0_5_0.xml +11 -0
  35. data/.idea/libraries/Gradle__org_msgpack_msgpack_core_0_8_7.xml +11 -0
  36. data/.idea/libraries/Gradle__org_slf4j_slf4j_api_1_7_12.xml +11 -0
  37. data/.idea/libraries/Gradle__org_yaml_snakeyaml_1_14.xml +11 -0
  38. data/.idea/misc.xml +57 -0
  39. data/.idea/modules.xml +10 -0
  40. data/.idea/modules/embulk-filter-concat.iml +12 -0
  41. data/.idea/modules/embulk-filter-concat_main.iml +44 -0
  42. data/.idea/modules/embulk-filter-concat_test.iml +48 -0
  43. data/.idea/vcs.xml +6 -0
  44. data/LICENSE.txt +21 -0
  45. data/README.md +57 -0
  46. data/build.gradle +96 -0
  47. data/classpath/embulk-filter-concat-0.1.0.jar +0 -0
  48. data/config/checkstyle/checkstyle.xml +128 -0
  49. data/config/checkstyle/default.xml +108 -0
  50. data/embulk-filter-concat.gemspec +19 -0
  51. data/gradle/wrapper/gradle-wrapper.jar +0 -0
  52. data/gradle/wrapper/gradle-wrapper.properties +6 -0
  53. data/gradlew +160 -0
  54. data/gradlew.bat +90 -0
  55. data/lib/embulk/filter/concat.rb +3 -0
  56. data/src/main/java/org/embulk/filter/concat/ConcatFilterPlugin.java +169 -0
  57. data/src/test/java/org/embulk/filter/concat/TestConcatFilterPlugin.java +5 -0
  58. metadata +128 -0
@@ -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>
@@ -0,0 +1,19 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-filter-concat"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["toru-takahashi"]
6
+ spec.summary = %[Concat filter plugin for Embulk]
7
+ spec.description = %[Concat]
8
+ spec.email = ["torutakahashi.ayashi@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ # TODO set this: spec.homepage = "https://github.com/toru-takahashi/embulk-filter-concat"
11
+
12
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
+ spec.test_files = spec.files.grep(%r"^(test|spec)/")
14
+ spec.require_paths = ["lib"]
15
+
16
+ #spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
17
+ spec.add_development_dependency 'bundler', ['~> 1.0']
18
+ spec.add_development_dependency 'rake', ['>= 10.0']
19
+ end
@@ -0,0 +1,6 @@
1
+ #Sat Jul 02 23:40:00 JST 2016
2
+ distributionBase=GRADLE_USER_HOME
3
+ distributionPath=wrapper/dists
4
+ zipStoreBase=GRADLE_USER_HOME
5
+ zipStorePath=wrapper/dists
6
+ distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
data/gradlew ADDED
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ##############################################################################
4
+ ##
5
+ ## Gradle start up script for UN*X
6
+ ##
7
+ ##############################################################################
8
+
9
+ # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10
+ DEFAULT_JVM_OPTS=""
11
+
12
+ APP_NAME="Gradle"
13
+ APP_BASE_NAME=`basename "$0"`
14
+
15
+ # Use the maximum available, or set MAX_FD != -1 to use that value.
16
+ MAX_FD="maximum"
17
+
18
+ warn ( ) {
19
+ echo "$*"
20
+ }
21
+
22
+ die ( ) {
23
+ echo
24
+ echo "$*"
25
+ echo
26
+ exit 1
27
+ }
28
+
29
+ # OS specific support (must be 'true' or 'false').
30
+ cygwin=false
31
+ msys=false
32
+ darwin=false
33
+ case "`uname`" in
34
+ CYGWIN* )
35
+ cygwin=true
36
+ ;;
37
+ Darwin* )
38
+ darwin=true
39
+ ;;
40
+ MINGW* )
41
+ msys=true
42
+ ;;
43
+ esac
44
+
45
+ # Attempt to set APP_HOME
46
+ # Resolve links: $0 may be a link
47
+ PRG="$0"
48
+ # Need this for relative symlinks.
49
+ while [ -h "$PRG" ] ; do
50
+ ls=`ls -ld "$PRG"`
51
+ link=`expr "$ls" : '.*-> \(.*\)$'`
52
+ if expr "$link" : '/.*' > /dev/null; then
53
+ PRG="$link"
54
+ else
55
+ PRG=`dirname "$PRG"`"/$link"
56
+ fi
57
+ done
58
+ SAVED="`pwd`"
59
+ cd "`dirname \"$PRG\"`/" >/dev/null
60
+ APP_HOME="`pwd -P`"
61
+ cd "$SAVED" >/dev/null
62
+
63
+ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64
+
65
+ # Determine the Java command to use to start the JVM.
66
+ if [ -n "$JAVA_HOME" ] ; then
67
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68
+ # IBM's JDK on AIX uses strange locations for the executables
69
+ JAVACMD="$JAVA_HOME/jre/sh/java"
70
+ else
71
+ JAVACMD="$JAVA_HOME/bin/java"
72
+ fi
73
+ if [ ! -x "$JAVACMD" ] ; then
74
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75
+
76
+ Please set the JAVA_HOME variable in your environment to match the
77
+ location of your Java installation."
78
+ fi
79
+ else
80
+ JAVACMD="java"
81
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82
+
83
+ Please set the JAVA_HOME variable in your environment to match the
84
+ location of your Java installation."
85
+ fi
86
+
87
+ # Increase the maximum file descriptors if we can.
88
+ if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89
+ MAX_FD_LIMIT=`ulimit -H -n`
90
+ if [ $? -eq 0 ] ; then
91
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92
+ MAX_FD="$MAX_FD_LIMIT"
93
+ fi
94
+ ulimit -n $MAX_FD
95
+ if [ $? -ne 0 ] ; then
96
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
97
+ fi
98
+ else
99
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100
+ fi
101
+ fi
102
+
103
+ # For Darwin, add options to specify how the application appears in the dock
104
+ if $darwin; then
105
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106
+ fi
107
+
108
+ # For Cygwin, switch paths to Windows format before running java
109
+ if $cygwin ; then
110
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112
+ JAVACMD=`cygpath --unix "$JAVACMD"`
113
+
114
+ # We build the pattern for arguments to be converted via cygpath
115
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116
+ SEP=""
117
+ for dir in $ROOTDIRSRAW ; do
118
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
119
+ SEP="|"
120
+ done
121
+ OURCYGPATTERN="(^($ROOTDIRS))"
122
+ # Add a user-defined pattern to the cygpath arguments
123
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125
+ fi
126
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
127
+ i=0
128
+ for arg in "$@" ; do
129
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131
+
132
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134
+ else
135
+ eval `echo args$i`="\"$arg\""
136
+ fi
137
+ i=$((i+1))
138
+ done
139
+ case $i in
140
+ (0) set -- ;;
141
+ (1) set -- "$args0" ;;
142
+ (2) set -- "$args0" "$args1" ;;
143
+ (3) set -- "$args0" "$args1" "$args2" ;;
144
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150
+ esac
151
+ fi
152
+
153
+ # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154
+ function splitJvmOpts() {
155
+ JVM_OPTS=("$@")
156
+ }
157
+ eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158
+ JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159
+
160
+ exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
@@ -0,0 +1,90 @@
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
+ @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12
+ set DEFAULT_JVM_OPTS=
13
+
14
+ set DIRNAME=%~dp0
15
+ if "%DIRNAME%" == "" set DIRNAME=.
16
+ set APP_BASE_NAME=%~n0
17
+ set APP_HOME=%DIRNAME%
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 Windowz variants
50
+
51
+ if not "%OS%" == "Windows_NT" goto win9xME_args
52
+ if "%@eval[2+2]" == "4" goto 4NT_args
53
+
54
+ :win9xME_args
55
+ @rem Slurp the command line arguments.
56
+ set CMD_LINE_ARGS=
57
+ set _SKIP=2
58
+
59
+ :win9xME_args_slurp
60
+ if "x%~1" == "x" goto execute
61
+
62
+ set CMD_LINE_ARGS=%*
63
+ goto execute
64
+
65
+ :4NT_args
66
+ @rem Get arguments from the 4NT Shell from JP Software
67
+ set CMD_LINE_ARGS=%$
68
+
69
+ :execute
70
+ @rem Setup the command line
71
+
72
+ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73
+
74
+ @rem Execute Gradle
75
+ "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76
+
77
+ :end
78
+ @rem End local scope for the variables with windows NT shell
79
+ if "%ERRORLEVEL%"=="0" goto mainEnd
80
+
81
+ :fail
82
+ rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83
+ rem the _cmd.exe /c_ return code!
84
+ if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85
+ exit /b 1
86
+
87
+ :mainEnd
88
+ if "%OS%"=="Windows_NT" endlocal
89
+
90
+ :omega
@@ -0,0 +1,3 @@
1
+ Embulk::JavaPlugin.register_filter(
2
+ "concat", "org.embulk.filter.concat.ConcatFilterPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1,169 @@
1
+ package org.embulk.filter.concat;
2
+
3
+ import com.google.common.base.Optional;
4
+ import org.embulk.config.Config;
5
+ import org.embulk.config.ConfigDefault;
6
+ import org.embulk.config.ConfigException;
7
+ import org.embulk.config.ConfigSource;
8
+ import org.embulk.config.Task;
9
+ import org.embulk.config.TaskSource;
10
+ import org.embulk.spi.Column;
11
+ import org.embulk.spi.Exec;
12
+ import org.embulk.spi.FilterPlugin;
13
+ import org.embulk.spi.Page;
14
+ import org.embulk.spi.PageOutput;
15
+ import org.embulk.spi.PageReader;
16
+ import org.embulk.spi.PageBuilder;
17
+ import org.embulk.spi.Schema;
18
+ import org.embulk.spi.type.TimestampType;
19
+ import org.embulk.spi.type.Types;
20
+ import org.embulk.spi.time.Timestamp;
21
+ import org.embulk.spi.type.JsonType;
22
+ import org.embulk.spi.type.Type;
23
+ import java.util.ArrayList;
24
+ import java.util.List;
25
+ import com.google.common.collect.ImmutableList;
26
+ import com.google.common.base.Joiner;
27
+ import org.joda.time.DateTimeZone;
28
+
29
+
30
+ public class ConcatFilterPlugin implements FilterPlugin
31
+ {
32
+ interface ColumnConfig extends Task
33
+ {
34
+ @Config("name")
35
+ String getName();
36
+ }
37
+
38
+ interface PluginTask extends Task
39
+ {
40
+ @Config("name")
41
+ String getName();
42
+
43
+ @Config("columns")
44
+ @ConfigDefault("[]")
45
+ List<ColumnConfig> getColumns();
46
+
47
+ @Config("delimiter")
48
+ @ConfigDefault("\" \"")
49
+ String getDelimiter();
50
+ }
51
+
52
+ private void configure(PluginTask task, Schema inputSchema) {
53
+ List<ColumnConfig> columns = task.getColumns();
54
+
55
+ if (columns.size() < 2) {
56
+ throw new ConfigException("\"columns\" should be specified 2~ columns.");
57
+ }
58
+
59
+ // throw if column type is not supported
60
+ for (ColumnConfig columnConfig : columns) {
61
+ String name = columnConfig.getName();
62
+ Type type = inputSchema.lookupColumn(name).getType();
63
+
64
+ if (type instanceof JsonType) {
65
+ throw new ConfigException(String.format("casting to json is not available: \"%s\"", name));
66
+ }
67
+ if (type instanceof TimestampType) {
68
+ throw new ConfigException(String.format("casting to timestamp is not available: \"%s\"", name));
69
+ }
70
+ }
71
+ }
72
+
73
+ @Override
74
+ public void transaction(ConfigSource config, Schema inputSchema,
75
+ FilterPlugin.Control control)
76
+ {
77
+ PluginTask task = config.loadConfig(PluginTask.class);
78
+
79
+ configure(task, inputSchema);
80
+
81
+ ImmutableList.Builder<Column> builder = ImmutableList.builder();
82
+ int i = 0;
83
+ Column outputColumn;
84
+
85
+ for (Column inputColumn: inputSchema.getColumns()) {
86
+ outputColumn = new Column(i++, inputColumn.getName(), inputColumn.getType());
87
+ builder.add(outputColumn);
88
+ }
89
+
90
+ outputColumn = new Column(i, task.getName(), Types.STRING);
91
+ builder.add(outputColumn);
92
+ Schema outputSchema = new Schema(builder.build());
93
+ control.run(task.dump(), outputSchema);
94
+ }
95
+
96
+ @Override
97
+ public PageOutput open(TaskSource taskSource, final Schema inputSchema, final Schema outputSchema, final PageOutput output)
98
+ {
99
+ final PluginTask task = taskSource.loadTask(PluginTask.class);
100
+ final Column outputColumn = outputSchema.lookupColumn(task.getName());
101
+ final List<ColumnConfig> columnConfigs = task.getColumns();
102
+
103
+ return new PageOutput() {
104
+ private final PageReader reader = new PageReader(inputSchema);
105
+ private final PageBuilder builder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, output);
106
+
107
+ @Override
108
+ public void finish() {
109
+ builder.finish();
110
+ }
111
+
112
+ @Override
113
+ public void close() {
114
+ builder.close();
115
+ }
116
+
117
+ @Override
118
+ public void add(Page page) {
119
+ reader.setPage(page);
120
+ while (reader.nextRecord()) {
121
+ ArrayList<String> buf = new ArrayList<String>();
122
+ for (ColumnConfig target: columnConfigs) {
123
+ Column column = outputSchema.lookupColumn(target.getName());
124
+ if (reader.isNull(column)) {
125
+ buf.add("");
126
+ continue;
127
+ }
128
+ if (Types.STRING.equals(column.getType())) {
129
+ buf.add(reader.getString(column));
130
+ } else if (Types.BOOLEAN.equals(column.getType())) {
131
+ buf.add(String.valueOf(reader.getBoolean(column)));
132
+ } else if (Types.DOUBLE.equals(column.getType())) {
133
+ buf.add(String.valueOf(reader.getDouble(column)));
134
+ } else if (Types.LONG.equals(column.getType())) {
135
+ buf.add(String.valueOf(reader.getLong(column)));
136
+ }
137
+ }
138
+
139
+ String output = Joiner.on(task.getDelimiter()).join(buf);
140
+
141
+ for (Column column: outputSchema.getColumns()) {
142
+ if (column.getName().equals(outputColumn.getName())) {
143
+ builder.setString(outputColumn, output);
144
+ continue;
145
+ }
146
+ if (reader.isNull(column)) {
147
+ builder.setNull(column);
148
+ continue;
149
+ }
150
+ if (Types.STRING.equals(column.getType())) {
151
+ builder.setString(column, reader.getString(column));
152
+ } else if (Types.BOOLEAN.equals(column.getType())) {
153
+ builder.setBoolean(column, reader.getBoolean(column));
154
+ } else if (Types.DOUBLE.equals(column.getType())) {
155
+ builder.setDouble(column, reader.getDouble(column));
156
+ } else if (Types.LONG.equals(column.getType())) {
157
+ builder.setLong(column, reader.getLong(column));
158
+ } else if (Types.TIMESTAMP.equals(column.getType())) {
159
+ builder.setTimestamp(column, reader.getTimestamp(column));
160
+ } else if (Types.JSON.equals(column.getType())) {
161
+ builder.setJson(column, reader.getJson(column));
162
+ }
163
+ }
164
+ builder.addRecord();
165
+ }
166
+ }
167
+ };
168
+ }
169
+ }