embulk-input-inline 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93a6a268daeca69dfe717bcf9fcd663410a6c42a
4
+ data.tar.gz: a6428b5470002ea77093e925a0cce8e671c741cc
5
+ SHA512:
6
+ metadata.gz: 8e46adc5786b564f9864c5a84d0f866c400e26ad774ea074780489b26b580b01211bccae003ef1efe7f0338087a061fd160ec60e30901be9ab0e84d7c198be3d
7
+ data.tar.gz: e75a580a82ff1ea0f28c8ae3d76146af5aab97817dfffe8af414f6f68218f2a7c07e6a875dda5c76eef55a19f1f4bc7840409ff67d53d18363d1099b6f8a3ef2
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-9.0.4.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
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,61 @@
1
+ # Inline input plugin for Embulk
2
+
3
+ Inline input plugin for Embulk.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: input
8
+ * **Resume supported**: no
9
+ * **Cleanup supported**: no
10
+ * **Guess supported**: no
11
+
12
+ ## Configuration
13
+
14
+ - **schema**: embulk schema (array, required)
15
+ - **name**: column name (string, required)
16
+ - **type**: column type (string, required)
17
+ - **data**: input data (array, required)
18
+
19
+ ## Example
20
+
21
+ ```yaml
22
+ in:
23
+ type: inline
24
+ schema:
25
+ - { name: long_column, type: long }
26
+ - { name: string_column, type: string }
27
+ - { name: double_column, type: double }
28
+ - { name: boolean_column, type: boolean }
29
+ - { name: json_column, type: json }
30
+ - { name: timestamp_column, type: timestamp }
31
+ data:
32
+ - { long_column: 1, string_column: test, json_column: { id: 1, name: toyama }, double_column: 0.1, boolean_column: true, timestamp_column: '2016-06-14 15:19:05' }
33
+ - { long_column: 2, string_column: test, json_column: { id: 2, name: toyama }, double_column: 0.1, boolean_column: true, timestamp_column: '2016-06-14 15:19:05' }
34
+ - { long_column: 3, string_column: test, json_column: { id: 3, name: toyama }, double_column: 0.1, boolean_column: true, timestamp_column: '2016-06-14 15:19:05' }
35
+ - {}
36
+ - { long_column: 4 }
37
+
38
+ out:
39
+ type: stdout
40
+ ```
41
+
42
+ ### Output
43
+ ```
44
+ 2016-06-14 15:40:47.724 +0900: Embulk v0.8.9
45
+ 2016-06-14 15:40:49.046 +0900 [INFO] (0001:preview): Loaded plugin embulk/input/inline from a load path
46
+ +------------------+----------------------+----------------------+------------------------+--------------------------+----------------------------+
47
+ | long_column:long | string_column:string | double_column:double | boolean_column:boolean | json_column:json | timestamp_column:timestamp |
48
+ +------------------+----------------------+----------------------+------------------------+--------------------------+----------------------------+
49
+ | 1 | test | 0.1 | true | {"id":1,"name":"toyama"} | 2016-06-14 06:19:05 UTC |
50
+ | 2 | test | 0.1 | true | {"id":2,"name":"toyama"} | 2016-06-14 06:19:05 UTC |
51
+ | 3 | test | 0.1 | true | {"id":3,"name":"toyama"} | 2016-06-14 06:19:05 UTC |
52
+ | | | | | | |
53
+ | 4 | | | | | |
54
+ +------------------+----------------------+----------------------+------------------------+--------------------------+----------------------------+
55
+ ```
56
+
57
+ ## Build
58
+
59
+ ```
60
+ $ rake
61
+ ```
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,19 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-input-inline"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["toyama0919"]
6
+ spec.summary = "Inline Yaml input plugin for Embulk"
7
+ spec.description = "Loads records from Yaml Inline."
8
+ spec.email = ["toyama0919@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/toyama0919/embulk-input-inline"
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.9']
17
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
18
+ spec.add_development_dependency 'rake', ['>= 10.0']
19
+ end
@@ -0,0 +1,78 @@
1
+ module Embulk
2
+ module Input
3
+
4
+ class Inline < InputPlugin
5
+ Plugin.register_input("inline", self)
6
+
7
+ def self.transaction(config, &control)
8
+ task = {
9
+ "schema" => config.param("schema", :array),
10
+ "data" => config.param("data", :array)
11
+ }
12
+
13
+ columns = task['schema'].map.with_index { |column, i|
14
+ Column.new(i, column['name'], column['type'].to_sym)
15
+ }
16
+
17
+ resume(task, columns, 1, &control)
18
+ end
19
+
20
+ def self.resume(task, columns, count, &control)
21
+ task_reports = yield(task, columns, count)
22
+
23
+ next_config_diff = {}
24
+ return next_config_diff
25
+ end
26
+
27
+ def init
28
+ @data = task["data"]
29
+ end
30
+
31
+ def run
32
+ @data.each do |record|
33
+ values = schema.map { |column|
34
+ convert_value(column.type, record[column.name])
35
+ }
36
+ page_builder.add(values)
37
+ end
38
+ page_builder.finish
39
+
40
+ task_report = {}
41
+ return task_report
42
+ end
43
+
44
+ private
45
+
46
+ def convert_value(type, value)
47
+ return nil if value.nil?
48
+ case type
49
+ when :string
50
+ value
51
+ when :long
52
+ value.to_i
53
+ when :double
54
+ value.to_f
55
+ when :boolean
56
+ if value.is_a?(TrueClass) || value.is_a?(FalseClass)
57
+ value
58
+ else
59
+ downcased_val = value.downcase
60
+ case downcased_val
61
+ when 'true' then true
62
+ when 'false' then false
63
+ when '1' then true
64
+ when '0' then false
65
+ else nil
66
+ end
67
+ end
68
+ when :timestamp
69
+ Time.parse(value)
70
+ when :json
71
+ value
72
+ else
73
+ raise "Unsupported type #{field['type']}"
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-input-inline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - toyama0919
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.8.9
19
+ name: embulk
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.9
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.10.6
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.10.6
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Loads records from Yaml Inline.
56
+ email:
57
+ - toyama0919@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-version"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - embulk-input-inline.gemspec
69
+ - lib/embulk/input/inline.rb
70
+ homepage: https://github.com/toyama0919/embulk-input-inline
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.8
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Inline Yaml input plugin for Embulk
94
+ test_files: []