embulk-output-vertica 0.1.2 → 0.1.3

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: 452d0c45a1e7f46e91cce223618aeffc0141c902
4
- data.tar.gz: 16e2bc4294f270f3df7c92243ce28b2ac56f2801
3
+ metadata.gz: 1316243ed313380058a701d08ef37a034d54fa57
4
+ data.tar.gz: 1e88fcd58409f47a8114759f3f25e23702b7b303
5
5
  SHA512:
6
- metadata.gz: 2538b4999f2ea7c7c8ab64c5f1aa5fa90f8dbd7bfc258643c59b00713fdd675bc29654b8c37a07d22cc29e7f9f08db03536de6e4236b14426963c0769f834607
7
- data.tar.gz: 0b9a30e215cf0836160e252cf2b77d4e4dc5223b8a5ed1c492b2fc0e16d02bcff26696a61b5c8e23e379a822f416828ea3c29d8700dfe5c62b2f6f4f13af5e0a
6
+ metadata.gz: d705ccab43c8394f6933e463acb8b05010849853eaba47978ef6f1eb86e79d0b685cd6099b1cc2b3735acce143dd1cfe90fb2e76bf7e4fd8074b8f5ce7cabf3b
7
+ data.tar.gz: 9bbf3719c8e2b1b915536cb7a5527613351bca648652f59ba1586279cb276784e106dab5d45baf4cee261f675fa468107516c4cbb4885239da2d697aeff66391
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.1.3 (2015/07/05)
2
+
3
+ Enhancements:
4
+
5
+ * Escape schama, table names
6
+ * Add `abort_on_error` option
7
+
1
8
  # 0.1.2 (2015/06/26)
2
9
 
3
10
  Enhancements:
data/README.md CHANGED
@@ -17,6 +17,7 @@
17
17
  - **schema**: schema name (string, default: public)
18
18
  - **table**: table name (string, required)
19
19
  - **copy_mode**: specifies how data is loaded into the database. (`AUTO`, `DIRECT`, or `TRICKLE`. default: AUTO)
20
+ - **abort_on_error**: Stops the COPY command if a row is rejected and rolls back the command. No data is loaded. (bool, default: false)
20
21
  - **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
21
22
  - **type**: type of a column when this plugin creates new tables (e.g. VARCHAR(255), INTEGER NOT NULL UNIQUE). This used when this plugin creates intermediate tables (insert and truncate_insert modes), and when it creates nonexistent target table automatically. (string, default: depends on input column type. INT (same with BIGINT in vertica) if input column type is long, BOOLEAN if boolean, FLOAT (same with DOUBLE PRECISION in vertica) if double, VARCHAR if string, TIMESTAMP if timestamp)
22
23
 
@@ -32,6 +33,7 @@ out:
32
33
  schema: sandbox
33
34
  table: embulk_test
34
35
  copy_mode: DIRECT
36
+ abort_on_error: true
35
37
  column_options:
36
38
  id: {type: INT}
37
39
  name: {type: VARCHAR(255)}
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "embulk-output-vertica"
3
- spec.version = "0.1.2"
3
+ spec.version = "0.1.3"
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"
@@ -18,6 +18,7 @@ module Embulk
18
18
  'schema' => config.param('schema', :string, :default => 'public'),
19
19
  'table' => config.param('table', :string),
20
20
  'copy_mode' => config.param('copy_mode', :string, :default => 'AUTO'),
21
+ 'abort_on_error' => config.param('abort_on_error', :bool, :default => false),
21
22
  'column_options' => config.param('column_options', :hash, :default => {}),
22
23
  }
23
24
 
@@ -29,13 +30,17 @@ module Embulk
29
30
  unique_name = "%08x%08x" % [now.tv_sec, now.tv_nsec]
30
31
  task['temp_table'] = "#{task['table']}_LOAD_TEMP_#{unique_name}"
31
32
 
32
- sql_schema = self.to_vertica_schema(schema, task['column_options'])
33
+ sql_schema = self.to_sql_schema(schema, task['column_options'])
34
+
35
+ quoted_schema = ::Jvertica.quote_identifier(task['schema'])
36
+ quoted_table = ::Jvertica.quote_identifier(task['table'])
37
+ quoted_temp_table = ::Jvertica.quote_identifier(task['temp_table'])
33
38
 
