embulk-filter-query_string 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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/LICENSE.txt +202 -0
- data/README.md +49 -0
- data/build.gradle +101 -0
- data/config/checkstyle/checkstyle.xml +128 -0
- data/config/checkstyle/default.xml +108 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +160 -0
- data/gradlew.bat +90 -0
- data/lib/embulk/filter/query_string.rb +3 -0
- data/src/main/java/org/embulk/filter/query_string/QueryStringFilterPlugin.java +279 -0
- data/src/test/java/org/embulk/filter/query_string/TestQueryStringFilterPlugin.java +128 -0
- data/src/test/resources/testOpen.yml +5 -0
- data/src/test/resources/testTransaction.yml +6 -0
- metadata +95 -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>
|
Binary file
|
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 "$@"
|
data/gradlew.bat
ADDED
@@ -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,279 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2016 Minnano Wedding Co., Ltd.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
package org.embulk.filter.query_string;
|
18
|
+
|
19
|
+
import com.indeed.util.urlparsing.ParseUtils;
|
20
|
+
import com.indeed.util.urlparsing.QueryStringParser;
|
21
|
+
import com.indeed.util.urlparsing.QueryStringParserCallback;
|
22
|
+
import com.indeed.util.urlparsing.QueryStringParserCallbackBuilder;
|
23
|
+
import org.embulk.config.Config;
|
24
|
+
import org.embulk.config.ConfigSource;
|
25
|
+
import org.embulk.config.Task;
|
26
|
+
import org.embulk.config.TaskSource;
|
27
|
+
import org.embulk.spi.Column;
|
28
|
+
import org.embulk.spi.ColumnConfig;
|
29
|
+
import org.embulk.spi.Exec;
|
30
|
+
import org.embulk.spi.FilterPlugin;
|
31
|
+
import org.embulk.spi.Page;
|
32
|
+
import org.embulk.spi.PageBuilder;
|
33
|
+
import org.embulk.spi.PageOutput;
|
34
|
+
import org.embulk.spi.PageReader;
|
35
|
+
import org.embulk.spi.Schema;
|
36
|
+
import org.embulk.spi.time.Timestamp;
|
37
|
+
import org.embulk.spi.type.Types;
|
38
|
+
import org.slf4j.Logger;
|
39
|
+
|
40
|
+
import java.util.HashMap;
|
41
|
+
import java.util.List;
|
42
|
+
import java.util.Map;
|
43
|
+
|
44
|
+
public class QueryStringFilterPlugin
|
45
|
+
implements FilterPlugin
|
46
|
+
{
|
47
|
+
@Override
|
48
|
+
public void transaction(ConfigSource config, Schema inputSchema, FilterPlugin.Control control)
|
49
|
+
{
|
50
|
+
PluginTask task = config.loadConfig(PluginTask.class);
|
51
|
+
String columnName = task.getQueryStringColumnName();
|
52
|
+
|
53
|
+
Schema.Builder builder = Schema.builder();
|
54
|
+
for (Column inputColumn : inputSchema.getColumns()) {
|
55
|
+
if (columnName.equals(inputColumn.getName())) {
|
56
|
+
insertColumns(builder, task.getExpandedColumns());
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
builder.add(inputColumn.getName(), inputColumn.getType());
|
60
|
+
}
|
61
|
+
}
|
62
|
+
control.run(task.dump(), builder.build());
|
63
|
+
}
|
64
|
+
|
65
|
+
private void insertColumns(Schema.Builder builder, List<ColumnConfig> expandedColumns)
|
66
|
+
{
|
67
|
+
for (ColumnConfig columnConfig : expandedColumns) {
|
68
|
+
builder.add(columnConfig.getName(), columnConfig.getType());
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
@Override
|
73
|
+
public PageOutput open(TaskSource taskSource, final Schema inputSchema, final Schema outputSchema, final PageOutput output)
|
74
|
+
{
|
75
|
+
final PluginTask task = taskSource.loadTask(PluginTask.class);
|
76
|
+
|
77
|
+
return new PageOutput()
|
78
|
+
{
|
79
|
+
final Logger logger = Exec.getLogger(this.getClass());
|
80
|
+
|
81
|
+
private PageReader reader = new PageReader(inputSchema);
|
82
|
+
private PageBuilder builder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, output);
|
83
|
+
|
84
|
+
private final QueryStringParserCallback stringParser = new QueryStringParserCallback<Map<String, Object>>()
|
85
|
+
{
|
86
|
+
@Override
|
87
|
+
public void parseKeyValuePair(String queryString, int keyStart, int keyEnd, int valueStart, int valueEnd, Map<String, Object> storage)
|
88
|
+
{
|
89
|
+
String key = queryString.substring(keyStart, keyEnd);
|
90
|
+
|
91
|
+
StringBuilder decoded = new StringBuilder();
|
92
|
+
ParseUtils.urlDecodeInto(queryString, valueStart, valueEnd, decoded);
|
93
|
+
|
94
|
+
storage.put(key, decoded.toString());
|
95
|
+
}
|
96
|
+
};
|
97
|
+
|
98
|
+
private final QueryStringParserCallback booleanParser = new QueryStringParserCallback<Map<String, Object>>()
|
99
|
+
{
|
100
|
+
@Override
|
101
|
+
public void parseKeyValuePair(String queryString, int keyStart, int keyEnd, int valueStart, int valueEnd, Map<String, Object> storage)
|
102
|
+
{
|
103
|
+
String key = queryString.substring(keyStart, keyEnd);
|
104
|
+
String value = queryString.substring(valueStart, valueEnd);
|
105
|
+
|
106
|
+
storage.put(key, Boolean.parseBoolean(value));
|
107
|
+
}
|
108
|
+
};
|
109
|
+
|
110
|
+
private final QueryStringParserCallback doubleParser = new QueryStringParserCallback<Map<String, Object>>()
|
111
|
+
{
|
112
|
+
@Override
|
113
|
+
public void parseKeyValuePair(String queryString, int keyStart, int keyEnd, int valueStart, int valueEnd, Map<String, Object> storage)
|
114
|
+
{
|
115
|
+
String key = queryString.substring(keyStart, keyEnd);
|
116
|
+
String value = queryString.substring(valueStart, valueEnd);
|
117
|
+
|
118
|
+
storage.put(key, Double.parseDouble(value));
|
119
|
+
}
|
120
|
+
};
|
121
|
+
|
122
|
+
private final QueryStringParserCallback longParser = new QueryStringParserCallback<Map<String, Object>>()
|
123
|
+
{
|
124
|
+
@Override
|
125
|
+
public void parseKeyValuePair(String queryString, int keyStart, int keyEnd, int valueStart, int valueEnd, Map<String, Object> storage)
|
126
|
+
{
|
127
|
+
String key = queryString.substring(keyStart, keyEnd);
|
128
|
+
long value = ParseUtils.parseUnsignedLong(queryString, valueStart, valueEnd);
|
129
|
+
|
130
|
+
storage.put(key, value);
|
131
|
+
}
|
132
|
+
};
|
133
|
+
|
134
|
+
private final QueryStringParserCallback unixTimestampParser = new QueryStringParserCallback<Map<String, Object>>()
|
135
|
+
{
|
136
|
+
@Override
|
137
|
+
public void parseKeyValuePair(String queryString, int keyStart, int keyEnd, int valueStart, int valueEnd, Map<String, Object> storage)
|
138
|
+
{
|
139
|
+
String key = queryString.substring(keyStart, keyEnd);
|
140
|
+
long value = ParseUtils.parseUnsignedLong(queryString, valueStart, valueEnd);
|
141
|
+
|
142
|
+
storage.put(key, Timestamp.ofEpochSecond(value));
|
143
|
+
}
|
144
|
+
};
|
145
|
+
|
146
|
+
@Override
|
147
|
+
public void add(Page page)
|
148
|
+
{
|
149
|
+
String columnName = task.getQueryStringColumnName();
|
150
|
+
QueryStringParserCallback<Map<String, Object>> callback = buildQueryStringParserCallback();
|
151
|
+
|
152
|
+
reader.setPage(page);
|
153
|
+
while (reader.nextRecord()) {
|
154
|
+
int curr = 0;
|
155
|
+
|
156
|
+
for (Column inputColumn : inputSchema.getColumns()) {
|
157
|
+
if (columnName.equals(inputColumn.getName())) {
|
158
|
+
String path = reader.getString(inputColumn);
|
159
|
+
|
160
|
+
int pos = path.indexOf('?');
|
161
|
+
if (pos > 0) {
|
162
|
+
String queryString = path.substring(pos + 1);
|
163
|
+
|
164
|
+
Map<String, Object> map = new HashMap<>();
|
165
|
+
QueryStringParser.parseQueryString(queryString, callback, map);
|
166
|
+
for (ColumnConfig config : task.getExpandedColumns()) {
|
167
|
+
Object object = map.get(config.getName());
|
168
|
+
|
169
|
+
if (object == null) {
|
170
|
+
builder.setNull(curr);
|
171
|
+
}
|
172
|
+
else {
|
173
|
+
if (Types.STRING.equals(config.getType())) {
|
174
|
+
builder.setString(curr, (String) object);
|
175
|
+
}
|
176
|
+
else if (Types.BOOLEAN.equals(config.getType())) {
|
177
|
+
builder.setBoolean(curr, (Boolean) object);
|
178
|
+
}
|
179
|
+
else if (Types.DOUBLE.equals(config.getType())) {
|
180
|
+
builder.setDouble(curr, (Double) object);
|
181
|
+
}
|
182
|
+
else if (Types.LONG.equals(config.getType())) {
|
183
|
+
builder.setLong(curr, (Long) object);
|
184
|
+
}
|
185
|
+
else if (Types.TIMESTAMP.equals(config.getType())) {
|
186
|
+
builder.setTimestamp(curr, (Timestamp) object);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
curr++;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
else {
|
194
|
+
logger.warn("The column was ignored because it does not seem to be a query string: " + path);
|
195
|
+
|
196
|
+
for (ColumnConfig config : task.getExpandedColumns()) {
|
197
|
+
builder.setNull(curr);
|
198
|
+
curr++;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
else {
|
203
|
+
if (reader.isNull(inputColumn)) {
|
204
|
+
builder.setNull(curr);
|
205
|
+
}
|
206
|
+
else {
|
207
|
+
if (Types.STRING.equals(inputColumn.getType())) {
|
208
|
+
builder.setString(curr, reader.getString(inputColumn));
|
209
|
+
}
|
210
|
+
else if (Types.BOOLEAN.equals(inputColumn.getType())) {
|
211
|
+
builder.setBoolean(curr, reader.getBoolean(inputColumn));
|
212
|
+
}
|
213
|
+
else if (Types.DOUBLE.equals(inputColumn.getType())) {
|
214
|
+
builder.setDouble(curr, reader.getDouble(inputColumn));
|
215
|
+
}
|
216
|
+
else if (Types.LONG.equals(inputColumn.getType())) {
|
217
|
+
builder.setLong(curr, reader.getLong(inputColumn));
|
218
|
+
}
|
219
|
+
else if (Types.TIMESTAMP.equals(inputColumn.getType())) {
|
220
|
+
builder.setTimestamp(curr, reader.getTimestamp(inputColumn));
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
curr++;
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
builder.addRecord();
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
private QueryStringParserCallback<Map<String, Object>> buildQueryStringParserCallback()
|
233
|
+
{
|
234
|
+
QueryStringParserCallbackBuilder<Map<String, Object>> callbackBuilder = new QueryStringParserCallbackBuilder<>();
|
235
|
+
|
236
|
+
for (ColumnConfig config : task.getExpandedColumns()) {
|
237
|
+
if (Types.STRING.equals(config.getType())) {
|
238
|
+
callbackBuilder.addCallback(config.getName(), stringParser);
|
239
|
+
}
|
240
|
+
else if (Types.BOOLEAN.equals(config.getType())) {
|
241
|
+
callbackBuilder.addCallback(config.getName(), booleanParser);
|
242
|
+
}
|
243
|
+
else if (Types.DOUBLE.equals(config.getType())) {
|
244
|
+
callbackBuilder.addCallback(config.getName(), doubleParser);
|
245
|
+
}
|
246
|
+
else if (Types.LONG.equals(config.getType())) {
|
247
|
+
callbackBuilder.addCallback(config.getName(), longParser);
|
248
|
+
}
|
249
|
+
else if (Types.TIMESTAMP.equals(config.getType())) {
|
250
|
+
callbackBuilder.addCallback(config.getName(), unixTimestampParser);
|
251
|
+
}
|
252
|
+
}
|
253
|
+
return callbackBuilder.buildCallback();
|
254
|
+
}
|
255
|
+
|
256
|
+
@Override
|
257
|
+
public void finish()
|
258
|
+
{
|
259
|
+
builder.finish();
|
260
|
+
}
|
261
|
+
|
262
|
+
@Override
|
263
|
+
public void close()
|
264
|
+
{
|
265
|
+
builder.close();
|
266
|
+
}
|
267
|
+
};
|
268
|
+
}
|
269
|
+
|
270
|
+
public interface PluginTask
|
271
|
+
extends Task
|
272
|
+
{
|
273
|
+
@Config("query_string_column_name")
|
274
|
+
public String getQueryStringColumnName();
|
275
|
+
|
276
|
+
@Config("expanded_columns")
|
277
|
+
public List<ColumnConfig> getExpandedColumns();
|
278
|
+
}
|
279
|
+
}
|