embulk-output-vertica 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 758fc8b31ffadedaf028b5775fd8820867e2998b
4
- data.tar.gz: 8be72ce20cfe83be5f9d7ef827f81a0c9691cfec
3
+ metadata.gz: ff28392e54434eac04115cb7bd4f8822befe9dfc
4
+ data.tar.gz: 7f072f39b7046ab26347bb940a0974565836ae46
5
5
  SHA512:
6
- metadata.gz: 08188e9dcc7209b7317e8b4256eca1e262dcd5759d44a43a4223ea5ebb6dac8a7f205140d789816de2b1032dc95e0074a074c6e85f107e43beb7450be855614e
7
- data.tar.gz: c7184dd4edae3f1a4c988e1ae62442ff634b72765e805e590fa365bb698594fd00e6ef5bf4ea98b39ffc2cec756726c3c2034e171f3f33d65e76446005499736
6
+ metadata.gz: d8ef85915db3658ff923913a6d2d1c78ee02c7752192f94f8518e63af50644865c4f5aa159b7edc369cf3c568fa08cfbdb305f864a0a5705930c0566faccc3e1
7
+ data.tar.gz: b929a4e1d49d336272b8659c44d6fa199ef802ff85829ba554b184a3efa4593378a1d1b2e8b1f1f5c1515e9153ff338b2a6fd857fecae51bfd58f4ea3f0ae584
data/CHANGELOG.md CHANGED
@@ -1,8 +1,12 @@
1
- # 0.2.7 (2015/11/06)
1
+ # 0.2.8 (2015/11/06)
2
2
 
3
3
  Enhancements:
4
4
 
5
- * Get sql schema information from existing table unless REPLACE mode
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.7"
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
- sql_schema ||= self.existing_sql_schema(task) unless task['mode'] == 'REPLACE'
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} (#{sql_schema_expression})])
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 a temp table
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.to_sql_schema(schema, column_options)
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 = to_sql_type(type)
175
+ sql_type = sql_type_from_embulk_type(type)
175
176
  end
176
177
  [column_name, sql_type]
177
- end.to_h
178
+ end
179
+ sql_schema.map {|name, type| "#{::Jvertica.quote_identifier(name)} #{type}" }.join(',')
178
180
  end
179
181
 
180
- def self.to_sql_type(type)
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
- # Get sql schema if table exists
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]] }.to_h
202
+ sql_schema = result.map {|row| [row[0], row[1]] }
202
203
  end
203
- Embulk.logger.info "embulk-output-vertica: existing_sql_schema: #{sql_schema}"
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-vertica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - eiji.sekiya