34
39
  connect(task) do |jv|
35
40
  # drop table if exists "DEST"
36
41
  # 'create table if exists "TEMP" ("COL" json)'
37
- jv.query %[drop table if exists #{task['schema']}.#{task['temp_table']}]
38
- jv.query %[create table #{task['schema']}.#{task['temp_table']} (#{sql_schema})]
42
+ jv.query %[drop table if exists #{quoted_schema}.#{quoted_temp_table}]
43
+ jv.query %[create table #{quoted_schema}.#{quoted_temp_table} (#{sql_schema})]
39
44
  end
40
45
 
41
46
  begin
@@ -43,14 +48,14 @@ module Embulk
43
48
  connect(task) do |jv|
44
49
  # create table if not exists "DEST" ("COL" json)
45
50
  # 'insert into "DEST" ("COL") select "COL" from "TEMP"'
46
- jv.query %[create table if not exists #{task['schema']}.#{task['table']} (#{sql_schema})]
47
- jv.query %[insert into #{task['schema']}.#{task['table']} select * from #{task['schema']}.#{task['temp_table']}]
51
+ jv.query %[create table if not exists #{quoted_schema}.#{quoted_table} (#{sql_schema})]
52
+ jv.query %[insert into #{quoted_schema}.#{quoted_table} select * from #{quoted_schema}.#{quoted_temp_table}]
48
53
  jv.commit
49
54
  end
50
55
  ensure
51
56
  connect(task) do |jv|
52
57
  # 'drop table if exists TEMP'
53
- jv.query %[drop table if exists #{task['schema']}.#{task['temp_table']}]
58
+ jv.query %[drop table if exists #{quoted_schema}.#{quoted_temp_table}]
54
59
  end
55
60
  end
56
61
  return {}
@@ -75,11 +80,14 @@ module Embulk
75
80
  jv
76
81
  end
77
82
 
78
- def self.to_vertica_schema(schema, column_options)
79
- schema.names.zip(schema.types).map do |name, type|
80
- sql_type = (column_options[name] and column_options[name]['type']) ?
81
- column_options[name]['type'] : to_sql_type(type)
82
- "#{name} #{sql_type}"
83
+ # @param [Schema] schema embulk defined column types
84
+ # @param [Hash] column_options user defined column types
85
+ # @return [String] sql schema used to CREATE TABLE
86
+ def self.to_sql_schema(schema, column_options)
87
+ schema.names.zip(schema.types).map do |column_name, type|
88
+ sql_type = (column_options[column_name] and column_options[column_name]['type']) ?
89
+ column_options[column_name]['type'] : to_sql_type(type)
90
+ "#{::Jvertica.quote_identifier(column_name)} #{sql_type}"
83
91
  end.join(',')
84
92
  end
85
93
 
@@ -104,9 +112,7 @@ module Embulk
104
112
  end
105
113
 
106
114
  def add(page)
107
- sql = "COPY #{@task['schema']}.#{@task['temp_table']} FROM STDIN DELIMITER ',' #{@task['copy_mode']} NO COMMIT"
108
- Embulk.logger.debug sql
109
- @jv.copy(sql) do |stdin|
115
+ @jv.copy(copy_sql) do |stdin|
110
116
  page.each_with_index do |record, idx|
111
117
  stdin << record.map {|v| ::Jvertica.quote(v) }.join(",") << "\n"
112
118
  end
@@ -123,6 +129,18 @@ module Embulk
123
129
  def commit
124
130
  {}
125
131
  end
132
+
133
+ private
134
+
135
+ def copy_sql
136
+ quoted_schema = ::Jvertica.quote_identifier(@task['schema'])
137
+ quoted_temp_table = ::Jvertica.quote_identifier(@task['temp_table'])
138
+ copy_mode = @task['copy_mode']
139
+ abort_on_error = @task['abort_on_error'] ? ' ABORT ON ERROR' : ''
140
+ sql = "COPY #{quoted_schema}.#{quoted_temp_table} FROM STDIN DELIMITER ',' #{copy_mode}#{abort_on_error} NO COMMIT"
141
+ Embulk.logger.debug sql
142
+ sql
143
+ end
126
144
  end
127
145
  end
128
146
  end
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - eiji.sekiya
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-26 00:00:00.000000000 Z
12
+ date: 2015-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement