embulk-filter-timestamp_format 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/.travis.yml +7 -0
- data/CHANGELOG.md +0 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/build.gradle +86 -0
- data/config/checkstyle/checkstyle.xml +127 -0
- data/example/example.jsonl +2 -0
- data/example/example.yml +17 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +164 -0
- data/gradlew.bat +90 -0
- data/lib/embulk/filter/timestamp_format.rb +3 -0
- data/src/main/java/org/embulk/filter/TimestampFormatFilterPlugin.java +289 -0
- data/src/main/java/org/embulk/filter/timestamp_format/TimestampFormatter.java +79 -0
- data/src/main/java/org/embulk/filter/timestamp_format/TimestampParser.java +108 -0
- data/src/test/java/org/embulk/filter/TestTimestampFormatFilterPlugin.java +5 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5bbc918d5bf6ffd22de31d35b00909dcb7e29b8a
|
4
|
+
data.tar.gz: 23ac08f9781e5c0accdd06c58034801f738ab4b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1db3ebc3893536c371f7765151d9ea673a21f05bd655a311a0a935b2f0da61cbb66bb18bd33dd59a7e63a12754be0f74991a431696ef091e48f68f2a2ff1b9d
|
7
|
+
data.tar.gz: e26a3e99225d16ed059f0201ecb7a1ecf009fb1544b0137ea32d2d7d49a6f89815bbc08e608b73f503fcbd21e353ea12f9a62aa5d5fee161af8ad37806b172f4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
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,85 @@
|
|
1
|
+
# Timestamp format filter plugin for Embulk
|
2
|
+
|
3
|
+
[](http://travis-ci.org/sonots/embulk-filter-timestamp_format)
|
4
|
+
|
5
|
+
A filter plugin for Embulk to change timesatmp format
|
6
|
+
|
7
|
+
## Configuration
|
8
|
+
|
9
|
+
- **columns**: columns to retain (array of hash)
|
10
|
+
- **name**: name of column, must be a string column (required)
|
11
|
+
- **from_format**: specify the format of the input timestamp (string or an array, default is default_from_format)
|
12
|
+
- **from_timezone**: specify the timezone of the input timestamp (string, default is default_from_timezone)
|
13
|
+
- **to_format**: specify the format of the output timestamp (string, default is default_to_format)
|
14
|
+
- **to_timezone**: specify the timezone of the output timestamp (string, default is default_to_timezone)
|
15
|
+
- **default_from_format**: default timestamp format for the input timestamp columns (string, default is `%Y-%m-%d %H:%M:%S.%N %z`)
|
16
|
+
- **default_from_timezone**: default timezone for the input timestamp columns (string, default is `UTC`)
|
17
|
+
- **default_to_format**: default timestamp format for the output timestamp columns (string, default is `%Y-%m-%d %H:%M:%S.%N %z`)
|
18
|
+
- **default_to_timezone**: default timezone for the output timestamp olumns (string, default is `UTC`)
|
19
|
+
|
20
|
+
## Example
|
21
|
+
|
22
|
+
Say example.jsonl is as follows (this is a typical format which Exporting BigQuery table outputs):
|
23
|
+
|
24
|
+
```
|
25
|
+
{"timestamp":"2015-07-12 15:00:00 UTC","record":{"timestamp":"2015-07-12 15:00:00 UTC"}}
|
26
|
+
{"timestamp":"2015-07-12 15:00:00.1 UTC","record":{"timestamp":"2015-07-12 15:00:00.1 UTC"}}
|
27
|
+
```
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
in:
|
31
|
+
type: file
|
32
|
+
path_prefix: example/example.jsonl
|
33
|
+
parser:
|
34
|
+
type: jsonl
|
35
|
+
columns:
|
36
|
+
- {name: timestamp, type: string}
|
37
|
+
- {name: record, type: json}
|
38
|
+
filters:
|
39
|
+
- type: timestamp_format
|
40
|
+
default_to_timezone: "Asia/Tokyo"
|
41
|
+
default_to_format: "%Y-%m-%d %H:%M:%S.%N"
|
42
|
+
columns:
|
43
|
+
- {name: timestamp, from_format: ["%Y-%m-%d %H:%M:%S.%N %z", "%Y-%m-%d %H:%M:%S %z"]}
|
44
|
+
- {name: record.timestamp, from_format: ["%Y-%m-%d %H:%M:%S.%N %z", "%Y-%m-%d %H:%M:%S %z"]}
|
45
|
+
type: stdout
|
46
|
+
```
|
47
|
+
|
48
|
+
Output will be as:
|
49
|
+
|
50
|
+
```
|
51
|
+
{"timestamp":"2015-07-13 00:00:00.0","record":{"timestamp":"2015-07-13 00:00:00.0}}
|
52
|
+
{"timestamp":"2015-07-13 00:00:00.1","record":{"timestamp":"2015-07-13 00:00:00.1}}
|
53
|
+
```
|
54
|
+
|
55
|
+
## ToDo
|
56
|
+
|
57
|
+
* Write test
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
Run example:
|
62
|
+
|
63
|
+
```
|
64
|
+
$ embulk gem install embulk-parser-jsonl
|
65
|
+
$ ./gradlew classpath
|
66
|
+
$ embulk run -I lib example/example.yml
|
67
|
+
```
|
68
|
+
|
69
|
+
Run test:
|
70
|
+
|
71
|
+
```
|
72
|
+
$ ./gradlew test
|
73
|
+
```
|
74
|
+
|
75
|
+
Run checkstyle:
|
76
|
+
|
77
|
+
```
|
78
|
+
$ ./gradlew check
|
79
|
+
```
|
80
|
+
|
81
|
+
Release gem:
|
82
|
+
|
83
|
+
```
|
84
|
+
$ ./gradlew gemPush
|
85
|
+
```
|
data/build.gradle
ADDED
@@ -0,0 +1,86 @@
|
|
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 "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.0"
|
17
|
+
sourceCompatibility = 1.7
|
18
|
+
targetCompatibility = 1.7
|
19
|
+
|
20
|
+
dependencies {
|
21
|
+
compile "org.embulk:embulk-core:0.8.2"
|
22
|
+
provided "org.embulk:embulk-core:0.8.2"
|
23
|
+
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
|
24
|
+
testCompile "junit:junit:4.+"
|
25
|
+
}
|
26
|
+
|
27
|
+
checkstyle {
|
28
|
+
toolVersion = '6.7'
|
29
|
+
}
|
30
|
+
|
31
|
+
task classpath(type: Copy, dependsOn: ["jar"]) {
|
32
|
+
doFirst { file("classpath").deleteDir() }
|
33
|
+
from (configurations.runtime - configurations.provided + files(jar.archivePath))
|
34
|
+
into "classpath"
|
35
|
+
}
|
36
|
+
clean { delete "classpath" }
|
37
|
+
|
38
|
+
task gem(type: JRubyExec, dependsOn: ["gemspec", "classpath"]) {
|
39
|
+
jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "build"
|
40
|
+
script "${project.name}.gemspec"
|
41
|
+
doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
|
42
|
+
}
|
43
|
+
|
44
|
+
task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
|
45
|
+
jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "push"
|
46
|
+
script "pkg/${project.name}-${project.version}.gem"
|
47
|
+
}
|
48
|
+
|
49
|
+
task "package"(dependsOn: ["gemspec", "classpath"]) << {
|
50
|
+
println "> Build succeeded."
|
51
|
+
println "> You can run embulk with '-L ${file(".").absolutePath}' argument."
|
52
|
+
}
|
53
|
+
|
54
|
+
task gemspec {
|
55
|
+
ext.gemspecFile = file("${project.name}.gemspec")
|
56
|
+
inputs.file "build.gradle"
|
57
|
+
outputs.file gemspecFile
|
58
|
+
doLast { gemspecFile.write($/
|
59
|
+
Gem::Specification.new do |spec|
|
60
|
+
spec.name = "${project.name}"
|
61
|
+
spec.version = "${project.version}"
|
62
|
+
spec.authors = ["Naotoshi Seo"]
|
63
|
+
spec.summary = %[A filter plugin for Embulk to change timestamp format]
|
64
|
+
spec.description = %[A filter plugin for Embulk to change timestamp format.]
|
65
|
+
spec.email = ["sonots@gmail.com"]
|
66
|
+
spec.licenses = ["MIT"]
|
67
|
+
spec.homepage = "https://github.com/sonots/embulk-filter-timestamp_format"
|
68
|
+
|
69
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
70
|
+
spec.test_files = spec.files.grep(%r"^(test|spec)/")
|
71
|
+
spec.require_paths = ["lib"]
|
72
|
+
|
73
|
+
if spec.respond_to?(:metadata)
|
74
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.dena.jp"
|
75
|
+
else
|
76
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
77
|
+
end
|
78
|
+
|
79
|
+
spec.add_development_dependency 'bundler', ['~> 1.0']
|
80
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
81
|
+
spec.add_development_dependency 'embulk-parser-jsonl'
|
82
|
+
end
|
83
|
+
/$)
|
84
|
+
}
|
85
|
+
}
|
86
|
+
clean { delete "${project.name}.gemspec" }
|
@@ -0,0 +1,127 @@
|
|
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
|
+
<module name="FileTabCharacter"/>
|
7
|
+
<module name="NewlineAtEndOfFile">
|
8
|
+
<property name="lineSeparator" value="lf"/>
|
9
|
+
</module>
|
10
|
+
<module name="RegexpMultiline">
|
11
|
+
<property name="format" value="\r"/>
|
12
|
+
<property name="message" value="Line contains carriage return"/>
|
13
|
+
</module>
|
14
|
+
<module name="RegexpMultiline">
|
15
|
+
<property name="format" value=" \n"/>
|
16
|
+
<property name="message" value="Line has trailing whitespace"/>
|
17
|
+
</module>
|
18
|
+
<module name="RegexpMultiline">
|
19
|
+
<property name="format" value="\{\n\n"/>
|
20
|
+
<property name="message" value="Blank line after opening brace"/>
|
21
|
+
</module>
|
22
|
+
<module name="RegexpMultiline">
|
23
|
+
<property name="format" value="\n\n\s*\}"/>
|
24
|
+
<property name="message" value="Blank line before closing brace"/>
|
25
|
+
</module>
|
26
|
+
<module name="RegexpMultiline">
|
27
|
+
<property name="format" value="\n\n\n"/>
|
28
|
+
<property name="message" value="Multiple consecutive blank lines"/>
|
29
|
+
</module>
|
30
|
+
<module name="RegexpMultiline">
|
31
|
+
<property name="format" value="\n\n\Z"/>
|
32
|
+
<property name="message" value="Blank line before end of file"/>
|
33
|
+
</module>
|
34
|
+
<module name="RegexpMultiline">
|
35
|
+
<property name="format" value="Preconditions\.checkNotNull"/>
|
36
|
+
<property name="message" value="Use of checkNotNull"/>
|
37
|
+
</module>
|
38
|
+
|
39
|
+
<module name="TreeWalker">
|
40
|
+
<module name="EmptyBlock">
|
41
|
+
<property name="option" value="text"/>
|
42
|
+
<property name="tokens" value="
|
43
|
+
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
|
44
|
+
LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, INSTANCE_INIT, STATIC_INIT"/>
|
45
|
+
</module>
|
46
|
+
<module name="EmptyStatement"/>
|
47
|
+
<module name="EmptyForInitializerPad"/>
|
48
|
+
<module name="EmptyForIteratorPad">
|
49
|
+
<property name="option" value="space"/>
|
50
|
+
</module>
|
51
|
+
<module name="MethodParamPad">
|
52
|
+
<property name="allowLineBreaks" value="true"/>
|
53
|
+
<property name="option" value="nospace"/>
|
54
|
+
</module>
|
55
|
+
<module name="ParenPad"/>
|
56
|
+
<module name="TypecastParenPad"/>
|
57
|
+
<module name="NeedBraces"/>
|
58
|
+
<module name="LeftCurly">
|
59
|
+
<property name="option" value="nl"/>
|
60
|
+
<property name="tokens" value="CLASS_DEF, CTOR_DEF, INTERFACE_DEF, METHOD_DEF"/>
|
61
|
+
</module>
|
62
|
+
<module name="LeftCurly">
|
63
|
+
<property name="option" value="eol"/>
|
64
|
+
<property name="tokens" value="
|
65
|
+
LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR,
|
66
|
+
LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE"/>
|
67
|
+
</module>
|
68
|
+
<module name="RightCurly">
|
69
|
+
<property name="option" value="alone"/>
|
70
|
+
</module>
|
71
|
+
<module name="GenericWhitespace"/>
|
72
|
+
<module name="WhitespaceAfter"/>
|
73
|
+
<module name="NoWhitespaceBefore"/>
|
74
|
+
|
75
|
+
<module name="UpperEll"/>
|
76
|
+
<module name="DefaultComesLast"/>
|
77
|
+
<module name="ArrayTypeStyle"/>
|
78
|
+
<module name="MultipleVariableDeclarations"/>
|
79
|
+
<module name="ModifierOrder"/>
|
80
|
+
<module name="OneStatementPerLine"/>
|
81
|
+
<module name="StringLiteralEquality"/>
|
82
|
+
<module name="MutableException"/>
|
83
|
+
<module name="EqualsHashCode"/>
|
84
|
+
<module name="InnerAssignment"/>
|
85
|
+
<module name="InterfaceIsType"/>
|
86
|
+
<module name="HideUtilityClassConstructor"/>
|
87
|
+
|
88
|
+
<module name="MemberName"/>
|
89
|
+
<module name="LocalVariableName"/>
|
90
|
+
<module name="LocalFinalVariableName"/>
|
91
|
+
<module name="TypeName"/>
|
92
|
+
<module name="PackageName"/>
|
93
|
+
<module name="ParameterName"/>
|
94
|
+
<module name="StaticVariableName"/>
|
95
|
+
<module name="ClassTypeParameterName">
|
96
|
+
<property name="format" value="^[A-Z][0-9]?$"/>
|
97
|
+
</module>
|
98
|
+
<module name="MethodTypeParameterName">
|
99
|
+
<property name="format" value="^[A-Z][0-9]?$"/>
|
100
|
+
</module>
|
101
|
+
|
102
|
+
<module name="AvoidStarImport"/>
|
103
|
+
<module name="RedundantImport"/>
|
104
|
+
<module name="UnusedImports"/>
|
105
|
+
<module name="ImportOrder">
|
106
|
+
<property name="groups" value="*,javax,java"/>
|
107
|
+
<property name="separated" value="true"/>
|
108
|
+
<property name="option" value="bottom"/>
|
109
|
+
<property name="sortStaticImportsAlphabetically" value="true"/>
|
110
|
+
</module>
|
111
|
+
|
112
|
+
<module name="WhitespaceAround">
|
113
|
+
<property name="allowEmptyConstructors" value="true"/>
|
114
|
+
<property name="allowEmptyMethods" value="true"/>
|
115
|
+
<property name="ignoreEnhancedForColon" value="false"/>
|
116
|
+
<property name="tokens" value="
|
117
|
+
ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN,
|
118
|
+
BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE,
|
119
|
+
LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
120
|
+
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
121
|
+
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE,
|
122
|
+
LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL,
|
123
|
+
PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN,
|
124
|
+
STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
|
125
|
+
</module>
|
126
|
+
</module>
|
127
|
+
</module>
|
data/example/example.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
in:
|
2
|
+
type: file
|
3
|
+
path_prefix: example/example.jsonl
|
4
|
+
parser:
|
5
|
+
type: jsonl
|
6
|
+
columns:
|
7
|
+
- {name: timestamp, type: string}
|
8
|
+
- {name: record, type: json}
|
9
|
+
filters:
|
10
|
+
- type: timestamp_format
|
11
|
+
default_to_timezone: "Asia/Tokyo"
|
12
|
+
default_to_format: "%Y-%m-%d %H:%M:%S.%N"
|
13
|
+
columns:
|
14
|
+
- {name: timestamp, from_format: ["%Y-%m-%d %H:%M:%S.%N %z", "%Y-%m-%d %H:%M:%S %z"]}
|
15
|
+
- {name: "$.record.record[0].timestamp", from_format: ["%Y-%m-%d %H:%M:%S.%N %z", "%Y-%m-%d %H:%M:%S %z"]}
|
16
|
+
out:
|
17
|
+
type: stdout
|
Binary file
|
data/gradlew
ADDED
@@ -0,0 +1,164 @@
|
|
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
|
+
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
46
|
+
if $cygwin ; then
|
47
|
+
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
48
|
+
fi
|
49
|
+
|
50
|
+
# Attempt to set APP_HOME
|
51
|
+
# Resolve links: $0 may be a link
|
52
|
+
PRG="$0"
|
53
|
+
# Need this for relative symlinks.
|
54
|
+
while [ -h "$PRG" ] ; do
|
55
|
+
ls=`ls -ld "$PRG"`
|
56
|
+
link=`expr "$ls" : '.*-> \(.*\)$'`
|
57
|
+
if expr "$link" : '/.*' > /dev/null; then
|
58
|
+
PRG="$link"
|
59
|
+
else
|
60
|
+
PRG=`dirname "$PRG"`"/$link"
|
61
|
+
fi
|
62
|
+
done
|
63
|
+
SAVED="`pwd`"
|
64
|
+
cd "`dirname \"$PRG\"`/" >&-
|
65
|
+
APP_HOME="`pwd -P`"
|
66
|
+
cd "$SAVED" >&-
|
67
|
+
|
68
|
+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
69
|
+
|
70
|
+
# Determine the Java command to use to start the JVM.
|
71
|
+
if [ -n "$JAVA_HOME" ] ; then
|
72
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
73
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
74
|
+
JAVACMD="$JAVA_HOME/jre/sh/java"
|
75
|
+
else
|
76
|
+
JAVACMD="$JAVA_HOME/bin/java"
|
77
|
+
fi
|
78
|
+
if [ ! -x "$JAVACMD" ] ; then
|
79
|
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
80
|
+
|
81
|
+
Please set the JAVA_HOME variable in your environment to match the
|
82
|
+
location of your Java installation."
|
83
|
+
fi
|
84
|
+
else
|
85
|
+
JAVACMD="java"
|
86
|
+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
87
|
+
|
88
|
+
Please set the JAVA_HOME variable in your environment to match the
|
89
|
+
location of your Java installation."
|
90
|
+
fi
|
91
|
+
|
92
|
+
# Increase the maximum file descriptors if we can.
|
93
|
+
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
94
|
+
MAX_FD_LIMIT=`ulimit -H -n`
|
95
|
+
if [ $? -eq 0 ] ; then
|
96
|
+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
97
|
+
MAX_FD="$MAX_FD_LIMIT"
|
98
|
+
fi
|
99
|
+
ulimit -n $MAX_FD
|
100
|
+
if [ $? -ne 0 ] ; then
|
101
|
+
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
102
|
+
fi
|
103
|
+
else
|
104
|
+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
105
|
+
fi
|
106
|
+
fi
|
107
|
+
|
108
|
+
# For Darwin, add options to specify how the application appears in the dock
|
109
|
+
if $darwin; then
|
110
|
+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
111
|
+
fi
|
112
|
+
|
113
|
+
# For Cygwin, switch paths to Windows format before running java
|
114
|
+
if $cygwin ; then
|
115
|
+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
116
|
+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
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
|
+
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,289 @@
|
|
1
|
+
package org.embulk.filter;
|
2
|
+
|
3
|
+
import com.google.common.base.Optional;
|
4
|
+
import com.google.common.base.Throwables;
|
5
|
+
|
6
|
+
import org.embulk.config.Config;
|
7
|
+
import org.embulk.config.ConfigInject;
|
8
|
+
import org.embulk.config.ConfigDefault;
|
9
|
+
import org.embulk.config.ConfigException;
|
10
|
+
import org.embulk.config.ConfigSource;
|
11
|
+
import org.embulk.config.Task;
|
12
|
+
import org.embulk.config.TaskSource;
|
13
|
+
|
14
|
+
import org.embulk.filter.timestamp_format.TimestampParser;
|
15
|
+
import org.embulk.filter.timestamp_format.TimestampFormatter;
|
16
|
+
|
17
|
+
import org.embulk.spi.Column;
|
18
|
+
import org.embulk.spi.ColumnVisitor;
|
19
|
+
import org.embulk.spi.Exec;
|
20
|
+
import org.embulk.spi.FilterPlugin;
|
21
|
+
import org.embulk.spi.Page;
|
22
|
+
import org.embulk.spi.PageBuilder;
|
23
|
+
import org.embulk.spi.PageOutput;
|
24
|
+
import org.embulk.spi.PageReader;
|
25
|
+
import org.embulk.spi.Schema;
|
26
|
+
import org.embulk.spi.json.JsonParser;
|
27
|
+
import org.embulk.spi.time.Timestamp;
|
28
|
+
import org.embulk.spi.time.TimestampParseException;
|
29
|
+
|
30
|
+
import org.jruby.embed.ScriptingContainer;
|
31
|
+
import org.joda.time.DateTimeZone;
|
32
|
+
import org.msgpack.value.ArrayValue;
|
33
|
+
import org.msgpack.value.MapValue;
|
34
|
+
import org.msgpack.value.Value;
|
35
|
+
import org.msgpack.value.ValueFactory;
|
36
|
+
import org.slf4j.Logger;
|
37
|
+
|
38
|
+
import java.util.HashMap;
|
39
|
+
import java.util.List;
|
40
|
+
import java.util.ArrayList;
|
41
|
+
import java.util.Map;
|
42
|
+
import java.util.Objects;
|
43
|
+
|
44
|
+
public class TimestampFormatFilterPlugin implements FilterPlugin
|
45
|
+
{
|
46
|
+
private static final Logger logger = Exec.getLogger(TimestampFormatFilterPlugin.class);
|
47
|
+
|
48
|
+
public TimestampFormatFilterPlugin()
|
49
|
+
{
|
50
|
+
}
|
51
|
+
|
52
|
+
// NOTE: This is not spi.ColumnConfig
|
53
|
+
private interface ColumnConfig extends Task,
|
54
|
+
TimestampParser.TimestampColumnOption, TimestampFormatter.TimestampColumnOption
|
55
|
+
{
|
56
|
+
@Config("name")
|
57
|
+
String getName();
|
58
|
+
}
|
59
|
+
|
60
|
+
public interface PluginTask extends Task,
|
61
|
+
TimestampParser.Task, TimestampFormatter.Task
|
62
|
+
{
|
63
|
+
@Config("columns")
|
64
|
+
@ConfigDefault("[]")
|
65
|
+
List<ColumnConfig> getColumns();
|
66
|
+
|
67
|
+
@Config("stop_on_invalid_record")
|
68
|
+
@ConfigDefault("false")
|
69
|
+
Boolean getStopOnInvalidRecord();
|
70
|
+
|
71
|
+
@ConfigInject
|
72
|
+
ScriptingContainer getJRuby();
|
73
|
+
}
|
74
|
+
|
75
|
+
@Override
|
76
|
+
public void transaction(final ConfigSource config, final Schema inputSchema,
|
77
|
+
final FilterPlugin.Control control)
|
78
|
+
{
|
79
|
+
PluginTask task = config.loadConfig(PluginTask.class);
|
80
|
+
|
81
|
+
List<ColumnConfig> columns = task.getColumns();
|
82
|
+
|
83
|
+
if (columns.size() == 0) {
|
84
|
+
throw new ConfigException("\"columns\" must be specified.");
|
85
|
+
}
|
86
|
+
|
87
|
+
control.run(task.dump(), inputSchema);
|
88
|
+
}
|
89
|
+
|
90
|
+
private TimestampParser getTimestampParser(ColumnConfig columnConfig, PluginTask task)
|
91
|
+
{
|
92
|
+
List<TimestampParser> timestampParser = new ArrayList<TimestampParser>();
|
93
|
+
DateTimeZone timezone = columnConfig.getFromTimeZone().or(task.getDefaultFromTimeZone());
|
94
|
+
List<String> formatList = columnConfig.getFromFormat().or(task.getDefaultFromTimestampFormat());
|
95
|
+
return new TimestampParser(task.getJRuby(), formatList, timezone);
|
96
|
+
}
|
97
|
+
|
98
|
+
private TimestampFormatter getTimestampFormatter(ColumnConfig columnConfig, PluginTask task)
|
99
|
+
{
|
100
|
+
String format = columnConfig.getToFormat().or(task.getDefaultToTimestampFormat());
|
101
|
+
DateTimeZone timezone = columnConfig.getToTimeZone().or(task.getDefaultToTimeZone());
|
102
|
+
return new TimestampFormatter(task.getJRuby(), format, timezone);
|
103
|
+
}
|
104
|
+
|
105
|
+
@Override
|
106
|
+
public PageOutput open(final TaskSource taskSource, final Schema inputSchema,
|
107
|
+
final Schema outputSchema, final PageOutput output)
|
108
|
+
{
|
109
|
+
final PluginTask task = taskSource.loadTask(PluginTask.class);
|
110
|
+
|
111
|
+
// columnName => TimestampParser
|
112
|
+
final HashMap<String, TimestampParser> timestampParserMap = new HashMap<String, TimestampParser>();
|
113
|
+
for (ColumnConfig columnConfig : task.getColumns()) {
|
114
|
+
TimestampParser parser = getTimestampParser(columnConfig, task);
|
115
|
+
timestampParserMap.put(columnConfig.getName(), parser); // NOTE: value would be null
|
116
|
+
}
|
117
|
+
// columnName => TimestampFormatter
|
118
|
+
final HashMap<String, TimestampFormatter> timestampFormatterMap = new HashMap<String, TimestampFormatter>();
|
119
|
+
for (ColumnConfig columnConfig : task.getColumns()) {
|
120
|
+
TimestampFormatter parser = getTimestampFormatter(columnConfig, task);
|
121
|
+
timestampFormatterMap.put(columnConfig.getName(), parser); // NOTE: value would be null
|
122
|
+
}
|
123
|
+
|
124
|
+
return new PageOutput() {
|
125
|
+
private PageReader pageReader = new PageReader(inputSchema);
|
126
|
+
private PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, output);
|
127
|
+
private ColumnVisitorImpl visitor = new ColumnVisitorImpl(pageBuilder);
|
128
|
+
|
129
|
+
@Override
|
130
|
+
public void finish()
|
131
|
+
{
|
132
|
+
pageBuilder.finish();
|
133
|
+
}
|
134
|
+
|
135
|
+
@Override
|
136
|
+
public void close()
|
137
|
+
{
|
138
|
+
pageBuilder.close();
|
139
|
+
}
|
140
|
+
|
141
|
+
@Override
|
142
|
+
public void add(Page page)
|
143
|
+
{
|
144
|
+
pageReader.setPage(page);
|
145
|
+
|
146
|
+
while (pageReader.nextRecord()) {
|
147
|
+
outputSchema.visitColumns(visitor);
|
148
|
+
pageBuilder.addRecord();
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
public Value formatTimestampStringRecursively(PluginTask task, String name, Value value)
|
153
|
+
throws TimestampParseException
|
154
|
+
{
|
155
|
+
if (value.isArrayValue()) {
|
156
|
+
ArrayValue arrayValue = value.asArrayValue();
|
157
|
+
int size = arrayValue.size();
|
158
|
+
Value newValue[] = new Value[size];
|
159
|
+
for (int i = 0; i < size; i++) {
|
160
|
+
String k = new StringBuilder(name).append("[").append(Integer.toString(i)).append("]").toString();
|
161
|
+
Value v = arrayValue.get(i);
|
162
|
+
newValue[i] = formatTimestampStringRecursively(task, k, v);
|
163
|
+
}
|
164
|
+
return ValueFactory.newArray(newValue, true);
|
165
|
+
}
|
166
|
+
else if (value.isMapValue()) {
|
167
|
+
MapValue mapValue = value.asMapValue();
|
168
|
+
int size = mapValue.size() * 2;
|
169
|
+
Value newValue[] = new Value[size];
|
170
|
+
int i = 0;
|
171
|
+
for (Map.Entry<Value, Value> entry : mapValue.entrySet()) {
|
172
|
+
Value k = entry.getKey();
|
173
|
+
Value v = entry.getValue();
|
174
|
+
String newName = new StringBuilder(name).append(".").append(k.asStringValue().asString()).toString();
|
175
|
+
Value r = formatTimestampStringRecursively(task, newName, v);
|
176
|
+
newValue[i++] = k;
|
177
|
+
newValue[i++] = r;
|
178
|
+
}
|
179
|
+
return ValueFactory.newMap(newValue, true);
|
180
|
+
}
|
181
|
+
else if (value.isStringValue()) {
|
182
|
+
String stringValue = value.asStringValue().asString() ;
|
183
|
+
String newValue = formatTimestampString(task, name, stringValue);
|
184
|
+
return (Objects.equals(newValue, stringValue)) ? value : ValueFactory.newString(newValue);
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
return value;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
public String formatTimestampString(PluginTask task, String name, String value)
|
192
|
+
throws TimestampParseException
|
193
|
+
{
|
194
|
+
TimestampParser parser = timestampParserMap.get(name);
|
195
|
+
TimestampFormatter formatter = timestampFormatterMap.get(name);
|
196
|
+
if (formatter == null || parser == null) {
|
197
|
+
return value;
|
198
|
+
}
|
199
|
+
try {
|
200
|
+
Timestamp timestamp = parser.parse(value);
|
201
|
+
return formatter.format(timestamp);
|
202
|
+
}
|
203
|
+
catch (TimestampParseException ex) {
|
204
|
+
if (task.getStopOnInvalidRecord()) {
|
205
|
+
throw Throwables.propagate(ex);
|
206
|
+
} else {
|
207
|
+
logger.warn("invalid value \"{}\":\"{}\"", name, value);
|
208
|
+
return value;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
class ColumnVisitorImpl implements ColumnVisitor
|
214
|
+
{
|
215
|
+
private final PageBuilder pageBuilder;
|
216
|
+
|
217
|
+
ColumnVisitorImpl(PageBuilder pageBuilder) {
|
218
|
+
this.pageBuilder = pageBuilder;
|
219
|
+
}
|
220
|
+
|
221
|
+
@Override
|
222
|
+
public void booleanColumn(Column column)
|
223
|
+
{
|
224
|
+
if (pageReader.isNull(column)) {
|
225
|
+
pageBuilder.setNull(column);
|
226
|
+
} else {
|
227
|
+
pageBuilder.setBoolean(column, pageReader.getBoolean(column));
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
@Override
|
232
|
+
public void longColumn(Column column)
|
233
|
+
{
|
234
|
+
if (pageReader.isNull(column)) {
|
235
|
+
pageBuilder.setNull(column);
|
236
|
+
} else {
|
237
|
+
pageBuilder.setLong(column, pageReader.getLong(column));
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
@Override
|
242
|
+
public void doubleColumn(Column column)
|
243
|
+
{
|
244
|
+
if (pageReader.isNull(column)) {
|
245
|
+
pageBuilder.setNull(column);
|
246
|
+
} else {
|
247
|
+
pageBuilder.setDouble(column, pageReader.getDouble(column));
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
@Override
|
252
|
+
public void stringColumn(Column column)
|
253
|
+
{
|
254
|
+
if (pageReader.isNull(column)) {
|
255
|
+
pageBuilder.setNull(column);
|
256
|
+
return;
|
257
|
+
}
|
258
|
+
String value = pageReader.getString(column);
|
259
|
+
String formatted = formatTimestampString(task, column.getName(), value);
|
260
|
+
pageBuilder.setString(column, formatted);
|
261
|
+
}
|
262
|
+
|
263
|
+
@Override
|
264
|
+
public void jsonColumn(Column column)
|
265
|
+
{
|
266
|
+
if (pageReader.isNull(column)) {
|
267
|
+
pageBuilder.setNull(column);
|
268
|
+
}
|
269
|
+
else {
|
270
|
+
String name = new StringBuilder("$.").append(column.getName()).toString();
|
271
|
+
Value value = pageReader.getJson(column);
|
272
|
+
Value formatted = formatTimestampStringRecursively(task, name, value);
|
273
|
+
pageBuilder.setJson(column, formatted);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
@Override
|
278
|
+
public void timestampColumn(Column column)
|
279
|
+
{
|
280
|
+
if (pageReader.isNull(column)) {
|
281
|
+
pageBuilder.setNull(column);
|
282
|
+
} else {
|
283
|
+
pageBuilder.setTimestamp(column, pageReader.getTimestamp(column));
|
284
|
+
}
|
285
|
+
}
|
286
|
+
}
|
287
|
+
};
|
288
|
+
}
|
289
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
package org.embulk.filter.timestamp_format;
|
2
|
+
|
3
|
+
import java.util.Locale;
|
4
|
+
import org.jruby.embed.ScriptingContainer;
|
5
|
+
import org.joda.time.DateTime;
|
6
|
+
import org.joda.time.DateTimeZone;
|
7
|
+
import com.google.common.base.Optional;
|
8
|
+
import org.jruby.embed.ScriptingContainer;
|
9
|
+
import org.jruby.util.RubyDateFormat;
|
10
|
+
import org.embulk.config.Config;
|
11
|
+
import org.embulk.config.ConfigDefault;
|
12
|
+
import org.embulk.spi.util.LineEncoder;
|
13
|
+
import org.embulk.spi.time.Timestamp;
|
14
|
+
|
15
|
+
import org.embulk.filter.TimestampFormatFilterPlugin.PluginTask;
|
16
|
+
|
17
|
+
public class TimestampFormatter
|
18
|
+
{
|
19
|
+
public interface Task
|
20
|
+
{
|
21
|
+
@Config("default_to_timezone")
|
22
|
+
@ConfigDefault("\"UTC\"")
|
23
|
+
DateTimeZone getDefaultToTimeZone();
|
24
|
+
|
25
|
+
@Config("default_to_timestamp_format")
|
26
|
+
@ConfigDefault("\"%Y-%m-%d %H:%M:%S.%6N %z\"")
|
27
|
+
String getDefaultToTimestampFormat();
|
28
|
+
}
|
29
|
+
|
30
|
+
public interface TimestampColumnOption
|
31
|
+
{
|
32
|
+
@Config("to_timezone")
|
33
|
+
@ConfigDefault("null")
|
34
|
+
Optional<DateTimeZone> getToTimeZone();
|
35
|
+
|
36
|
+
@Config("to_format")
|
37
|
+
@ConfigDefault("null")
|
38
|
+
Optional<String> getToFormat();
|
39
|
+
}
|
40
|
+
|
41
|
+
private final RubyDateFormat toDateFormat;
|
42
|
+
private final DateTimeZone toTimeZone;
|
43
|
+
|
44
|
+
public TimestampFormatter(PluginTask task, Optional<? extends TimestampColumnOption> columnOption)
|
45
|
+
{
|
46
|
+
this(task.getJRuby(),
|
47
|
+
columnOption.isPresent() ?
|
48
|
+
columnOption.get().getToFormat().or(task.getDefaultToTimestampFormat())
|
49
|
+
: task.getDefaultToTimestampFormat(),
|
50
|
+
columnOption.isPresent() ?
|
51
|
+
columnOption.get().getToTimeZone().or(task.getDefaultToTimeZone())
|
52
|
+
: task.getDefaultToTimeZone());
|
53
|
+
}
|
54
|
+
|
55
|
+
public TimestampFormatter(ScriptingContainer jruby, String format, DateTimeZone toTimeZone)
|
56
|
+
{
|
57
|
+
this.toTimeZone = toTimeZone;
|
58
|
+
this.toDateFormat = new RubyDateFormat(format, Locale.ENGLISH, true);
|
59
|
+
}
|
60
|
+
|
61
|
+
public DateTimeZone getToTimeZone()
|
62
|
+
{
|
63
|
+
return toTimeZone;
|
64
|
+
}
|
65
|
+
|
66
|
+
public void format(Timestamp value, LineEncoder encoder)
|
67
|
+
{
|
68
|
+
// TODO optimize by directly appending to internal buffer
|
69
|
+
encoder.addText(format(value));
|
70
|
+
}
|
71
|
+
|
72
|
+
public String format(Timestamp value)
|
73
|
+
{
|
74
|
+
// TODO optimize by using reused StringBuilder
|
75
|
+
toDateFormat.setDateTime(new DateTime(value.getEpochSecond()*1000, toTimeZone));
|
76
|
+
toDateFormat.setNSec(value.getNano());
|
77
|
+
return toDateFormat.format(null);
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
package org.embulk.filter.timestamp_format;
|
2
|
+
|
3
|
+
import org.jruby.embed.ScriptingContainer;
|
4
|
+
import org.joda.time.DateTimeZone;
|
5
|
+
import com.google.common.base.Optional;
|
6
|
+
import org.embulk.config.Config;
|
7
|
+
import org.embulk.config.ConfigDefault;
|
8
|
+
import static org.embulk.spi.time.TimestampFormat.parseDateTimeZone;
|
9
|
+
import org.embulk.spi.time.Timestamp;
|
10
|
+
import org.embulk.spi.time.TimestampParseException;
|
11
|
+
import org.embulk.spi.time.JRubyTimeParserHelper;
|
12
|
+
import org.embulk.spi.time.JRubyTimeParserHelperFactory;
|
13
|
+
|
14
|
+
import org.embulk.filter.TimestampFormatFilterPlugin.PluginTask;
|
15
|
+
import java.util.List;
|
16
|
+
import java.util.ArrayList;
|
17
|
+
|
18
|
+
public class TimestampParser
|
19
|
+
{
|
20
|
+
public interface Task
|
21
|
+
{
|
22
|
+
@Config("default_from_timezone")
|
23
|
+
@ConfigDefault("\"UTC\"")
|
24
|
+
DateTimeZone getDefaultFromTimeZone();
|
25
|
+
|
26
|
+
@Config("default_from_timestamp_format")
|
27
|
+
@ConfigDefault("[\"%Y-%m-%d %H:%M:%S.%N %z\"]")
|
28
|
+
List<String> getDefaultFromTimestampFormat();
|
29
|
+
}
|
30
|
+
|
31
|
+
public interface TimestampColumnOption
|
32
|
+
{
|
33
|
+
@Config("from_timezone")
|
34
|
+
@ConfigDefault("null")
|
35
|
+
Optional<DateTimeZone> getFromTimeZone();
|
36
|
+
|
37
|
+
@Config("from_format")
|
38
|
+
@ConfigDefault("null")
|
39
|
+
Optional<List<String>> getFromFormat();
|
40
|
+
}
|
41
|
+
|
42
|
+
private final List<JRubyTimeParserHelper> helperList;
|
43
|
+
private final DateTimeZone defaultFromTimeZone;
|
44
|
+
|
45
|
+
TimestampParser(PluginTask task)
|
46
|
+
{
|
47
|
+
this(task.getJRuby(), task.getDefaultFromTimestampFormat(), task.getDefaultFromTimeZone());
|
48
|
+
}
|
49
|
+
|
50
|
+
public TimestampParser(PluginTask task, TimestampColumnOption columnOption)
|
51
|
+
{
|
52
|
+
this(task.getJRuby(),
|
53
|
+
columnOption.getFromFormat().or(task.getDefaultFromTimestampFormat()),
|
54
|
+
columnOption.getFromTimeZone().or(task.getDefaultFromTimeZone()));
|
55
|
+
}
|
56
|
+
|
57
|
+
public TimestampParser(ScriptingContainer jruby, List<String> formatList, DateTimeZone defaultFromTimeZone)
|
58
|
+
{
|
59
|
+
JRubyTimeParserHelperFactory helperFactory = (JRubyTimeParserHelperFactory) jruby.runScriptlet("Embulk::Java::TimeParserHelper::Factory.new");
|
60
|
+
// TODO get default current time from ExecTask.getExecTimestamp
|
61
|
+
this.helperList = new ArrayList<JRubyTimeParserHelper>();
|
62
|
+
for (String format : formatList) {
|
63
|
+
JRubyTimeParserHelper helper = (JRubyTimeParserHelper) helperFactory.newInstance(format, 1970, 1, 1, 0, 0, 0, 0); // TODO default time zone
|
64
|
+
this.helperList.add(helper);
|
65
|
+
}
|
66
|
+
this.defaultFromTimeZone = defaultFromTimeZone;
|
67
|
+
}
|
68
|
+
|
69
|
+
public DateTimeZone getDefaultFromTimeZone()
|
70
|
+
{
|
71
|
+
return defaultFromTimeZone;
|
72
|
+
}
|
73
|
+
|
74
|
+
public Timestamp parse(String text) throws TimestampParseException
|
75
|
+
{
|
76
|
+
JRubyTimeParserHelper helper = null;
|
77
|
+
long localUsec = -1;
|
78
|
+
TimestampParseException exception = null;
|
79
|
+
|
80
|
+
for (JRubyTimeParserHelper h : helperList) {
|
81
|
+
helper = h;
|
82
|
+
try {
|
83
|
+
localUsec = helper.strptimeUsec(text);
|
84
|
+
} catch (TimestampParseException ex) {
|
85
|
+
exception = ex;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
if (localUsec == -1) {
|
89
|
+
throw exception;
|
90
|
+
}
|
91
|
+
String zone = helper.getZone();
|
92
|
+
|
93
|
+
DateTimeZone timeZone = defaultFromTimeZone;
|
94
|
+
if (zone != null) {
|
95
|
+
// TODO cache parsed zone?
|
96
|
+
timeZone = parseDateTimeZone(zone);
|
97
|
+
if (timeZone == null) {
|
98
|
+
throw new TimestampParseException("Invalid time zone name '" + text + "'");
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
long localSec = localUsec / 1000000;
|
103
|
+
long usec = localUsec % 1000000;
|
104
|
+
long sec = timeZone.convertLocalToUTC(localSec*1000, false) / 1000;
|
105
|
+
|
106
|
+
return Timestamp.ofEpochSecond(sec, usec * 1000);
|
107
|
+
}
|
108
|
+
}
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-filter-timestamp_format
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naotoshi Seo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.0'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '10.0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: embulk-parser-jsonl
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
description: A filter plugin for Embulk to change timestamp format.
|
56
|
+
email:
|
57
|
+
- sonots@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- CHANGELOG.md
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- build.gradle
|
68
|
+
- config/checkstyle/checkstyle.xml
|
69
|
+
- example/example.jsonl
|
70
|
+
- example/example.yml
|
71
|
+
- gradle/wrapper/gradle-wrapper.jar
|
72
|
+
- gradle/wrapper/gradle-wrapper.properties
|
73
|
+
- gradlew
|
74
|
+
- gradlew.bat
|
75
|
+
- lib/embulk/filter/timestamp_format.rb
|
76
|
+
- src/main/java/org/embulk/filter/TimestampFormatFilterPlugin.java
|
77
|
+
- src/main/java/org/embulk/filter/timestamp_format/TimestampFormatter.java
|
78
|
+
- src/main/java/org/embulk/filter/timestamp_format/TimestampParser.java
|
79
|
+
- src/test/java/org/embulk/filter/TestTimestampFormatFilterPlugin.java
|
80
|
+
- classpath/embulk-filter-timestamp_format-0.1.0.jar
|
81
|
+
homepage: https://github.com/sonots/embulk-filter-timestamp_format
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata:
|
85
|
+
allowed_push_host: https://rubygems.dena.jp
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.1.9
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: A filter plugin for Embulk to change timestamp format
|
106
|
+
test_files: []
|