embulk-output-vertica 0.2.7 → 0.2.8
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 +4 -4
- data/CHANGELOG.md +6 -2
- data/embulk-output-vertica.gemspec +1 -1
- data/lib/embulk/output/vertica.rb +22 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff28392e54434eac04115cb7bd4f8822befe9dfc
|
4
|
+
data.tar.gz: 7f072f39b7046ab26347bb940a0974565836ae46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8ef85915db3658ff923913a6d2d1c78ee02c7752192f94f8518e63af50644865c4f5aa159b7edc369cf3c568fa08cfbdb305f864a0a5705930c0566faccc3e1
|
7
|
+
data.tar.gz: b929a4e1d49d336272b8659c44d6fa199ef802ff85829ba554b184a3efa4593378a1d1b2e8b1f1f5c1515e9153ff338b2a6fd857fecae51bfd58f4ea3f0ae584
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
# 0.2.
|
1
|
+
# 0.2.8 (2015/11/06)
|
2
2
|
|
3
3
|
Enhancements:
|
4
4
|
|
5
|
-
* Get sql schema
|
5
|
+
* Get sql schema from the existing target table to create internal temporary tables to avoid schema conflicts
|
6
|
+
|
7
|
+
# 0.2.7 (2015/11/06)
|
8
|
+
|
9
|
+
Skipped
|
6
10
|
|
7
11
|
# 0.2.6 (2015/11/06)
|
8
12
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "embulk-output-vertica"
|
3
|
-
spec.version = "0.2.
|
3
|
+
spec.version = "0.2.8"
|
4
4
|
spec.authors = ["eiji.sekiya", "Naotoshi Seo"]
|
5
5
|
spec.email = ["eiji.sekiya.0326@gmail.com", "sonots@gmail.com"]
|
6
6
|
spec.summary = "Vertica output plugin for Embulk"
|
@@ -50,28 +50,29 @@ module Embulk
|
|
50
50
|
quoted_table = ::Jvertica.quote_identifier(task['table'])
|
51
51
|
quoted_temp_table = ::Jvertica.quote_identifier(task['temp_table'])
|
52
52
|
|
53
|
-
|
54
|
-
sql_schema ||= self.to_sql_schema(schema, task['column_options'])
|
55
|
-
sql_schema_expression = sql_schema.map {|name, type| "#{::Jvertica.quote_identifier(name)} #{type}" }.join(',')
|
53
|
+
sql_schema_table = self.sql_schema_from_embulk_schema(schema, task['column_options'])
|
56
54
|
|
55
|
+
# create the target table
|
56
|
+
connect(task) do |jv|
|
57
|
+
query(jv, %[DROP TABLE IF EXISTS #{quoted_schema}.#{quoted_table}]) if task['mode'] == 'REPLACE'
|
58
|
+
query(jv, %[CREATE TABLE IF NOT EXISTS #{quoted_schema}.#{quoted_table} (#{sql_schema_table})])
|
59
|
+
end
|
60
|
+
|
61
|
+
sql_schema_temp_table = self.sql_schema_from_table(task)
|
62
|
+
|
63
|
+
# create a temp table
|
57
64
|
connect(task) do |jv|
|
58
|
-
# create a temp table
|
59
65
|
query(jv, %[DROP TABLE IF EXISTS #{quoted_schema}.#{quoted_temp_table}])
|
60
|
-
query(jv, %[CREATE TABLE #{quoted_schema}.#{quoted_temp_table} (#{
|
66
|
+
query(jv, %[CREATE TABLE #{quoted_schema}.#{quoted_temp_table} (#{sql_schema_temp_table})])
|
61
67
|
end
|
62
68
|
|
63
69
|
begin
|
64
|
-
# insert data into
|
70
|
+
# insert data into the temp table
|
65
71
|
task_reports = yield(task) # obtain an array of task_reports where one report is of a task
|
66
72
|
Embulk.logger.info { "embulk-output-vertica: task_reports: #{task_reports.to_json}" }
|
67
73
|
|
74
|
+
# insert select from the temp table
|
68
75
|
connect(task) do |jv|
|
69
|
-
# create the target table if not exists or mode == replace
|
70
|
-
if task['mode'] == 'REPLACE'
|
71
|
-
query(jv, %[DROP TABLE IF EXISTS #{quoted_schema}.#{quoted_table}])
|
72
|
-
end
|
73
|
-
query(jv, %[CREATE TABLE IF NOT EXISTS #{quoted_schema}.#{quoted_table} (#{sql_schema_expression})])
|
74
|
-
# insert select from the temp table
|
75
76
|
query(jv, %[INSERT INTO #{quoted_schema}.#{quoted_table} SELECT * FROM #{quoted_schema}.#{quoted_temp_table}])
|
76
77
|
jv.commit
|
77
78
|
end
|
@@ -166,18 +167,19 @@ module Embulk
|
|
166
167
|
# @param [Schema] schema embulk defined column types
|
167
168
|
# @param [Hash] column_options user defined column types
|
168
169
|
# @return [String] sql schema used to CREATE TABLE
|
169
|
-
def self.
|
170
|
-
schema.names.zip(schema.types).map do |column_name, type|
|
170
|
+
def self.sql_schema_from_embulk_schema(schema, column_options)
|
171
|
+
sql_schema = schema.names.zip(schema.types).map do |column_name, type|
|
171
172
|
if column_options[column_name] and column_options[column_name]['type']
|
172
173
|
sql_type = column_options[column_name]['type']
|
173
174
|
else
|
174
|
-
sql_type =
|
175
|
+
sql_type = sql_type_from_embulk_type(type)
|
175
176
|
end
|
176
177
|
[column_name, sql_type]
|
177
|
-
end
|
178
|
+
end
|
179
|
+
sql_schema.map {|name, type| "#{::Jvertica.quote_identifier(name)} #{type}" }.join(',')
|
178
180
|
end
|
179
181
|
|
180
|
-
def self.
|
182
|
+
def self.sql_type_from_embulk_type(type)
|
181
183
|
case type
|
182
184
|
when :boolean then 'BOOLEAN'
|
183
185
|
when :long then 'INT' # BIGINT is a synonym for INT in vertica
|
@@ -188,8 +190,7 @@ module Embulk
|
|
188
190
|
end
|
189
191
|
end
|
190
192
|
|
191
|
-
|
192
|
-
def self.existing_sql_schema(task)
|
193
|
+
def self.sql_schema_from_table(task)
|
193
194
|
quoted_schema = Jvertica.quote(task['schema'])
|
194
195
|
quoted_table = Jvertica.quote(task['table'])
|
195
196
|
sql = "SELECT column_name, data_type FROM v_catalog.columns " \
|
@@ -198,10 +199,9 @@ module Embulk
|
|
198
199
|
sql_schema = {}
|
199
200
|
connect(task) do |jv|
|
200
201
|
result = query(jv, sql)
|
201
|
-
sql_schema = result.map {|row| [row[0], row[1]] }
|
202
|
+
sql_schema = result.map {|row| [row[0], row[1]] }
|
202
203
|
end
|
203
|
-
|
204
|
-
sql_schema.empty? ? nil : sql_schema
|
204
|
+
sql_schema.map {|name, type| "#{::Jvertica.quote_identifier(name)} #{type}" }.join(',')
|
205
205
|
end
|
206
206
|
|
207
207
|
def self.query(conn, sql)
|