embulk-filter-expand_csv_array 0.1.2
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 +5 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +3 -0
- data/embulk-filter-expand_csv_array.gemspec +19 -0
- data/lib/embulk/filter/expand_csv_array.rb +56 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ab74ecd5c11ec14e33e1f679705cde6a0ad31180c702b04bf74df010c83f828c
|
4
|
+
data.tar.gz: 43ce48ba9fcf8a52928bf5425769e51d20f91aa3768b5b2661f0b162e393e02b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2f4b578ad7c8f1b434011bacc13d4b9522b4f58e504ea98b22a5d3072c76f53ae984d60dc2cc1b754b4a2adaebf6bae858aa95db55421f9148ef1c9335aa437
|
7
|
+
data.tar.gz: 2e9ec4ed62f43d74bcd0158dfab82f9454ee1195de4c9cb7dafad067424d79888d3bd727387f7b797fc48f43cada456a5d052c049aca1aec44c97ec3a70ac3b1
|
data/Gemfile
ADDED
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,62 @@
|
|
1
|
+
# Expand CSV Array filter plugin for Embulk
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
* **Plugin type**: filter
|
6
|
+
|
7
|
+
This is a embulk plugin for expanding record which has csv column includes `N`-size array to `N` records.
|
8
|
+
|
9
|
+
For example, plugin expands below record which has csv column `csv_value` includes size-3 array value to 3 records.
|
10
|
+
|
11
|
+
Before:
|
12
|
+
|
13
|
+
```
|
14
|
+
+------+-----------+------+
|
15
|
+
| col1 | col2 | col3 |
|
16
|
+
+------+-----------+------+
|
17
|
+
| 1 | 1,2,3,4,5 | test |
|
18
|
+
+------+-----------+------+
|
19
|
+
```
|
20
|
+
|
21
|
+
Filtered:
|
22
|
+
|
23
|
+
```
|
24
|
+
+------+-------+
|
25
|
+
| col1 | col2 |
|
26
|
+
+------+-------+
|
27
|
+
| 1 | 1 |
|
28
|
+
+------+-------+
|
29
|
+
| 1 | 2 |
|
30
|
+
+------+-------+
|
31
|
+
| 1 | 3 |
|
32
|
+
+------+-------+
|
33
|
+
| 1 | 4 |
|
34
|
+
+------+-------+
|
35
|
+
| 1 | 5 |
|
36
|
+
+------+-------+
|
37
|
+
```
|
38
|
+
|
39
|
+
## Configuration
|
40
|
+
|
41
|
+
- **csv_column_name**: column of csv value in record (string , required)
|
42
|
+
- **column_names**: output column names
|
43
|
+
|
44
|
+
## Example
|
45
|
+
|
46
|
+
```yaml
|
47
|
+
filters:
|
48
|
+
- type: expand_csv_array
|
49
|
+
csv_column_name: col2
|
50
|
+
column_names: [col1, col2]
|
51
|
+
```
|
52
|
+
|
53
|
+
## Build
|
54
|
+
|
55
|
+
```
|
56
|
+
$ rake
|
57
|
+
```
|
58
|
+
|
59
|
+
## Reference
|
60
|
+
|
61
|
+
- [ainoya/embulk-filter-expand_json_array](https://github.com/ainoya/embulk-filter-expand_json_array)
|
62
|
+
- [civitaspo/embulk-filter-expand_json](https://github.com/civitaspo/embulk-filter-expand_json)
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-filter-expand_csv_array"
|
4
|
+
spec.version = "0.1.2"
|
5
|
+
spec.authors = ["SNakano", "Naoki AINOYA"]
|
6
|
+
spec.summary = "Expand CSV Array filter plugin for Embulk"
|
7
|
+
spec.description = "Expand CSV Array"
|
8
|
+
spec.email = ["s.nakano@guppy.co.jp", "ainonic@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/SNakano/embulk-filter-expand_csv_array"
|
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_development_dependency 'embulk', ['~> 0.8.13']
|
17
|
+
spec.add_development_dependency 'bundler', ['~> 1.10.6']
|
18
|
+
spec.add_development_dependency 'rake', ['~> 10.0']
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Embulk
|
4
|
+
module Filter
|
5
|
+
class ExpandCsvArray < FilterPlugin
|
6
|
+
Plugin.register_filter("expand_csv_array", self)
|
7
|
+
|
8
|
+
def self.transaction(config, in_schema, &control)
|
9
|
+
# configuration code:
|
10
|
+
task = {
|
11
|
+
"csv_column_name" => config.param("csv_column_name", :string),
|
12
|
+
"column_names" => config.param("column_names", :array, default: [])
|
13
|
+
}
|
14
|
+
|
15
|
+
task["target"] = in_schema.find {|c| c.name == task['csv_column_name']}
|
16
|
+
task["columns"] = in_schema.select {|c| task["column_names"].include?(c.name) }
|
17
|
+
|
18
|
+
out_columns = in_schema.select do |col|
|
19
|
+
col if task["column_names"].find { |n| n == col.name }
|
20
|
+
end
|
21
|
+
|
22
|
+
yield(task, out_columns)
|
23
|
+
end
|
24
|
+
|
25
|
+
def init
|
26
|
+
# initialization code:
|
27
|
+
@csv_column_name = task["csv_column_name"]
|
28
|
+
@columns = task["columns"]
|
29
|
+
@target = task["target"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def close
|
33
|
+
end
|
34
|
+
|
35
|
+
def add(page)
|
36
|
+
# filtering code:
|
37
|
+
page.each do |record|
|
38
|
+
record[@target["index"]].parse_csv.each do |val|
|
39
|
+
data = @columns.map do |f|
|
40
|
+
if f["index"] == @target["index"]
|
41
|
+
val
|
42
|
+
else
|
43
|
+
record[f["index"]]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
page_builder.add(data)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def finish
|
52
|
+
page_builder.finish
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-filter-expand_csv_array
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SNakano
|
8
|
+
- Naoki AINOYA
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-02-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: embulk
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.8.13
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.8.13
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.10.6
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.10.6
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
description: Expand CSV Array
|
57
|
+
email:
|
58
|
+
- s.nakano@guppy.co.jp
|
59
|
+
- ainonic@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- embulk-filter-expand_csv_array.gemspec
|
70
|
+
- lib/embulk/filter/expand_csv_array.rb
|
71
|
+
homepage: https://github.com/SNakano/embulk-filter-expand_csv_array
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Expand CSV Array filter plugin for Embulk
|
94
|
+
test_files: []
|