embulk-filter-eval 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 +8 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +3 -0
- data/embulk-filter-eval.gemspec +19 -0
- data/lib/embulk/filter/eval.rb +77 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9b2be8a156962385ff464dde3a9e94ccaa44ef0
|
4
|
+
data.tar.gz: b08d79f589eccd4cc5964a56da97f926bdc31d07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd8870e83e0d12641268dd335387c1f754208d9fa8a0f6e284337d2a51159b067a9309930c7b1f2a524a758e59175d93467c9035e7a42db9104b8cf614f6068a
|
7
|
+
data.tar.gz: 13d7de4f06a8b0b6daac59a23766fc6541a4635763d84e06006c67f6fdf1ec33f59b393a00c4cd3e9c7c1e94e0b74b41c398f7517f0e9c5198eff4ff0a0ec9af
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 MOGI Hiromu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
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,63 @@
|
|
1
|
+
# Eval filter plugin for Embulk
|
2
|
+
|
3
|
+
Evaluate the row element by ruby code
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
* **Plugin type**: filter
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
* **eval_columns**: (array)
|
12
|
+
* The ruby code to be evaluated for each element
|
13
|
+
* **out_columns**: (array)
|
14
|
+
* The column to be output from the input columns
|
15
|
+
|
16
|
+
## Example
|
17
|
+
|
18
|
+
```
|
19
|
+
$ embulk example
|
20
|
+
$ embulk guess embulk-example/example.yml -o config.yml
|
21
|
+
$ embulk preview config.yml
|
22
|
+
|
23
|
+
+---------+--------------+-------------------------+-------------------------+----------------------------+
|
24
|
+
| id:long | account:long | time:timestamp | purchase:timestamp | comment:string |
|
25
|
+
+---------+--------------+-------------------------+-------------------------+----------------------------+
|
26
|
+
| 1 | 32,864 | 2015-01-27 19:23:49 UTC | 2015-01-27 00:00:00 UTC | embulk |
|
27
|
+
| 2 | 14,824 | 2015-01-27 19:01:23 UTC | 2015-01-27 00:00:00 UTC | embulk jruby |
|
28
|
+
| 3 | 27,559 | 2015-01-28 02:20:02 UTC | 2015-01-28 00:00:00 UTC | Embulk "csv" parser plugin |
|
29
|
+
| 4 | 11,270 | 2015-01-29 11:54:36 UTC | 2015-01-29 00:00:00 UTC | NULL |
|
30
|
+
+---------+--------------+-------------------------+-------------------------+----------------------------+
|
31
|
+
```
|
32
|
+
|
33
|
+
config.yml as follows
|
34
|
+
|
35
|
+
```yaml
|
36
|
+
filters:
|
37
|
+
- type: eval
|
38
|
+
eval_columns:
|
39
|
+
- id: value + 1
|
40
|
+
- account:
|
41
|
+
- time: Time.now
|
42
|
+
- comment: "'Evil is Evil! ' + value"
|
43
|
+
```
|
44
|
+
|
45
|
+
`value` is an element of the column.
|
46
|
+
Such as sample, output will be this.
|
47
|
+
|
48
|
+
```
|
49
|
+
+---------+--------------+-----------------------------+-------------------------+------------------------------------------+
|
50
|
+
| id:long | account:long | time:timestamp | purchase:timestamp | comment:string |
|
51
|
+
+---------+--------------+-----------------------------+-------------------------+------------------------------------------+
|
52
|
+
| 2 | 32,864 | 2015-03-13 13:20:18.753 UTC | 2015-01-27 00:00:00 UTC | Evil is Evil! embulk |
|
53
|
+
| 3 | 14,824 | 2015-03-13 13:20:18.754 UTC | 2015-01-27 00:00:00 UTC | Evil is Evil! embulk jruby |
|
54
|
+
| 4 | 27,559 | 2015-03-13 13:20:18.755 UTC | 2015-01-28 00:00:00 UTC | Evil is Evil! Embulk "csv" parser plugin |
|
55
|
+
| 5 | 11,270 | 2015-03-13 13:20:18.756 UTC | 2015-01-29 00:00:00 UTC | Evil is Evil! NULL |
|
56
|
+
+---------+--------------+-----------------------------+-------------------------+------------------------------------------+
|
57
|
+
```
|
58
|
+
|
59
|
+
## Build
|
60
|
+
|
61
|
+
```
|
62
|
+
$ rake
|
63
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-filter-eval"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["mgi166"]
|
6
|
+
spec.summary = "Eval filter plugin for Embulk"
|
7
|
+
spec.description = "Eval"
|
8
|
+
spec.email = ["skskoari@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/mgi166/embulk-filter-eval"
|
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,77 @@
|
|
1
|
+
module Embulk
|
2
|
+
module Filter
|
3
|
+
|
4
|
+
class EvalFilterPlugin < FilterPlugin
|
5
|
+
Plugin.register_filter("eval", self)
|
6
|
+
|
7
|
+
class NotFoundOutColumn < StandardError; end;
|
8
|
+
VERSION = '0.1.0'
|
9
|
+
|
10
|
+
def self.transaction(config, in_schema, &control)
|
11
|
+
# configuration code:
|
12
|
+
task = {
|
13
|
+
"eval_columns" => config.param("eval_columns", :array, default: []),
|
14
|
+
"out_columns" => config.param("out_columns", :array, default: [])
|
15
|
+
}
|
16
|
+
|
17
|
+
out_schema = out_schema(task['out_columns'], in_schema)
|
18
|
+
|
19
|
+
yield(task, out_schema)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.out_schema(out_columns, in_schema)
|
23
|
+
schema = out_columns.map.with_index do |name, i|
|
24
|
+
sch = in_schema.find { |sch| sch.name == name }
|
25
|
+
|
26
|
+
unless sch
|
27
|
+
raise NotFoundOutSchema, "Not found output schema: `#{name}'"
|
28
|
+
end
|
29
|
+
|
30
|
+
Embulk::Column.new(index: i, name: sch.name, type: sch.type, format: sch.format)
|
31
|
+
end
|
32
|
+
schema.empty? ? in_schema : schema
|
33
|
+
end
|
34
|
+
|
35
|
+
def init
|
36
|
+
@table = task["eval_columns"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def close
|
40
|
+
end
|
41
|
+
|
42
|
+
def add(page)
|
43
|
+
page.each do |record|
|
44
|
+
begin
|
45
|
+
record = hash_record(record)
|
46
|
+
|
47
|
+
result = {}
|
48
|
+
|
49
|
+
record.each do |key, value|
|
50
|
+
source = @table.find do |t|
|
51
|
+
t.key?(key)
|
52
|
+
end
|
53
|
+
|
54
|
+
if source && source = source[key]
|
55
|
+
result[key] = eval(source)
|
56
|
+
else
|
57
|
+
result[key] = value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
page_builder.add(result.values)
|
62
|
+
rescue
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def finish
|
68
|
+
page_builder.finish
|
69
|
+
end
|
70
|
+
|
71
|
+
def hash_record(record)
|
72
|
+
Hash[in_schema.names.zip(record)]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-filter-eval
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mgi166
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Eval
|
42
|
+
email:
|
43
|
+
- skskoari@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- embulk-filter-eval.gemspec
|
55
|
+
- lib/embulk/filter/eval.rb
|
56
|
+
homepage: https://github.com/mgi166/embulk-filter-eval
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Eval filter plugin for Embulk
|
80
|
+
test_files: []
|