bricolage 5.16.7 → 5.16.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: 8a8efbc939f402ccf882643c4a90ca12ea640c30
4
- data.tar.gz: e062facaaae1162a6f7a191d83b11a2df6c00f93
3
+ metadata.gz: b81ae1279889983f0a8c1f0637024aa4dd0e47b9
4
+ data.tar.gz: 62451f57e167a845b5b838cf2e2708137f284e80
5
5
  SHA512:
6
- metadata.gz: 7566e80daca754ce975ad7ea047a468661670e6364f7784631fac49795c2ad2f2239bd115a55d1d0724db057ecae0bdd7bc31200baded0f58d7b92129d0860ea
7
- data.tar.gz: 049efc4e14ca96ed81dca065ab177ee590b498c50de57b9be737e6ea264fd5c9e153bb33b2b5bf7762f89127b229e981abe74a0dc0101c48d24084a4dccd8e34
6
+ metadata.gz: 7966c1ebdc742ea017cffef2a0f5cbec9bd8994af325e8c60159ecbc3d2ae6b1d6f9b47f4f5b38cf29556b0f07710edbdc9ba5e09f7ac96e05ad4bda0d0f1f63
7
+ data.tar.gz: dd6d3178526464a47edc4eaa02db6bda76d2cd3e8c053ca12570b45393d5be9aa10fed71938f2e89a27fcb5f78218ebe0d1c5950c3c86bc57189da7eb8e5d315
data/lib/bricolage/job.rb CHANGED
@@ -108,11 +108,13 @@ module Bricolage
108
108
  @script.bind @context, @variables
109
109
  end
110
110
 
111
+ def provide_default(name, value)
112
+ @param_vals[name] ||= value if @param_vals
113
+ end
114
+
111
115
  # Called from jobclasses (parameters_filter)
112
116
  def provide_sql_file_by_job_id
113
- if @param_vals and @id
114
- @param_vals['sql-file'] ||= @id
115
- end
117
+ provide_default 'sql-file', @id if @id
116
118
  end
117
119
 
118
120
  def declarations
@@ -4,8 +4,14 @@ require 'logger'
4
4
  module Bricolage
5
5
  class Logger < ::Logger
6
6
  def Logger.default
7
- logger = new($stderr)
8
- logger.level = $stderr.tty? ? Logger::DEBUG : Logger::INFO
7
+ @default ||= new
8
+ end
9
+
10
+ DEFAULT_ROTATION_SIZE = 1024 ** 2 * 100 # 100MB
11
+
12
+ def Logger.new(device: $stderr, rotation_period: nil, rotation_size: DEFAULT_ROTATION_SIZE)
13
+ logger = super(device, (rotation_period || 0), rotation_size)
14
+ logger.level = (device == $stderr && $stderr.tty?) ? Logger::DEBUG : Logger::INFO
9
15
  logger.formatter = -> (sev, time, prog, msg) {
10
16
  "#{time}: #{sev}: #{msg}\n"
11
17
  }
@@ -17,13 +17,13 @@ module Bricolage
17
17
  end
18
18
 
19
19
  def execute_update(query)
