bricolage-streamingload 0.11.0 → 0.12.0

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: 338d44b3bf3b51f784bb6a2984c60ec8ef9338d9
4
- data.tar.gz: 46fb68569a99af0f28243871d36949e78cc89f63
3
+ metadata.gz: c8c9c822c1c2d207827cc5d0b6573140254b1638
4
+ data.tar.gz: 166188b17014074c82a963aa9aecaff796ced70d
5
5
  SHA512:
6
- metadata.gz: 5d512c32008682db824b92b7907da884a356f65e86bdc1abdce55345196d1eb1116528a65c7b27cb12e76a8dc9961ce9d46f0121ab2310a01152b540d75b2567
7
- data.tar.gz: bd06304e4a2602d13fa30b912ed1bfda941718165b8f2776c14a64b0d4ff616bf19348d017c767f35fa6d48758fab8c378b7b5ca3b86d0e774f7df84600bb55a
6
+ metadata.gz: 17e35b2d5d49312d92a4f9f7e232cd6ff9daeb7975d7a1383936a935d12dd22c89550e1fece87920c36cac46fea6aa5517431c7af56e741cb5fe774a21cd7825
7
+ data.tar.gz: 7556f6eb45b74d041891f3d9254aee4bf32c30d12e9aa61093351f5a08af4c7f6a04926b75a37d8cfbde4c359a50e5efc610cd6ceda605f63ca147e3d96d3285
@@ -86,8 +86,8 @@ module Bricolage
86
86
  end
87
87
 
88
88
  if @task.unknown_state?
