embulk-output-vertica 0.1.6 → 0.1.7

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: 3f78066cc105d0aa31d8fe9a70f9166facdef222
4
- data.tar.gz: 9f60547ac77c5f54461722b907f8fafd5c32000c
3
+ metadata.gz: daadcaba0204e6e4c1103f4edd8e5b3c6b70924f
4
+ data.tar.gz: 339ab9e6350031e1325ac69d2773f45bc6f7e0b0
5
5
  SHA512:
6
- metadata.gz: 9fee2ba24167506cfe0ef7fbae612361ecc15bc42d35bbee245d0221f573742434768e8b49f11a62332ee8c8e8475e26d44fcce4259b963e459bb36c9f2c39d8
7
- data.tar.gz: 257182e4efed2b0ef43b955ab989bcd658a9d14b5efb09dc56106c1dd1a7f68e6080414c91e534c5c4db480a29a54accff892bd63d6522fe7e72c6f5940aa3d0
6
+ metadata.gz: ecec7a142322fdff6596c3359fb67949235d8082ae626e491df8ed5cce55961777eb7715cb69a7d12243f3305ec97595a97c3e820188f6198f3a68e43595e01f
7
+ data.tar.gz: 7d17307369af315a30ab296aad4bb94da6ff08806db4f73fef541c1aa710326a7e251804e730004c854be97a68a194059306867b484f607af7864e02210e9bd5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.1.7 (2015/07/25)
2
+
3
+ Enhancements:
4
+
5
+ * Add reject_on_materialized_type_error option
6
+
1
7
  # 0.1.6 (2015/07/24)
2
8
 
3
9
  Enhancements:
data/README.md CHANGED
@@ -19,13 +19,14 @@
19
19
  - **mode**: "insert", or "replace". See bellow. (string, default: insert)
20
20
  - **copy_mode**: specifies how data is loaded into the database. (`AUTO`, `DIRECT`, or `TRICKLE`. default: AUTO) See vertica documents for details.
21
21
  - **abort_on_error**: Stops the COPY command if a row is rejected and rolls back the command. No data is loaded. (bool, default: false)
22
+ - **reject_on_materialized_type_error**: Use `reject_on_materialized_type_error` option for fjsonparser(). This rejects rows if any of olumn types and value types do not fit. ex) double value into INT column fails. See vertica documents for details. (bool, default: false)
22
23
  - **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
23
24
  - **type**: type of a column when this plugin creates new tables such as `VARCHAR(255)`, `INTEGER NOT NULL UNIQUE`. This is used on creating intermediate tables (insert and truncate_insert modes) and on creating a new target table. (string, default: depends on input column type, see below)
24
- - `INT` (same with `BIGINT` in vertica) for `long`
25
- - `BOOLEAN` for `boolean`
26
- - `FLOAT` (same with `DOUBLE PRECISION` in vertica) for `double`
27
- - `VARCHAR` for `string`
28
- - `TIMESTAMP` for `timestamp`
25
+ - long: `INT` (same with `BIGINT` in vertica)
26
+ - boolean: `BOOLEAN`
27
+ - double: `FLOAT` (same with `DOUBLE PRECISION` in vertica)
28
+ - string: `VARCHAR`
29
+ - timestamp: `TIMESTAMP`
29
30
 
30
31
  ### Modes
31
32
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "embulk-output-vertica"
3
- spec.version = "0.1.6"
3
+ spec.version = "0.1.7"
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"
data/example.yml CHANGED
@@ -30,7 +30,10 @@ out:
30
30
  database: vdb
31
31
  schema: sandbox
32
32
  table: embulk_test
33
+ mode: replace
33
34
  copy_mode: direct
35
+ abort_on_error: true
36
+ reject_on_materialized_type_error: true
34
37
  column_options:
35
38
  date: {type: DATE}
36
39
  id: {type: INT}
