embulk-input-rediskeys 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +3 -0
- data/embulk-input-rediskeys.gemspec +20 -0
- data/lib/embulk/input/rediskeys.rb +132 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5527062cdeec1dd043b1575d971b5b963d05d9bb
|
4
|
+
data.tar.gz: f9d04b386626c6441a0e7627133f4e3f9cee9fc4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1119f58adbff986d095542f4f5fa9006021783de02a0abb719f348446bc13f3450ee83f810b6a79be9c14dc500edc5b31eadc6bc52de5831ee3d6ccd01f24a0d
|
7
|
+
data.tar.gz: ea95c97378cd2366fb4535e2b275ceb14b5506b960c2663af1b35e1d91b47c97471775a33e56724fe7a18e3fab8f3dfffbb9bdba304072ae95bac5021772c004
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.0.4.0
|
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,35 @@
|
|
1
|
+
# Redis input plugin for Embulk
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
* **Plugin type**: input
|
6
|
+
* **Resume supported**: yes
|
7
|
+
* **Cleanup supported**: yes
|
8
|
+
* **Guess supported**: no
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
- host: Redis hostname (string, default:localhost).
|
13
|
+
- port: Redis port number (int, default: 6379).
|
14
|
+
- db: Number of Redis DB to dump columns (int, default: 0).
|
15
|
+
- key_prefix: Prefix of column name to read (string, required).
|
16
|
+
- encode: Type of eoncoding of data to read (string, default:json).
|
17
|
+
|
18
|
+
## Example
|
19
|
+
|
20
|
+
```yaml
|
21
|
+
in:
|
22
|
+
type: rediskeys
|
23
|
+
host: localhost
|
24
|
+
port: 6379
|
25
|
+
db: 0
|
26
|
+
key_prefix: test_key
|
27
|
+
encode: json
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
## Build
|
32
|
+
|
33
|
+
```
|
34
|
+
$ rake
|
35
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-input-rediskeys"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["dokuma"]
|
6
|
+
spec.summary = "Redis input plugin for Embulk"
|
7
|
+
spec.description = "Loads records from Redis."
|
8
|
+
spec.email = ["dokuma.h@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/dokuma/embulk-input-rediskeys"
|
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 'redis', ['>= 3.0.5']
|
17
|
+
spec.add_development_dependency 'embulk', ['>= 0.8.9']
|
18
|
+
spec.add_development_dependency 'bundler', ['>= 1.10.6']
|
19
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
20
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module Embulk
|
2
|
+
module Input
|
3
|
+
|
4
|
+
class Redis < InputPlugin
|
5
|
+
require 'redis'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
Plugin.register_input("rediskeys", self)
|
9
|
+
|
10
|
+
def self.transaction(config, &control)
|
11
|
+
# configuration code:
|
12
|
+
task = {
|
13
|
+
'host' => config.param('host', :string, :default => 'localhost'),
|
14
|
+
'port' => config.param('port', :integer, :default => 6379),
|
15
|
+
'db' => config.param('db', :integer, :default => 0),
|
16
|
+
'key_prefix' => config.param('key_prefix', :string, :default => ''),
|
17
|
+
'encode' => config.param('encode', :string, :default => 'json')
|
18
|
+
}
|
19
|
+
|
20
|
+
redis = ::Redis.new(:host => task['host'], :port => task['port'], :db => task['db'])
|
21
|
+
keys = redis.keys("#{task['key_prefix']}*").inject([]){|col, k|
|
22
|
+
col.push({'name' => k, 'type' => 'string'})
|
23
|
+
col
|
24
|
+
}
|
25
|
+
puts "keys:#{keys}"
|
26
|
+
|
27
|
+
task['columns'] = config.param('columns', :array, :default => keys).inject({}){|a, col|
|
28
|
+
a[col['name']] = col['type'].to_sym
|
29
|
+
a
|
30
|
+
}
|
31
|
+
|
32
|
+
columns = task['columns'].map.with_index{|(name, type), i|
|
33
|
+
Column.new(i, name, type)
|
34
|
+
}
|
35
|
+
|
36
|
+
#resume(task, columns, 1, &control)
|
37
|
+
puts "Redis input started."
|
38
|
+
task_reports = yield(task, columns, 1)
|
39
|
+
puts "Redis input finished. Commit reports = #{task_reports.to_json}"
|
40
|
+
|
41
|
+
return {}
|
42
|
+
end
|
43
|
+
|
44
|
+
# def self.resume(task, columns, count, &control)
|
45
|
+
# task_reports = yield(task, columns, count)
|
46
|
+
#
|
47
|
+
# next_config_diff = {}
|
48
|
+
# return next_config_diff
|
49
|
+
# end
|
50
|
+
|
51
|
+
# TODO
|
52
|
+
#def self.guess(config)
|
53
|
+
# sample_records = [
|
54
|
+
# {"example"=>"a", "column"=>1, "value"=>0.1},
|
55
|
+
# {"example"=>"a", "column"=>2, "value"=>0.2},
|
56
|
+
# ]
|
57
|
+
# columns = Guess::SchemaGuess.from_hash_records(sample_records)
|
58
|
+
# return {"columns" => columns}
|
59
|
+
#end
|
60
|
+
|
61
|
+
def init
|
62
|
+
# initialization code:
|
63
|
+
puts "Redis input thread #{index}..."
|
64
|
+
super
|
65
|
+
@rows = 0
|
66
|
+
@redis = ::Redis.new(:host => task['host'], :port => task['port'], :db => task['db'])
|
67
|
+
end
|
68
|
+
|
69
|
+
def deserialize_element(name, x)
|
70
|
+
begin
|
71
|
+
type = nil
|
72
|
+
@task['columns'].each do |key, value|
|
73
|
+
if key == name
|
74
|
+
type = value
|
75
|
+
break
|
76
|
+
end
|
77
|
+
end
|
78
|
+
val = x
|
79
|
+
case type.to_sym # Converted to String implicitly?
|
80
|
+
when :boolean
|
81
|
+
if val.is_a?(TrueClass) || val.is_a?(FalseClass)
|
82
|
+
val
|
83
|
+
else
|
84
|
+
downcased_val = val.downcase
|
85
|
+
case downcased_val
|
86
|
+
when 'true' then true
|
87
|
+
when 'false' then false
|
88
|
+
else nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
when :long
|
92
|
+
Integer(val)
|
93
|
+
when :double
|
94
|
+
Float(val)
|
95
|
+
when :string
|
96
|
+
val
|
97
|
+
when :timestamp
|
98
|
+
Time.parse(val)
|
99
|
+
else
|
100
|
+
raise "Shouldn't reach here: val:#{val}, col_name:#{name}, col_type:#{type}"
|
101
|
+
end
|
102
|
+
rescue => e
|
103
|
+
STDERR.puts "Failed to deserialize: val:#{val}, col_name:#{name}, col_type:#{type}, error:#{e.inspect}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def run
|
108
|
+
records = []
|
109
|
+
@redis.keys("#{@task['key_prefix']}*").each do |k|
|
110
|
+
case @task['encode']
|
111
|
+
when 'json'
|
112
|
+
v = @redis.get(k)
|
113
|
+
when 'hash'
|
114
|
+
v = @redis.hgetall(k).to_json
|
115
|
+
end
|
116
|
+
v = "{\"#{k}\":#{v}}"
|
117
|
+
x = JSON.parse(v)
|
118
|
+
records.push(deserialize_element(k, x))
|
119
|
+
@rows += 1
|
120
|
+
end
|
121
|
+
@page_builder.add(records)
|
122
|
+
@page_builder.finish # don't forget to call finish :-)
|
123
|
+
|
124
|
+
task_report = {
|
125
|
+
"rows" => @rows
|
126
|
+
}
|
127
|
+
return task_report
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-input-rediskeys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- dokuma
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: embulk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.9
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.9
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.10.6
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.10.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Loads records from Redis.
|
70
|
+
email:
|
71
|
+
- dokuma.h@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- embulk-input-rediskeys.gemspec
|
83
|
+
- lib/embulk/input/rediskeys.rb
|
84
|
+
homepage: https://github.com/dokuma/embulk-input-rediskeys
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.5.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Redis input plugin for Embulk
|
108
|
+
test_files: []
|