89
- true_status = DataConnection.open(@data_ds, @logger) {|data|
90
- data.get_job_status(@log_table, @task.last_job_id)
89
+ true_status = DataConnection.open(@data_ds, log_table: @log_table, logger: @logger) {|data|
90
+ data.get_job_status(@task.last_job_id)
91
91
  }
92
92
  @logger.info "fixiating unknown job status: job_id=#{@task.last_job_id}, status=(unknown->#{true_status})"
93
93
  @task.fix_last_job_status true_status
@@ -142,11 +142,14 @@ module Bricolage
142
142
  params = JobParams.load(@context, task.task_class, task.schema_name, task.table_name)
143
143
  @data_ds = params.ds
144
144
  @manifest = ManifestFile.create(ds: params.ctl_bucket, job_id: job_id, object_urls: task.object_urls, logger: @logger)
145
- DataConnection.open(params.ds, @logger) {|data|
145
+ log = LoadLog.new
146
+ log.task_id = @task_id
147
+ log.job_id = job_id
148
+ DataConnection.open(params.ds, log_table: @log_table, logger: @logger) {|data|
146
149
  if params.enable_work_table?
147
- data.load_with_work_table params.work_table, @manifest, params.load_options_string, params.sql_source, @log_table, job_id
150
+ data.load_with_work_table params.work_table, @manifest, params.load_options_string, params.sql_source, log
148
151
  else
149
- data.load_objects params.dest_table, @manifest, params.load_options_string, @log_table, job_id
152
+ data.load_objects params.dest_table, @manifest, params.load_options_string, log
150
153
  end
151
154
  }
152
155
  end
@@ -175,18 +178,22 @@ module Bricolage
175
178
  end
176
179
 
177
180
 
181
+ LoadLog = Struct.new(:task_id, :job_id)
182
+
183
+
178
184
  class DataConnection
179
185
 
180
186
  include SQLUtils
181
187
 
182
- def DataConnection.open(ds, logger = ds.logger, &block)
183
- new(ds, logger).open(&block)
188
+ def DataConnection.open(ds, log_table:, logger: ds.logger, &block)
189
+ new(ds, log_table: log_table, logger: logger).open(&block)
184
190
  end
185
191
 
186
- def initialize(ds, logger = ds.logger)
192
+ def initialize(ds, log_table:, logger: ds.logger)
187
193
  @ds = ds
188
- @connection = nil
194
+ @log_table = log_table
189
195
  @logger = logger
196
+ @connection = nil
190
197
  end
191
198
 
192
199
  def open(&block)
@@ -198,27 +205,27 @@ module Bricolage
198
205
  raise DataConnectionFailed, "data connection failed: #{ex.message}"
199
206
  end
200
207
 
201
- def get_job_status(log_table, job_id)
202
- count = @connection.query_value("select count(*) from #{log_table} where job_id = #{job_id}")
208
+ def get_job_status(job_id)
209
+ count = @connection.query_value("select count(*) from #{@log_table} where job_id = #{job_id}")
203
210
  count.to_i > 0 ? 'success' : 'failure'
204
211
  end
205
212
 
206
- def load_with_work_table(work_table, manifest, options, sql_source, log_table, job_id)
213
+ def load_with_work_table(work_table, manifest, options, sql_source, log)
207
214
  @connection.transaction {|txn|
208
215
  # NOTE: This transaction ends with truncation, this DELETE does nothing
209
216
  # from the second time. So don't worry about DELETE cost here.
210
217
  @connection.execute("delete from #{work_table}")
211
218
  execute_copy work_table, manifest, options
212
219
  @connection.execute sql_source
213
- write_load_log log_table, job_id
220
+ write_load_log log
214
221
  txn.truncate_and_commit work_table
215
222
  }
216
223
  end
217
224
 
218
- def load_objects(dest_table, manifest, options, log_table, job_id)
225
+ def load_objects(dest_table, manifest, options, log)
219
226
  @connection.transaction {|txn|
220
227
  execute_copy dest_table, manifest, options
221
- write_load_log log_table, job_id
228
+ write_load_log log
222
229
  }
223
230
  end
224
231
 
@@ -236,8 +243,8 @@ module Bricolage
236
243
  @logger.info "load succeeded: #{manifest.url}"
237
244
  end
238
245
 
239
- def write_load_log(log_table, job_id)
240
- @connection.execute("insert into #{log_table} (job_id, finish_time) values (#{job_id}, current_timestamp)")
246
+ def write_load_log(log)
247
+ @connection.execute("insert into #{@log_table} (task_id, job_id, finish_time) values (#{log.task_id}, #{log.job_id}, current_timestamp)")
241
248
  end
242
249
 
243
250
  end # class DataConnection
@@ -1,5 +1,5 @@
1
1
  module Bricolage
2
2
  module StreamingLoad
3
- VERSION = '0.11.0'
3
+ VERSION = '0.12.0'
4
4
  end
5
5
  end
@@ -30,7 +30,7 @@ module Bricolage
30
30
  assert_equal [
31
31
  "begin transaction;",
32
32
  "copy testschema.desttable from '#{job.manifest.url}' credentials 'cccc' manifest statupdate false compupdate false json 'auto' gzip timeformat 'auto' dateformat 'auto' acceptanydate acceptinvchars ' ' truncatecolumns trimblanks ;",
33
- "insert into strload_load_logs (job_id, finish_time) values (#{job.job_id}, current_timestamp)",
33
+ "insert into strload_load_logs (task_id, job_id, finish_time) values (1, #{job.job_id}, current_timestamp)",
34
34
  "commit;"
35
35
  ], job.data_ds.sql_list
36
36
 
@@ -58,7 +58,7 @@ module Bricolage
58
58
  "delete from testschema.with_work_table_wk",
59
59
  "copy testschema.with_work_table_wk from '#{job.manifest.url}' credentials 'cccc' manifest statupdate false compupdate false json 'auto' gzip timeformat 'auto' dateformat 'auto' acceptanydate acceptinvchars ' ' truncatecolumns trimblanks ;",
60
60
  "insert into testschema.with_work_table select * from testschema.with_work_table_wk;\n",
61
- "insert into strload_load_logs (job_id, finish_time) values (#{job.job_id}, current_timestamp)",
61
+ "insert into strload_load_logs (task_id, job_id, finish_time) values (11, #{job.job_id}, current_timestamp)",
62
62
  "truncate testschema.with_work_table_wk;"
63
63
  ], job.data_ds.sql_list
64
64
 
@@ -114,7 +114,7 @@ module Bricolage
114
114
  assert_equal [
115
115
  "begin transaction;",
116
116
  "copy testschema.desttable from '#{job.manifest.url}' credentials 'cccc' manifest statupdate false compupdate false json 'auto' gzip timeformat 'auto' dateformat 'auto' acceptanydate acceptinvchars ' ' truncatecolumns trimblanks ;",
117
- "insert into strload_load_logs (job_id, finish_time) values (#{job.job_id}, current_timestamp)",
117
+ "insert into strload_load_logs (task_id, job_id, finish_time) values (11, #{job.job_id}, current_timestamp)",
118
118
  "commit;"
119
119
  ], job.data_ds.sql_list
120
120
 
@@ -303,7 +303,7 @@ module Bricolage
303
303
  assert_equal [
304
304
  "begin transaction;",
305
305
  "copy testschema.desttable from '#{job.manifest.url}' credentials 'cccc' manifest statupdate false compupdate false json 'auto' gzip timeformat 'auto' dateformat 'auto' acceptanydate acceptinvchars ' ' truncatecolumns trimblanks ;",
306
- "insert into strload_load_logs (job_id, finish_time) values (#{job.job_id}, current_timestamp)",
306
+ "insert into strload_load_logs (task_id, job_id, finish_time) values (11, #{job.job_id}, current_timestamp)",
307
307
  "commit;"
308
308
  ], job.data_ds.sql_list
309
309
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bricolage-streamingload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-06 00:00:00.000000000 Z
12
+ date: 2017-12-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bricolage
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.5.1
158
+ rubygems_version: 2.6.11
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Bricolage Streaming Load Daemon