@@ -20,6 +20,7 @@ module Embulk
20
20
  'mode' => config.param('mode', :string, :default => 'insert'),
21
21
  'copy_mode' => config.param('copy_mode', :string, :default => 'AUTO'),
22
22
  'abort_on_error' => config.param('abort_on_error', :bool, :default => false),
23
+ 'reject_on_materialized_type_error' => config.param('reject_on_materialized_type_error', :bool, :default => false),
23
24
  'column_options' => config.param('column_options', :hash, :default => {}),
24
25
  }
25
26
 
@@ -59,7 +60,7 @@ module Embulk
59
60
  ensure
60
61
  connect(task) do |jv|
61
62
  query(jv, %[DROP TABLE IF EXISTS #{quoted_schema}.#{quoted_temp_table}])
62
- Embulk.logger.debug { query(jv, %[SELECT * FROM #{quoted_schema}.#{quoted_table} LIMIT 10]).map {|row| row.to_h }.join("\n") rescue nil }
63
+ Embulk.logger.debug { "embulk-output-vertica: #{query(jv, %[SELECT * FROM #{quoted_schema}.#{quoted_table} LIMIT 10]).map {|row| row.to_h }.join("\n") rescue nil}" }
63
64
  end
64
65
  end
65
66
  return {}
@@ -75,12 +76,25 @@ module Embulk
75
76
  end
76
77
 
77
78
  def add(page)
78
- copy(@jv, copy_sql) do |stdin|
79
- page.each do |record|
80
- stdin << to_json(record) << "\n"
79
+ json = nil # for log
80
+ begin
81
+ copy(@jv, copy_sql) do |stdin|
82
+ page.each do |record|
83
+ json = to_json(record)
84
+ stdin << json << "\n"
85
+ end
86
+ end
87
+ Embulk.logger.debug "embulk-output-vertica: COMMIT!"
88
+ @jv.commit
89
+ rescue java.sql.SQLDataException => e
90
+ @jv.rollback
91
+ if @task['reject_on_materialized_type_error'] and e.message =~ /Rejected by user-defined parser/
92
+ Embulk.logger.warn "embulk-output-vertica: ROLLBACK! some of column types and values types do not fit #{json}"
93
+ else
94
+ Embulk.logger.warn "embulk-output-vertica: ROLLBACK!"
81
95
  end
96
+ raise e
82
97
  end
83
- @jv.commit
84
98
  end
85
99
 
86
100
  def finish
@@ -154,7 +168,7 @@ module Embulk
154
168
  end
155
169
 
156
170
  def copy_sql
157
- @copy_sql ||= "COPY #{quoted_schema}.#{quoted_temp_table} FROM STDIN PARSER fjsonparser() #{copy_mode}#{abort_on_error} NO COMMIT"
171
+ @copy_sql ||= "COPY #{quoted_schema}.#{quoted_temp_table} FROM STDIN#{fjsonparser}#{copy_mode}#{abort_on_error} NO COMMIT"
158
172
  end
159
173
 
160
174
  def to_json(record)
@@ -174,13 +188,20 @@ module Embulk
174
188
  end
175
189
 
176
190
  def copy_mode
177
- @task['copy_mode']
191
+ " #{@task['copy_mode']}"
178
192
  end
179
193
 
180
194
  def abort_on_error
181
195
  @task['abort_on_error'] ? ' ABORT ON ERROR' : ''
182
196
  end
183
197
 
198
+ def fjsonparser
199
+ " PARSER fjsonparser(#{reject_on_materialized_type_error})"
200
+ end
201
+
202
+ def reject_on_materialized_type_error
203
+ @task['reject_on_materialized_type_error'] ? 'reject_on_materialized_type_error=true' : ''
204
+ end
184
205
  end
185
206
  end
186
207
  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.6
4
+ version: 0.1.7
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-07-23 00:00:00.000000000 Z
12
+ date: 2015-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement