embulk-output-vertica 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +5 -0
- data/embulk-output-vertica.gemspec +19 -0
- data/example.csv +2 -0
- data/example.yml +15 -0
- data/lib/embulk/output/vertica.rb +119 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b5979942b9ed3ae9f640b1150f9a05679e2f4ce
|
4
|
+
data.tar.gz: 0af6db714dc9fa90258c6f3ff5587847037e43ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb62e8c19e59aa31f71659db45a5c4a6c840540b6b074483e79f3ff9f844ace4d283a351877c4cbfaadce82fda3dc07425704e2101fdb16ff9e6c3988bfa5d25
|
7
|
+
data.tar.gz: e559a967086ae51ccd02f0dd95c8acb4f362c410edae12ebd972f6e17c5bd22a7edc5ba278e54b48e073643f331df0d04b06d05bb4b57f1f4bb1bfef96027cef
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 eiji.sekiya
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Vertica output plugin for Embulk
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
* **Plugin type**: output
|
6
|
+
* **Load all or nothing**: no
|
7
|
+
* **Resume supported**: no
|
8
|
+
* **Cleanup supported**: yes
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
- **host**: hostname (string, default: localhost)
|
13
|
+
- **port**: port number (integer, default: 5433)
|
14
|
+
- **username**: username (string, required)
|
15
|
+
- **password**: password (string, default: '')
|
16
|
+
- **database**: database name (string, default: vdb)
|
17
|
+
- **schema**: schema name (string, default: public)
|
18
|
+
- **table**: table name (string, required)
|
19
|
+
|
20
|
+
## Example
|
21
|
+
|
22
|
+
```yaml
|
23
|
+
out:
|
24
|
+
type: vertica
|
25
|
+
host: 127.0.0.1
|
26
|
+
username: dbadmin
|
27
|
+
password: xxxxxxx
|
28
|
+
database: vdb
|
29
|
+
schema: sandbox
|
30
|
+
table: embulk_test
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
Run example:
|
37
|
+
|
38
|
+
```
|
39
|
+
$ embulk gem install embulk-input-random
|
40
|
+
$ embulk gem install jvertica
|
41
|
+
$ embulk run -I lib example.yml
|
42
|
+
```
|
43
|
+
|
44
|
+
Release gem:
|
45
|
+
|
46
|
+
```
|
47
|
+
$ bundle exec rake release
|
48
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "embulk-output-vertica"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["eiji.sekiya", "Naotoshi Seo"]
|
5
|
+
spec.email = ["eiji.sekiya.0326@gmail.com", "sonots@gmail.com"]
|
6
|
+
spec.summary = "Vertica output plugin for Embulk"
|
7
|
+
spec.description = "Dump records to vertica"
|
8
|
+
spec.homepage = "https://github.com/eratostennis/embulk-plugin-vertica"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
spec.files = `git ls-files -z`.split("\x0")
|
12
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_dependency "jvertica", "~> 0.2"
|
17
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
18
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
19
|
+
end
|
data/example.csv
ADDED
data/example.yml
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'jvertica'
|
2
|
+
|
3
|
+
module Embulk
|
4
|
+
module Output
|
5
|
+
class Vertica < OutputPlugin
|
6
|
+
Plugin.register_output('vertica', self)
|
7
|
+
|
8
|
+
class Error < StandardError; end
|
9
|
+
class NotSupportedType < Error; end
|
10
|
+
|
11
|
+
def self.transaction(config, schema, processor_count, &control)
|
12
|
+
task = {
|
13
|
+
'host' => config.param('host', :string, :default => 'localhost'),
|
14
|
+
'port' => config.param('port', :integer, :default => 5433),
|
15
|
+
'username' => config.param('username', :string),
|
16
|
+
'password' => config.param('password', :string, :default => ''),
|
17
|
+
'database' => config.param('database', :string, :default => 'vdb'),
|
18
|
+
'schema' => config.param('schema', :string, :default => 'public'),
|
19
|
+
'table' => config.param('table', :string),
|
20
|
+
}
|
21
|
+
|
22
|
+
now = Time.now
|
23
|
+
unique_name = "%08x%08x" % [now.tv_sec, now.tv_nsec]
|
24
|
+
task['temp_table'] = "#{task['table']}_LOAD_TEMP_#{unique_name}"
|
25
|
+
|
26
|
+
sql_schema = self.to_vertica_schema schema
|
27
|
+
|
28
|
+
connect(task) do |jv|
|
29
|
+
# drop table if exists "DEST"
|
30
|
+
# 'create table if exists "TEMP" ("COL" json)'
|
31
|
+
jv.query %[drop table if exists #{task['schema']}.#{task['temp_table']}]
|
32
|
+
jv.query %[create table #{task['schema']}.#{task['temp_table']} (#{sql_schema})]
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
yield(task)
|
37
|
+
connect(task) do |jv|
|
38
|
+
# create table if not exists "DEST" ("COL" json)
|
39
|
+
# 'insert into "DEST" ("COL") select "COL" from "TEMP"'
|
40
|
+
jv.query %[create table if not exists #{task['schema']}.#{task['table']} (#{sql_schema})]
|
41
|
+
jv.query %[insert into #{task['schema']}.#{task['table']} select * from #{task['schema']}.#{task['temp_table']}]
|
42
|
+
jv.commit
|
43
|
+
end
|
44
|
+
ensure
|
45
|
+
connect(task) do |jv|
|
46
|
+
# 'drop table if exists TEMP'
|
47
|
+
jv.query %[drop table if exists #{task['schema']}.#{task['temp_table']}]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.connect(task)
|
54
|
+
jv = ::Jvertica.connect({
|
55
|
+
host: task['host'],
|
56
|
+
port: task['port'],
|
57
|
+
user: task['username'],
|
58
|
+
password: task['password'],
|
59
|
+
database: task['database'],
|
60
|
+
})
|
61
|
+
|
62
|
+
if block_given?
|
63
|
+
begin
|
64
|
+
yield jv
|
65
|
+
ensure
|
66
|
+
jv.close
|
67
|
+
end
|
68
|
+
end
|
69
|
+
jv
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.to_vertica_schema(schema)
|
73
|
+
schema.names.zip(schema.types)
|
74
|
+
.map { |name, type| "#{name} #{to_sql_type(type)}" }
|
75
|
+
.join(',')
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.to_sql_type(type)
|
79
|
+
case type
|
80
|
+
when :boolean then 'BOOLEAN'
|
81
|
+
when :long then 'INT'
|
82
|
+
when :double then 'FLOAT'
|
83
|
+
when :string then 'VARCHAR'
|
84
|
+
when :timestamp then 'TIMESTAMP'
|
85
|
+
else raise NotSupportedType, "embulk-output-vertica cannot take column type #{type}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def initialize(task, schema, index)
|
90
|
+
super
|
91
|
+
@jv = self.class.connect(task)
|
92
|
+
end
|
93
|
+
|
94
|
+
def close
|
95
|
+
@jv.close
|
96
|
+
end
|
97
|
+
|
98
|
+
def add(page)
|
99
|
+
sql = "COPY #{@task['schema']}.#{@task['temp_table']} FROM STDIN DELIMITER ',' NO COMMIT"
|
100
|
+
@jv.copy(sql) do |stdin|
|
101
|
+
page.each_with_index do |record, idx|
|
102
|
+
stdin << record.map {|v| ::Jvertica.quote(v) }.join(",") << "\n"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
@jv.commit
|
106
|
+
end
|
107
|
+
|
108
|
+
def finish
|
109
|
+
end
|
110
|
+
|
111
|
+
def abort
|
112
|
+
end
|
113
|
+
|
114
|
+
def commit
|
115
|
+
{}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-output-vertica
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- eiji.sekiya
|
8
|
+
- Naotoshi Seo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
name: jvertica
|
21
|
+
prerelease: false
|
22
|
+
type: :runtime
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
name: bundler
|
35
|
+
prerelease: false
|
36
|
+
type: :development
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.7'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
name: rake
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
description: Dump records to vertica
|
57
|
+
email:
|
58
|
+
- eiji.sekiya.0326@gmail.com
|
59
|
+
- sonots@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-output-vertica.gemspec
|
70
|
+
- example.csv
|
71
|
+
- example.yml
|
72
|
+
- lib/embulk/output/vertica.rb
|
73
|
+
homepage: https://github.com/eratostennis/embulk-plugin-vertica
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Vertica output plugin for Embulk
|
97
|
+
test_files: []
|