bricolage 5.12.3 → 5.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jobclass/create.rb +2 -0
- data/jobclass/createview.rb +22 -0
- data/jobclass/my-migrate.rb +1 -1
- data/jobclass/rebuild-drop.rb +1 -1
- data/jobclass/rebuild-rename.rb +1 -1
- data/jobclass/sql.rb +2 -0
- data/lib/bricolage/mysqldatasource.rb +4 -3
- data/lib/bricolage/psqldatasource.rb +38 -2
- data/lib/bricolage/s3datasource.rb +11 -2
- data/lib/bricolage/version.rb +1 -1
- data/test/home/Gemfile.lock +1 -1
- data/test/home/config/development/database.yml +1 -0
- data/test/home/subsys/load.job +9 -0
- data/test/home/subsys/some_view-cv.sql.job +11 -0
- data/test/home/subsys/variable.yml +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1936717e92dd5c0ceab713deb5f4ece78b91f49
|
4
|
+
data.tar.gz: 16721287ca7a2eb341796c06e8b21dcf57f50809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac5b19704f17a36b208cdb8e557659bf1d76a9b24c5a8ad9d06ca5e50adafa4b89a994aa04d751776d9ca680d2e6c04c754641440309055b7b58e991c85782b
|
7
|
+
data.tar.gz: 2458de15c20a2439ea130919ab1245a907557c971d6c2e150cd9ed83c4527359f98ff98a2933b0e04575be4f5a311c12f602ec8b88a7ad7a6d1a412d4c3ce21e
|
data/jobclass/create.rb
CHANGED
@@ -4,6 +4,7 @@ JobClass.define('create') {
|
|
4
4
|
params.add DestTableParam.new
|
5
5
|
params.add OptionalBoolParam.new('drop', 'DROP table before CREATE.')
|
6
6
|
params.add OptionalBoolParam.new('analyze', 'ANALYZE table after SQL is executed.')
|
7
|
+
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed. (required keys: privilege, to)')
|
7
8
|
params.add DataSourceParam.new('sql')
|
8
9
|
}
|
9
10
|
|
@@ -16,6 +17,7 @@ JobClass.define('create') {
|
|
16
17
|
task.drop_force_if params['drop']
|
17
18
|
task.exec params['table-def']
|
18
19
|
task.analyze_if params['analyze']
|
20
|
+
task.grant_if params['grant'], params['dest-table']
|
19
21
|
}
|
20
22
|
}
|
21
23
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
JobClass.define('createview') {
|
2
|
+
parameters {|params|
|
3
|
+
params.add SQLFileParam.new('sql-file', 'PATH', 'CREATE VIEW file.')
|
4
|
+
params.add DestTableParam.new
|
5
|
+
params.add SrcTableParam.new
|
6
|
+
params.add OptionalBoolParam.new('drop', 'DROP table before CREATE.')
|
7
|
+
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed. (required keys: privilege, to)')
|
8
|
+
params.add DataSourceParam.new('sql')
|
9
|
+
}
|
10
|
+
|
11
|
+
declarations {|params|
|
12
|
+
params['sql-file'].declarations
|
13
|
+
}
|
14
|
+
|
15
|
+
script {|params, script|
|
16
|
+
script.task(params['data-source']) {|task|
|
17
|
+
task.drop_view_force_if params['drop']
|
18
|
+
task.exec params['sql-file']
|
19
|
+
task.grant_if params['grant'], params['dest-table']
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
data/jobclass/my-migrate.rb
CHANGED
@@ -27,7 +27,7 @@ JobClass.define('my-migrate') {
|
|
27
27
|
params.add OptionalBoolParam.new('analyze', 'ANALYZE table after SQL is executed.', default: true)
|
28
28
|
params.add OptionalBoolParam.new('vacuum', 'VACUUM table after SQL is executed.')
|
29
29
|
params.add OptionalBoolParam.new('vacuum-sort', 'VACUUM SORT table after SQL is executed.')
|
30
|
-
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed.')
|
30
|
+
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed. (required keys: privilege, to)')
|
31
31
|
|
32
32
|
# All
|
33
33
|
params.add OptionalBoolParam.new('export', 'Runs EXPORT task.')
|
data/jobclass/rebuild-drop.rb
CHANGED
@@ -7,7 +7,7 @@ JobClass.define('rebuild-drop') {
|
|
7
7
|
params.add OptionalBoolParam.new('analyze', 'ANALYZE table after SQL is executed.', default: true)
|
8
8
|
params.add OptionalBoolParam.new('vacuum', 'VACUUM table after SQL is executed.')
|
9
9
|
params.add OptionalBoolParam.new('vacuum-sort', 'VACUUM SORT table after SQL is executed.')
|
10
|
-
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed. (required keys:
|
10
|
+
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed. (required keys: privilege, to)')
|
11
11
|
params.add DataSourceParam.new('sql')
|
12
12
|
}
|
13
13
|
|
data/jobclass/rebuild-rename.rb
CHANGED
@@ -7,7 +7,7 @@ JobClass.define('rebuild-rename') {
|
|
7
7
|
params.add OptionalBoolParam.new('analyze', 'ANALYZE table after SQL is executed.', default: true)
|
8
8
|
params.add OptionalBoolParam.new('vacuum', 'VACUUM table after SQL is executed.')
|
9
9
|
params.add OptionalBoolParam.new('vacuum-sort', 'VACUUM SORT table after SQL is executed.')
|
10
|
-
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed.')
|
10
|
+
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed. (required keys: privilege, to)')
|
11
11
|
params.add DataSourceParam.new('sql')
|
12
12
|
}
|
13
13
|
|
data/jobclass/sql.rb
CHANGED
@@ -7,6 +7,7 @@ JobClass.define('sql') {
|
|
7
7
|
params.add OptionalBoolParam.new('analyze', 'ANALYZE table after SQL is executed.')
|
8
8
|
params.add OptionalBoolParam.new('vacuum', 'VACUUM table after SQL is executed.')
|
9
9
|
params.add OptionalBoolParam.new('vacuum-sort', 'VACUUM SORT table after SQL is executed.')
|
10
|
+
params.add KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed. (required keys: privilege, to)')
|
10
11
|
params.add DataSourceParam.new('sql')
|
11
12
|
}
|
12
13
|
|
@@ -24,6 +25,7 @@ JobClass.define('sql') {
|
|
24
25
|
task.exec params['sql-file']
|
25
26
|
task.vacuum_if params['vacuum'], params['vacuum-sort']
|
26
27
|
task.analyze_if params['analyze']
|
28
|
+
task.grant_if params['grant'], params['dest-table']
|
27
29
|
}
|
28
30
|
}
|
29
31
|
}
|
@@ -4,6 +4,7 @@ require 'json'
|
|
4
4
|
require 'csv'
|
5
5
|
require 'stringio'
|
6
6
|
require 'open3'
|
7
|
+
require 'etc'
|
7
8
|
|
8
9
|
module Bricolage
|
9
10
|
|
@@ -66,7 +67,7 @@ module Bricolage
|
|
66
67
|
end
|
67
68
|
|
68
69
|
class MySQLTask < DataSourceTask
|
69
|
-
def export(stmt, path: nil, format: nil, override: false, gzip: false, sqldump:
|
70
|
+
def export(stmt, path: nil, format: nil, override: false, gzip: false, sqldump: false)
|
70
71
|
add Export.new(stmt, path: path, format: format, override: override, gzip: gzip, sqldump: sqldump)
|
71
72
|
end
|
72
73
|
|
@@ -118,7 +119,7 @@ module Bricolage
|
|
118
119
|
end
|
119
120
|
|
120
121
|
def sqldump_available?
|
121
|
-
|
122
|
+
sqldump_real_path.executable?
|
122
123
|
end
|
123
124
|
|
124
125
|
def sqldump_path
|
@@ -130,7 +131,7 @@ module Bricolage
|
|
130
131
|
end
|
131
132
|
|
132
133
|
def platform_name
|
133
|
-
@platform_name ||=
|
134
|
+
@platform_name ||= Etc.uname[:sysname]
|
134
135
|
end
|
135
136
|
|
136
137
|
def sqldump_usable?
|
@@ -232,18 +232,30 @@ module Bricolage
|
|
232
232
|
drop '${dest_table}' if enabled
|
233
233
|
end
|
234
234
|
|
235
|
-
def
|
235
|
+
def drop_obj_force(type, name)
|
236
236
|
exec SQLStatement.for_string(
|
237
237
|
"\\set ON_ERROR_STOP false\n" +
|
238
|
-
"drop
|
238
|
+
"drop #{type} #{name} cascade;\n" +
|
239
239
|
"\\set ON_ERROR_STOP true\n"
|
240
240
|
)
|
241
241
|
end
|
242
242
|
|
243
|
+
def drop_force(target_table)
|
244
|
+
drop_obj_force('table', target_table)
|
245
|
+
end
|
246
|
+
|
247
|
+
def drop_view_force(target_view)
|
248
|
+
drop_obj_force('view', target_view)
|
249
|
+
end
|
250
|
+
|
243
251
|
def drop_force_if(enabled)
|
244
252
|
drop_force('${dest_table}') if enabled
|
245
253
|
end
|
246
254
|
|
255
|
+
def drop_view_force_if(enabled)
|
256
|
+
drop_view_force('${dest_table}') if enabled
|
257
|
+
end
|
258
|
+
|
247
259
|
def truncate_if(enabled, target = '${dest_table}')
|
248
260
|
exec SQLStatement.for_string("truncate #{target};") if enabled
|
249
261
|
end
|
@@ -310,6 +322,7 @@ module Bricolage
|
|
310
322
|
unless src_ds.redshift_loader_source?
|
311
323
|
raise ParameterError, "input data source does not support redshift as bulk loading source: #{src_ds.name}"
|
312
324
|
end
|
325
|
+
provide_default_load_options opts, src_ds
|
313
326
|
buf = StringIO.new
|
314
327
|
buf.puts "copy #{dest_table}"
|
315
328
|
buf.puts "from '#{src_ds.url(src_path)}'"
|
@@ -322,6 +335,12 @@ module Bricolage
|
|
322
335
|
buf.string
|
323
336
|
end
|
324
337
|
|
338
|
+
def provide_default_load_options(opts, src_ds)
|
339
|
+
if src_ds.encrypted? and not opts.key?('encrypted')
|
340
|
+
opts['encrypted'] = true
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
325
344
|
def format_option(fmt, src_ds, jsonpath)
|
326
345
|
case fmt
|
327
346
|
when 'tsv'
|
@@ -420,10 +439,25 @@ module Bricolage
|
|
420
439
|
@opts = opts
|
421
440
|
end
|
422
441
|
|
442
|
+
def key?(name)
|
443
|
+
n = name.to_s
|
444
|
+
@opts.any? {|opt| opt.name == n }
|
445
|
+
end
|
446
|
+
|
423
447
|
def each(&block)
|
424
448
|
@opts.each(&block)
|
425
449
|
end
|
426
450
|
|
451
|
+
def []=(name, value)
|
452
|
+
n = name.to_s
|
453
|
+
delete n
|
454
|
+
@opts.push Option.new(n, value)
|
455
|
+
end
|
456
|
+
|
457
|
+
def delete(name)
|
458
|
+
@opts.reject! {|opt| opt.name == name }
|
459
|
+
end
|
460
|
+
|
427
461
|
def merge(pairs)
|
428
462
|
h = {}
|
429
463
|
@opts.each do |opt|
|
@@ -465,6 +499,8 @@ module Bricolage
|
|
465
499
|
"#{@name} '#{@value}'"
|
466
500
|
when Integer # maxerror 10
|
467
501
|
"#{@name} #{@value}"
|
502
|
+
when nil # (explicitly disable boolean options)
|
503
|
+
''
|
468
504
|
else
|
469
505
|
raise ParameterError, "unsupported type of option value for #{@name}: #{@value.inspect}"
|
470
506
|
end
|
@@ -10,13 +10,14 @@ module Bricolage
|
|
10
10
|
|
11
11
|
def initialize(endpoint: 's3-ap-northeast-1.amazonaws.com',
|
12
12
|
bucket: nil, prefix: nil,
|
13
|
-
access_key_id: nil, secret_access_key: nil,
|
13
|
+
access_key_id: nil, secret_access_key: nil, master_symmetric_key: nil,
|
14
14
|
s3cfg: nil)
|
15
15
|
@endpoint = endpoint
|
16
16
|
@bucket = bucket
|
17
17
|
@prefix = (prefix && prefix.empty?) ? nil : prefix
|
18
18
|
@access_key_id = access_key_id
|
19
19
|
@secret_access_key = secret_access_key
|
20
|
+
@master_symmetric_key = master_symmetric_key
|
20
21
|
@s3cfg = s3cfg
|
21
22
|
@configurations = @s3cfg ? load_configurations(@s3cfg) : nil
|
22
23
|
end
|
@@ -31,7 +32,11 @@ module Bricolage
|
|
31
32
|
|
32
33
|
# For Redshift
|
33
34
|
def credential_string
|
34
|
-
|
35
|
+
[
|
36
|
+
"aws_access_key_id=#{access_key}",
|
37
|
+
"aws_secret_access_key=#{secret_key}",
|
38
|
+
(@master_symmetric_key && "master_symmetric_key=#{@master_symmetric_key}")
|
39
|
+
].compact.join(';')
|
35
40
|
end
|
36
41
|
|
37
42
|
def access_key
|
@@ -59,6 +64,10 @@ module Bricolage
|
|
59
64
|
h
|
60
65
|
end
|
61
66
|
|
67
|
+
def encrypted?
|
68
|
+
!!@master_symmetric_key
|
69
|
+
end
|
70
|
+
|
62
71
|
#
|
63
72
|
# Ruby Interface
|
64
73
|
#
|
data/lib/bricolage/version.rb
CHANGED
data/test/home/Gemfile.lock
CHANGED
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.12.
|
4
|
+
version: 5.12.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minero Aoki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- bin/bricolage
|
107
107
|
- bin/bricolage-jobnet
|
108
108
|
- jobclass/create.rb
|
109
|
+
- jobclass/createview.rb
|
109
110
|
- jobclass/exec.rb
|
110
111
|
- jobclass/insert-delta.rb
|
111
112
|
- jobclass/insert.rb
|
@@ -180,6 +181,7 @@ files:
|
|
180
181
|
- test/home/subsys/job5.job
|
181
182
|
- test/home/subsys/job6.job
|
182
183
|
- test/home/subsys/job7.job
|
184
|
+
- test/home/subsys/load.job
|
183
185
|
- test/home/subsys/load_test.ct
|
184
186
|
- test/home/subsys/load_test.job
|
185
187
|
- test/home/subsys/migrate.job
|
@@ -191,6 +193,7 @@ files:
|
|
191
193
|
- test/home/subsys/search_backends.ct
|
192
194
|
- test/home/subsys/separated.job
|
193
195
|
- test/home/subsys/separated.sql
|
196
|
+
- test/home/subsys/some_view-cv.sql.job
|
194
197
|
- test/home/subsys/unified.jobnet
|
195
198
|
- test/home/subsys/unified.sql.job
|
196
199
|
- test/home/subsys/variable.yml
|