20
- @logger.info "[#{@ds.name}] #{query}"
21
- log_elapsed_time {
22
- rs = @connection.exec(query)
23
- result = rs.to_a
24
- rs.clear
25
- result
20
+ log_query query
21
+ rs = log_elapsed_time {
22
+ @connection.exec(query)
26
23
  }
24
+ result = rs.to_a
25
+ rs.clear
26
+ result
27
27
  rescue PG::Error => ex
28
28
  raise PostgreSQLException.wrap(ex)
29
29
  end
@@ -35,8 +35,21 @@ module Bricolage
35
35
  execute_query("select * from #{table}", &block)
36
36
  end
37
37
 
38
+ def query_value(query)
39
+ row = query_row(query)
40
+ row ? row.values.first : nil
41
+ end
42
+
43
+ def query_values(query)
44
+ execute_query(query) {|rs| rs.to_a }.flat_map {|rec| rec.values }
45
+ end
46
+
47
+ def query_row(query)
48
+ execute_query(query) {|rs| rs.to_a.first }
49
+ end
50
+
38
51
  def execute_query(query, &block)
39
- @logger.info "[#{@ds.name}] #{query}"
52
+ log_query query
40
53
  rs = log_elapsed_time {
41
54
  @connection.exec(query)
42
55
  }
@@ -56,7 +69,7 @@ module Bricolage
56
69
  end
57
70
 
58
71
  def streaming_execute_query(query, &block)
59
- @logger.info "[#{@ds.name}] #{query}"
72
+ log_query query
60
73
  log_elapsed_time {
61
74
  @connection.send_query(query)
62
75
  }
@@ -79,8 +92,40 @@ module Bricolage
79
92
 
80
93
  def transaction
81
94
  execute 'begin transaction'
82
- yield
83
- execute 'commit'
95
+ txn = Transaction.new(self)
96
+ begin
97
+ yield txn
98
+ rescue
99
+ begin
100
+ txn.abort unless txn.committed?
101
+ rescue => ex
102
+ @logger.error "SQL error on transaction abort: #{ex.message} (ignored)"
103
+ end
104
+ raise
105
+ ensure
106
+ txn.commit unless txn.committed?
107
+ end
108
+ end
109
+
110
+ class Transaction
111
+ def initialize(conn)
112
+ @conn = conn
113
+ @committed = false
114
+ end
115
+
116
+ def committed?
117
+ @committed
118
+ end
119
+
120
+ def commit
121
+ @conn.execute 'commit'
122
+ @committed = true
123
+ end
124
+
125
+ def abort
126
+ @conn.execute 'abort'
127
+ @committed = true
128
+ end
84
129
  end
85
130
 
86
131
  def open_cursor(query, name = nil, &block)
@@ -140,7 +185,18 @@ module Bricolage
140
185
  execute "analyze #{table};"
141
186
  end
142
187
 
143
- private
188
+ def lock(table)
189
+ execute("lock #{table}")
190
+ end
191
+
192
+ def log_query(query)
193
+ @logger.info "[#{@ds.name}] #{mask_secrets query}"
194
+ end
195
+
196
+ def mask_secrets(msg)
197
+ msg.gsub(/\bcredentials\s+'.*?'/mi, "credentials '****'")
198
+ end
199
+ private :mask_secrets
144
200
 
145
201
  def log_elapsed_time
146
202
  b = Time.now
@@ -150,6 +206,7 @@ module Bricolage
150
206
  t = e - b
151
207
  @logger.info "#{'%.1f' % t} secs"
152
208
  end
209
+
153
210
  end
154
211
 
155
212
  end
@@ -0,0 +1,29 @@
1
+ module Bricolage
2
+
3
+ module SQLUtils
4
+
5
+ private
6
+
7
+ def sql_string_literal(s)
8
+ %Q('#{escape_sql_string s}')
9
+ end
10
+
11
+ alias s sql_string_literal
12
+
13
+ def escape_sql_string(s)
14
+ s.gsub(/'/, "''")
15
+ end
16
+
17
+ def sql_timestamp_literal(time)
18
+ %Q(timestamp '#{sql_timestamp_format(time)}')
19
+ end
20
+
21
+ alias t sql_timestamp_literal
22
+
23
+ def sql_timestamp_format(time)
24
+ time.strftime('%Y-%m-%d %H:%M:%S')
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -1,4 +1,4 @@
1
1
  module Bricolage
2
2
  APPLICATION_NAME = 'Bricolage'
3
- VERSION = '5.16.7'
3
+ VERSION = '5.16.8'
4
4
  end
data/test/all.rb CHANGED
@@ -1,3 +1,3 @@
1
- Dir.glob("#{__dir__}/test_*.rb").each do |path|
1
+ Dir.glob("#{__dir__}/**/test_*.rb").each do |path|
2
2
  load path
3
3
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- bricolage (5.16.7)
4
+ bricolage (5.16.8)
5
5
  aws-sdk (~> 2)
6
6
  mysql2
7
7
  pg
@@ -11,17 +11,17 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- aws-sdk (2.3.2)
15
- aws-sdk-resources (= 2.3.2)
16
- aws-sdk-core (2.3.2)
14
+ aws-sdk (2.3.15)
15
+ aws-sdk-resources (= 2.3.15)
16
+ aws-sdk-core (2.3.15)
17
17
  jmespath (~> 1.0)
18
- aws-sdk-resources (2.3.2)
19
- aws-sdk-core (= 2.3.2)
18
+ aws-sdk-resources (2.3.15)
19
+ aws-sdk-core (= 2.3.15)
20
20
  coderay (1.1.0)
21
21
  fluent-logger (0.5.1)
22
22
  msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
23
23
  hirb (0.7.3)
24
- httpclient (2.7.1)
24
+ httpclient (2.8.0)
25
25
  jmespath (1.2.4)
26
26
  json_pure (>= 1.8.1)
27
27
  json (1.8.3)
@@ -29,7 +29,7 @@ GEM
29
29
  method_source (0.8.2)
30
30
  msgpack (0.5.12)
31
31
  mysql2 (0.4.4)
32
- parallel (0.6.5)
32
+ parallel (1.8.0)
33
33
  pg (0.18.4)
34
34
  pry (0.10.3)
35
35
  coderay (~> 1.1.0)
@@ -39,17 +39,17 @@ GEM
39
39
  ruby-progressbar (1.7.5)
40
40
  rubyzip (1.1.7)
41
41
  slop (3.6.0)
42
- td (0.13.2)
42
+ td (0.14.0)
43
43
  hirb (>= 0.4.5)
44
44
  msgpack (>= 0.4.4, < 0.8.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
45
- parallel (~> 0.6.1)
45
+ parallel (~> 1.8.0)
46
46
  ruby-progressbar (~> 1.7.5)
47
47
  rubyzip (~> 1.1.7)
48
- td-client (~> 0.8.78)
48
+ td-client (~> 0.8.79)
49
49
  td-logger (~> 0.3.21)
50
50
  yajl-ruby (~> 1.1)
51
51
  zip-zip (~> 0.3)
52
- td-client (0.8.78)
52
+ td-client (0.8.81)
53
53
  httpclient (~> 2.7)
54
54
  json (>= 1.7.6)
55
55
  msgpack (>= 0.4.4, < 0.8.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
@@ -69,4 +69,4 @@ DEPENDENCIES
69
69
  pry
70
70
 
71
71
  BUNDLED WITH
72
- 1.11.2
72
+ 1.12.5
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bricolage
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.16.7
4
+ version: 5.16.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-14 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: SQL batch framework
125
+ description: Redshift-oriented Data Warehouse Batch Framework
126
126
  email: aamine@loveruby.net
127
127
  executables:
128
128
  - bricolage
@@ -182,6 +182,7 @@ files:
182
182
  - lib/bricolage/s3datasource.rb
183
183
  - lib/bricolage/script.rb
184
184
  - lib/bricolage/sqlstatement.rb
185
+ - lib/bricolage/sqlutils.rb
185
186
  - lib/bricolage/taskqueue.rb
186
187
  - lib/bricolage/tddatasource.rb
187
188
  - lib/bricolage/vacuumlock.rb
@@ -335,5 +336,5 @@ rubyforge_project:
335
336
  rubygems_version: 2.5.1
336
337
  signing_key:
337
338
  specification_version: 4
338
- summary: SQL batch framework
339
+ summary: SQL Batch Framework
339
340
  test_files: []