bricolage 5.27.2 → 5.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +22 -0
- data/Gemfile +2 -0
- data/LICENSES +21 -0
- data/RELEASE.md +271 -0
- data/Rakefile +3 -0
- data/bricolage.gemspec +26 -0
- data/jobclass/exec.rb +5 -2
- data/lib/bricolage/configloader.rb +12 -10
- data/lib/bricolage/datasource.rb +16 -11
- data/lib/bricolage/job.rb +3 -0
- data/lib/bricolage/jobfile.rb +42 -6
- data/lib/bricolage/parameters.rb +6 -2
- data/lib/bricolage/version.rb +1 -1
- data/streaming_load_log.ct +9 -0
- metadata +11 -143
- data/test/all.rb +0 -3
- data/test/home/Gemfile +0 -3
- data/test/home/Gemfile.lock +0 -44
- data/test/home/config/bricolage.yml +0 -1
- data/test/home/config/development/database.yml +0 -100
- data/test/home/config/development/password.yml +0 -6
- data/test/home/config/development/variable.yml +0 -7
- data/test/home/data/20141002-1355_00.txt +0 -2
- data/test/home/data/20141002-1355_01.txt +0 -2
- data/test/home/data/20141002-1355_02.txt +0 -2
- data/test/home/data/test.txt +0 -1
- data/test/home/jobnet-test.rb +0 -61
- data/test/home/log/20170117/subsys::job1/20170117_202014082/subsys-job1.log +0 -3
- data/test/home/log/20170117/subsys::job1/20170117_202334852/subsys-job1.log +0 -3
- data/test/home/log/20170117/subsys::job1/20170117_202405056/subsys-job1.log +0 -3
- data/test/home/log/20170117/subsys::migrate/20170117_202548409/subsys-migrate.log +0 -80
- data/test/home/log/20170117/subsys::migrate/20170117_202636115/subsys-migrate.log +0 -79
- data/test/home/log/20170117/subsys::net1/20170117_203022461/subsys-job1.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203022461/subsys-job2.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203022461/subsys-job3.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203022461/subsys-job4.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203102130/subsys-job1.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203102130/subsys-job2.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203102130/subsys-job3.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203102130/subsys-job4.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203232033/subsys-job1.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203232033/subsys-job2.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203232033/subsys-job3.log +0 -3
- data/test/home/log/20170117/subsys::net1/20170117_203232033/subsys-job4.log +0 -3
- data/test/home/log/20170629/subsys::job1/20170629_155543985/subsys-job1.log +0 -3
- data/test/home/log/20170629/subsys::net1/20170629_154308811/subsys-job1.log +0 -3
- data/test/home/log/20170629/subsys::net1/20170629_154308811/subsys-job2.log +0 -3
- data/test/home/log/20170629/subsys::net1/20170629_154308811/subsys-job3.log +0 -3
- data/test/home/log/20170629/subsys::net1/20170629_154308811/subsys-job4.log +0 -3
- data/test/home/log/20170629/subsys::net1/20170629_155330208/subsys-job1.log +0 -3
- data/test/home/log/20170629/subsys::net1/20170629_155330208/subsys-job2.log +0 -3
- data/test/home/log/20170629/subsys::net1/20170629_155330208/subsys-job3.log +0 -3
- data/test/home/log/20170629/subsys::net1/20170629_155330208/subsys-job4.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145523511/subsys-job1.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145523511/subsys-job2.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145523511/subsys-job3.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145523511/subsys-job4.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145545097/subsys-job1.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145545097/subsys-job2.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145545097/subsys-job3.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145545097/subsys-job4.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145615702/subsys-job1.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145615702/subsys-job2.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145615702/subsys-job3.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_145615702/subsys-job4.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_153437221/subsys-job1.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_153507519/subsys-job1.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_153507519/subsys-job2.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_153507519/subsys-job3.log +0 -3
- data/test/home/log/20170630/subsys::net1/20170630_153507519/subsys-job4.log +0 -3
- data/test/home/log/20170704/subsys::insert/20170704_164335210/subsys-insert.log +0 -14
- data/test/home/log/20170704/subsys::insert/20170704_164344251/subsys-insert.log +0 -14
- data/test/home/log/20170704/subsys::insert/20170704_164723299/subsys-insert.log +0 -14
- data/test/home/log/20170704/subsys::insert.sql/20170704_164143661/subsys-insert.sql.log +0 -14
- data/test/home/log/20170704/subsys::insert.sql.job/20170704_163033119/subsys-insert.log +0 -14
- data/test/home/log/20170704/subsys::insert.sql.job/20170704_172410576/subsys-insert.log +0 -14
- data/test/home/log/20170704/subsys::insert.sql.job/20170704_173130175/subsys-insert.log +0 -14
- data/test/home/log/20170704/subsys::insert.sql.job/20170704_173201376/subsys-insert.log +0 -14
- data/test/home/log/20170704/subsys::net1/20170704_162457694/subsys-job1.log +0 -3
- data/test/home/log/20170704/subsys::net1/20170704_162544282/subsys-job1.log +0 -3
- data/test/home/log/20170704/subsys::net1/20170704_162544282/subsys-job2.log +0 -3
- data/test/home/log/20170704/subsys::net1/20170704_162544282/subsys-job3.log +0 -3
- data/test/home/log/20170704/subsys::net1/20170704_162544282/subsys-job4.log +0 -3
- data/test/home/log/20170706/subsys::net1/20170706_201157129/subsys-job1.log +0 -3
- data/test/home/log/20170706/subsys::net1/20170706_201157129/subsys-job2.log +0 -3
- data/test/home/log/20170706/subsys::net1/20170706_201157129/subsys-job3.log +0 -3
- data/test/home/log/20170706/subsys::net1/20170706_201157129/subsys-job4.log +0 -3
- data/test/home/log/20170707/subsys::insert/20170707_020050817/subsys-insert.log +0 -51
- data/test/home/log/20170707/subsys::insert/20170707_020050817/subsys-insert.log.status +0 -1
- data/test/home/log/20170707/subsys::job1/20170707_020542902/subsys-job1.log +0 -3
- data/test/home/log/20170707/subsys::net1/20170707_012252058/subsys-job1.log +0 -3
- data/test/home/log/20170707/subsys::net1/20170707_012252058/subsys-job2.log +0 -3
- data/test/home/log/20170707/subsys::net1/20170707_012252058/subsys-job3.log +0 -3
- data/test/home/log/20170707/subsys::net1/20170707_012252058/subsys-job4.log +0 -3
- data/test/home/log/20170707/subsys::net1/20170707_020039222/subsys-job1.log +0 -3
- data/test/home/log/20170707/subsys::net1/20170707_020039222/subsys-job2.log +0 -3
- data/test/home/log/20170707/subsys::net1/20170707_020039222/subsys-job3.log +0 -3
- data/test/home/log/20170707/subsys::net1/20170707_020039222/subsys-job4.log +0 -3
- data/test/home/revert.sh +0 -7
- data/test/home/s +0 -1
- data/test/home/subsys/d.ct +0 -7
- data/test/home/subsys/insert.sql.job +0 -7
- data/test/home/subsys/item_pv_acc.ct +0 -8
- data/test/home/subsys/job1.job +0 -1
- data/test/home/subsys/job2.job +0 -1
- data/test/home/subsys/job3.job +0 -1
- data/test/home/subsys/job4.job +0 -1
- data/test/home/subsys/job5.job +0 -1
- data/test/home/subsys/job6.job +0 -1
- data/test/home/subsys/job7.job +0 -1
- data/test/home/subsys/load.job +0 -9
- data/test/home/subsys/load_test.ct +0 -6
- data/test/home/subsys/load_test.job +0 -14
- data/test/home/subsys/migrate.job +0 -33
- data/test/home/subsys/my-import-delta.sql.job +0 -40
- data/test/home/subsys/my-import.job +0 -31
- data/test/home/subsys/net1.jobnet +0 -3
- data/test/home/subsys/net2.jobnet +0 -2
- data/test/home/subsys/put.job +0 -3
- data/test/home/subsys/raw-vacuum.jobnet +0 -1
- data/test/home/subsys/raw-vacuum.sql.job +0 -7
- data/test/home/subsys/rebuild.sql.job +0 -14
- data/test/home/subsys/redis_export.job +0 -9
- data/test/home/subsys/redis_export2.job +0 -8
- data/test/home/subsys/search_backends.ct +0 -13
- data/test/home/subsys/separated.job +0 -1
- data/test/home/subsys/separated.sql +0 -1
- data/test/home/subsys/some_view-cv.sql.job +0 -11
- data/test/home/subsys/unified.jobnet +0 -1
- data/test/home/subsys/unified.sql.job +0 -5
- data/test/home/subsys/users.ct +0 -13
- data/test/home/subsys/variable.yml +0 -6
- data/test/test_c_streaming_load.rb +0 -13
- data/test/test_filesystem.rb +0 -19
- data/test/test_logfilepath.rb +0 -19
- data/test/test_parameters.rb +0 -401
- data/test/test_psqldatasource.rb +0 -12
- data/test/test_s3datasource.rb +0 -40
- data/test/test_variables.rb +0 -114
- data/test/vacuum-test.rb +0 -8
@@ -1,40 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
class: my-import-delta
|
3
|
-
src-ds: mysql_summary
|
4
|
-
src-tables:
|
5
|
-
item_pv: item_pv
|
6
|
-
s3-ds: s3
|
7
|
-
s3-prefix: bricolage/my-import-delta/$data_date/data.
|
8
|
-
gzip: true
|
9
|
-
dump-options:
|
10
|
-
partition_column: id
|
11
|
-
delete_objects: true
|
12
|
-
dest-ds: sql
|
13
|
-
dest-table: $test_schema.item_pv_acc
|
14
|
-
delete-cond: "data_date = '$data_date'"
|
15
|
-
options:
|
16
|
-
statupdate: false
|
17
|
-
compupdate: false
|
18
|
-
maxerror: 0
|
19
|
-
#acceptinvchars: " "
|
20
|
-
#trimblanks: true
|
21
|
-
#truncatecolumns: true
|
22
|
-
## datetime
|
23
|
-
#acceptanydate: true
|
24
|
-
#dateformat: "auto"
|
25
|
-
#timeformat: "auto"
|
26
|
-
#vacuum-sort: true
|
27
|
-
analyze: true
|
28
|
-
*/
|
29
|
-
|
30
|
-
select
|
31
|
-
data_date
|
32
|
-
, item_id
|
33
|
-
, pv
|
34
|
-
, uu
|
35
|
-
from
|
36
|
-
$item_pv
|
37
|
-
where
|
38
|
-
date = '$data_date'
|
39
|
-
and (@PARTITION_CONDITION@)
|
40
|
-
;
|
@@ -1,31 +0,0 @@
|
|
1
|
-
class: my-import
|
2
|
-
src-ds: mysql
|
3
|
-
src-tables:
|
4
|
-
users: main.users
|
5
|
-
s3-ds: s3
|
6
|
-
s3-prefix: $test_schema/test-abc-
|
7
|
-
gzip: true
|
8
|
-
dump-options:
|
9
|
-
src_zone_offset: "+00:00"
|
10
|
-
dst_zone_offset: "+09:00"
|
11
|
-
delete_objects: true
|
12
|
-
dest-ds: sql
|
13
|
-
dest-table: $test_schema.users
|
14
|
-
table-def: users.ct
|
15
|
-
#no-backup: true
|
16
|
-
options:
|
17
|
-
statupdate: false
|
18
|
-
compupdate: false
|
19
|
-
maxerror: 3
|
20
|
-
acceptinvchars: " "
|
21
|
-
#trimblanks: true
|
22
|
-
#truncatecolumns: true
|
23
|
-
## datetime
|
24
|
-
#acceptanydate: true
|
25
|
-
#dateformat: "auto"
|
26
|
-
#timeformat: "auto"
|
27
|
-
#vacuum-sort: true
|
28
|
-
analyze: true
|
29
|
-
grant:
|
30
|
-
privilege: select
|
31
|
-
to: "$test_group"
|
data/test/home/subsys/put.job
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
raw-vacuum
|
@@ -1 +0,0 @@
|
|
1
|
-
class: sql
|
@@ -1 +0,0 @@
|
|
1
|
-
select 1;
|
@@ -1 +0,0 @@
|
|
1
|
-
unified
|
data/test/home/subsys/users.ct
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
--dest-table: users
|
2
|
-
|
3
|
-
create table $dest_table
|
4
|
-
( id int encode delta
|
5
|
-
, user_name varchar(1000) encode lzo
|
6
|
-
, birthday date encode lzo
|
7
|
-
, zip varchar(255) encode lzo
|
8
|
-
, created_at timestamp encode lzo
|
9
|
-
, updated_at timestamp encode lzo
|
10
|
-
)
|
11
|
-
distkey (id)
|
12
|
-
sortkey (id)
|
13
|
-
;
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'bricolage/jobclass'
|
3
|
-
Bricolage::JobClass.get('streaming_load')
|
4
|
-
|
5
|
-
module Bricolage
|
6
|
-
class TestStreamingLoadJobClass_S3Queue < Test::Unit::TestCase
|
7
|
-
def test_compile_name_pattern
|
8
|
-
q = StreamingLoadJobClass::S3Queue.new(data_source: nil, queue_path: nil, ctl_prefix: nil, persistent_path: nil, file_name: nil, logger: nil)
|
9
|
-
re = q.compile_name_pattern("%*%Y%m%d-%H%M_%Q.gz")
|
10
|
-
assert_equal /\A[^\/]*(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})\-(?<hour>\d{2})(?<minute>\d{2})_(?<seq>\d+)\.gz\z/, re
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/test/test_filesystem.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'bricolage/filesystem'
|
3
|
-
require 'pathname'
|
4
|
-
require 'pp'
|
5
|
-
|
6
|
-
module Bricolage
|
7
|
-
class TestFileSystem < Test::Unit::TestCase
|
8
|
-
fs = FileSystem.new("#{__dir__}/home", "test")
|
9
|
-
subfs = fs.subsystem('subsys')
|
10
|
-
|
11
|
-
test "FileSystem.job_file" do
|
12
|
-
path = subfs.job_file('unified')
|
13
|
-
assert_instance_of Pathname, path
|
14
|
-
assert_equal subfs.relative('unified.sql.job'), path
|
15
|
-
|
16
|
-
assert_equal subfs.relative('separated.job'), subfs.job_file('separated')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/test/test_logfilepath.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'bricolage/logfilepath'
|
3
|
-
require 'bricolage/jobnet'
|
4
|
-
|
5
|
-
module Bricolage
|
6
|
-
class TestLogFilePath < Test::Unit::TestCase
|
7
|
-
test '#format' do
|
8
|
-
path = LogFilePath.new('./log/%{std}.log')
|
9
|
-
ref = JobNet::JobRef.new('subsys', 'somejob', '-')
|
10
|
-
start = Time.new(2012,3,4,12,34,56)
|
11
|
-
assert_equal './log/20120304/subsys::rebuild/20120304_123456000/subsys-somejob.log', path.format(
|
12
|
-
job_ref: ref,
|
13
|
-
jobnet_id: 'subsys/rebuild',
|
14
|
-
job_start_time: start,
|
15
|
-
jobnet_start_time: start
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/test/test_parameters.rb
DELETED
@@ -1,401 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'bricolage/parameters'
|
3
|
-
require 'optparse'
|
4
|
-
require 'pp'
|
5
|
-
|
6
|
-
module Bricolage
|
7
|
-
class TestParameters < Test::Unit::TestCase
|
8
|
-
def apply_values(decls, values)
|
9
|
-
parser = Parameters::DirectValueHandler.new(decls)
|
10
|
-
parser.parse(values)
|
11
|
-
end
|
12
|
-
|
13
|
-
def apply_options(decls, argv)
|
14
|
-
parser = Parameters::CommandLineOptionHandler.new(decls)
|
15
|
-
opts = OptionParser.new
|
16
|
-
parser.define_options(opts)
|
17
|
-
opts.parse!(argv)
|
18
|
-
parser.values
|
19
|
-
end
|
20
|
-
|
21
|
-
def wrap_decl(decl)
|
22
|
-
Parameters::Declarations.new.tap {|params|
|
23
|
-
params.add decl
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
default_context = nil
|
28
|
-
default_variables = ResolvedVariables.new
|
29
|
-
|
30
|
-
# StringParam (8)
|
31
|
-
|
32
|
-
test "StringParam (*.job)" do
|
33
|
-
decls = wrap_decl StringParam.new('options', 'OPTIONS', 'Loader options.', optional: true)
|
34
|
-
pvals = apply_values(decls, {'options' => 'gzip, maxerror=3'})
|
35
|
-
params = pvals.resolve(default_context, default_variables)
|
36
|
-
assert_equal 'gzip, maxerror=3', params['options']
|
37
|
-
assert_false params.variables.bound?('options')
|
38
|
-
end
|
39
|
-
|
40
|
-
test "StringParam (--opt)" do
|
41
|
-
decls = wrap_decl StringParam.new('options', 'OPTIONS', 'Loader options.', optional: true)
|
42
|
-
pvals = apply_options(decls, ['--options=gzip, maxerror=3'])
|
43
|
-
params = pvals.resolve(default_context, default_variables)
|
44
|
-
assert_equal 'gzip, maxerror=3', params['options']
|
45
|
-
assert_false params.variables.bound?('options')
|
46
|
-
end
|
47
|
-
|
48
|
-
test "StringParam (default value)" do
|
49
|
-
decls = wrap_decl StringParam.new('options', 'OPTIONS', 'Loader options.', optional: true)
|
50
|
-
pvals = apply_values(decls, {})
|
51
|
-
params = pvals.resolve(default_context, default_variables)
|
52
|
-
assert_nil params['options']
|
53
|
-
end
|
54
|
-
|
55
|
-
test "StringParam (missing value)" do
|
56
|
-
decls = wrap_decl StringParam.new('delete-cond', 'SQL_EXPR', 'DELETE condition.')
|
57
|
-
pvals = apply_values(decls, {})
|
58
|
-
assert_raise(ParameterError) {
|
59
|
-
pvals.resolve(default_context, default_variables)
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
# BoolParam (0)
|
64
|
-
|
65
|
-
# OptionalBoolParam (41)
|
66
|
-
|
67
|
-
test "OptionalBoolParam (*.job)" do
|
68
|
-
decls = wrap_decl OptionalBoolParam.new('vacuum-sort', 'VACUUM SORT table after SQL is executed.')
|
69
|
-
pvals = apply_values(decls, {'vacuum-sort' => true})
|
70
|
-
params = pvals.resolve(default_context, default_variables)
|
71
|
-
assert_true params['vacuum-sort']
|
72
|
-
assert_false params.variables.bound?('vacuum_sort')
|
73
|
-
end
|
74
|
-
|
75
|
-
test "OptionalBoolParam (--opt)" do
|
76
|
-
decls = wrap_decl OptionalBoolParam.new('vacuum-sort', 'VACUUM SORT table after SQL is executed.', publish: true)
|
77
|
-
pvals = apply_options(decls, ['--vacuum-sort'])
|
78
|
-
params = pvals.resolve(default_context, default_variables)
|
79
|
-
assert_true params['vacuum-sort']
|
80
|
-
assert_equal 'true', params.variables['vacuum_sort']
|
81
|
-
end
|
82
|
-
|
83
|
-
test "OptionalBoolParam (default value #1)" do
|
84
|
-
decls = wrap_decl OptionalBoolParam.new('vacuum', 'VACUUM table after SQL is executed.')
|
85
|
-
pvals = apply_values(decls, {})
|
86
|
-
params = pvals.resolve(default_context, default_variables)
|
87
|
-
assert_false params['vacuum']
|
88
|
-
assert_false params.variables.bound?('vacuum')
|
89
|
-
end
|
90
|
-
|
91
|
-
test "OptionalBoolParam (default value #2)" do
|
92
|
-
decls = wrap_decl OptionalBoolParam.new('gzip', 'If true, compresses target file by gzip.', default: true)
|
93
|
-
pvals = apply_values(decls, {})
|
94
|
-
params = pvals.resolve(default_context, default_variables)
|
95
|
-
assert_true params['gzip']
|
96
|
-
assert_false params.variables.bound?('gzip')
|
97
|
-
end
|
98
|
-
|
99
|
-
# DateParam (2)
|
100
|
-
|
101
|
-
test "DateParam (*.job)" do
|
102
|
-
decls = wrap_decl DateParam.new('to', 'DATE', 'End date of logs to delete (%Y-%m-%d).')
|
103
|
-
pvals = apply_values(decls, {'to' => '2014-01-23'})
|
104
|
-
params = pvals.resolve(default_context, default_variables)
|
105
|
-
assert_equal Date.new(2014, 1, 23), params['to']
|
106
|
-
assert_false params.variables.bound?('to')
|
107
|
-
end
|
108
|
-
|
109
|
-
test "DateParam (--opt)" do
|
110
|
-
decls = wrap_decl DateParam.new('to', 'DATE', 'End date of logs to delete (%Y-%m-%d).', publish: true)
|
111
|
-
pvals = apply_options(decls, ['--to=2014-01-23'])
|
112
|
-
params = pvals.resolve(default_context, default_variables)
|
113
|
-
assert_equal Date.new(2014, 1, 23), params['to']
|
114
|
-
assert_equal '2014-01-23', params.variables['to']
|
115
|
-
end
|
116
|
-
|
117
|
-
test "DateParam (default value)" do
|
118
|
-
decls = wrap_decl DateParam.new('to', 'DATE', 'End date of logs to delete (%Y-%m-%d).', optional: true)
|
119
|
-
pvals = apply_values(decls, {})
|
120
|
-
params = pvals.resolve(default_context, default_variables)
|
121
|
-
assert_nil params['to']
|
122
|
-
assert_false params.variables.bound?('to')
|
123
|
-
end
|
124
|
-
|
125
|
-
# EnumParam (4)
|
126
|
-
|
127
|
-
test "EnumParam (*.job)" do
|
128
|
-
decls = wrap_decl EnumParam.new('format', %w(tsv json), 'Data file format.', default: 'tsv')
|
129
|
-
pvals = apply_values(decls, {'format' => 'json'})
|
130
|
-
params = pvals.resolve(default_context, default_variables)
|
131
|
-
assert_equal 'json', params['format']
|
132
|
-
assert_false params.variables.bound?('format')
|
133
|
-
end
|
134
|
-
|
135
|
-
test "EnumParam (--opt)" do
|
136
|
-
decls = wrap_decl EnumParam.new('format', %w(tsv json), 'Data file format.', default: nil, publish: true)
|
137
|
-
pvals = apply_options(decls, ['--format=tsv'])
|
138
|
-
params = pvals.resolve(default_context, default_variables)
|
139
|
-
assert_equal 'tsv', params['format']
|
140
|
-
assert_equal 'tsv', params.variables['format']
|
141
|
-
end
|
142
|
-
|
143
|
-
test "EnumParam (default value)" do
|
144
|
-
decls = wrap_decl EnumParam.new('format', %w(tsv json), 'Data file format.', default: 'tsv')
|
145
|
-
pvals = apply_values(decls, {})
|
146
|
-
params = pvals.resolve(default_context, default_variables)
|
147
|
-
assert_equal 'tsv', params['format']
|
148
|
-
end
|
149
|
-
|
150
|
-
# DataSourceParam (17)
|
151
|
-
|
152
|
-
class DummyContext_ds
|
153
|
-
def initialize(kind, name, result)
|
154
|
-
@kind = kind
|
155
|
-
@name = name
|
156
|
-
@result = result
|
157
|
-
end
|
158
|
-
|
159
|
-
def get_data_source(kind, name)
|
160
|
-
if kind == @kind and name == @name
|
161
|
-
@result
|
162
|
-
else
|
163
|
-
raise ParameterError, "wrong ds argument: #{kind}, #{name}"
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
DummyDataSource = Struct.new(:name)
|
169
|
-
app_ds = DummyDataSource.new('app')
|
170
|
-
sql_ds = DummyDataSource.new('sql')
|
171
|
-
|
172
|
-
test "DataSourceParam (*.job)" do
|
173
|
-
decls = wrap_decl DataSourceParam.new('sql')
|
174
|
-
pvals = apply_values(decls, {'data-source' => 'app'})
|
175
|
-
ctx = DummyContext_ds.new('sql', app_ds.name, app_ds)
|
176
|
-
params = pvals.resolve(ctx, default_variables)
|
177
|
-
assert_equal app_ds, params['data-source']
|
178
|
-
assert_false params.variables.bound?('data-source')
|
179
|
-
end
|
180
|
-
|
181
|
-
test "DataSourceParam (--opt)" do
|
182
|
-
decls = wrap_decl DataSourceParam.new('sql')
|
183
|
-
pvals = apply_options(decls, ['--data-source=app'])
|
184
|
-
ctx = DummyContext_ds.new('sql', app_ds.name, app_ds)
|
185
|
-
params = pvals.resolve(ctx, default_variables)
|
186
|
-
assert_equal app_ds, params['data-source']
|
187
|
-
assert_false params.variables.bound?('data-source')
|
188
|
-
end
|
189
|
-
|
190
|
-
test "DataSourceParam (default value)" do
|
191
|
-
decls = wrap_decl DataSourceParam.new('sql')
|
192
|
-
pvals = apply_values(decls, {})
|
193
|
-
ctx = DummyContext_ds.new('sql', nil, sql_ds)
|
194
|
-
params = pvals.resolve(ctx, default_variables)
|
195
|
-
assert_equal sql_ds, params['data-source']
|
196
|
-
assert_false params.variables.bound?('data-source')
|
197
|
-
end
|
198
|
-
|
199
|
-
# SQLFileParam (14)
|
200
|
-
|
201
|
-
DummyContext_sqlfile = Struct.new(:name, :ext, :result)
|
202
|
-
class DummyContext_sqlfile
|
203
|
-
def parameter_file(_name, _ext)
|
204
|
-
raise ParameterError, "bad argument: #{_name}, #{_ext}" unless [name, ext] == [_name, _ext]
|
205
|
-
result
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
dummy_sql_resource = StringResource.new("select * from t;")
|
210
|
-
dummy_sql_file = SQLStatement.new(dummy_sql_resource)
|
211
|
-
|
212
|
-
test "SQLFileParam (*.job)" do
|
213
|
-
decls = wrap_decl SQLFileParam.new
|
214
|
-
pvals = apply_values(decls, {'sql-file' => 'some_path.sql'})
|
215
|
-
ctx = DummyContext_sqlfile.new('some_path.sql', 'sql', dummy_sql_resource)
|
216
|
-
params = pvals.resolve(ctx, default_variables)
|
217
|
-
assert_equal dummy_sql_file, params['sql-file']
|
218
|
-
assert_false params.variables.bound?('sql_file')
|
219
|
-
end
|
220
|
-
|
221
|
-
test "SQLFileParam (--opt)" do
|
222
|
-
decls = wrap_decl SQLFileParam.new
|
223
|
-
pvals = apply_options(decls, ['--sql-file=some_path.sql'])
|
224
|
-
ctx = DummyContext_sqlfile.new('some_path.sql', 'sql', dummy_sql_resource)
|
225
|
-
params = pvals.resolve(ctx, default_variables)
|
226
|
-
assert_equal dummy_sql_file, params['sql-file']
|
227
|
-
assert_false params.variables.bound?('sql_file')
|
228
|
-
end
|
229
|
-
|
230
|
-
test "SQLFileParam (default value)" do
|
231
|
-
decls = wrap_decl SQLFileParam.new(optional: true)
|
232
|
-
pvals = apply_values(decls, {})
|
233
|
-
params = pvals.resolve(default_context, default_variables)
|
234
|
-
assert_nil params['sql-file']
|
235
|
-
end
|
236
|
-
|
237
|
-
# DestTableParam (9)
|
238
|
-
|
239
|
-
test "DestTableParam (*.job)" do
|
240
|
-
decls = wrap_decl DestTableParam.new
|
241
|
-
pvals = apply_values(decls, {'dest-table' => 'schemaA.tableA'})
|
242
|
-
params = pvals.resolve(default_context, default_variables)
|
243
|
-
assert_equal TableSpec.new('schemaA', 'tableA'), params['dest-table']
|
244
|
-
assert_equal 'schemaA.tableA', params.variables['dest_table']
|
245
|
-
end
|
246
|
-
|
247
|
-
test "DestTableParam (--opt)" do
|
248
|
-
decls = wrap_decl DestTableParam.new(optional: false)
|
249
|
-
pvals = apply_options(decls, ['--dest-table=schemaA.tableA'])
|
250
|
-
params = pvals.resolve(default_context, default_variables)
|
251
|
-
assert_equal TableSpec.new('schemaA', 'tableA'), params['dest-table']
|
252
|
-
assert_equal 'schemaA.tableA', params.variables['dest_table']
|
253
|
-
end
|
254
|
-
|
255
|
-
test "DestTableParam (default value)" do
|
256
|
-
decls = wrap_decl DestTableParam.new
|
257
|
-
pvals = apply_values(decls, {})
|
258
|
-
params = pvals.resolve(default_context, default_variables)
|
259
|
-
assert_nil params['dest-table']
|
260
|
-
assert_false params.variables.bound?('dest_table')
|
261
|
-
end
|
262
|
-
|
263
|
-
test "DestTableParam (variable expansion)" do
|
264
|
-
decls = wrap_decl DestTableParam.new
|
265
|
-
pvals = apply_values(decls, {'dest-table' => '$s.t'})
|
266
|
-
vars = ResolvedVariables.new
|
267
|
-
vars.add ResolvedVariable.new('s', 'SCH')
|
268
|
-
params = pvals.resolve(default_context, vars)
|
269
|
-
assert_equal TableSpec.new('SCH', 't'), params['dest-table']
|
270
|
-
assert_equal 'SCH.t', params.variables['dest_table']
|
271
|
-
end
|
272
|
-
|
273
|
-
test "DestTableParam (no such variable)" do
|
274
|
-
decls = wrap_decl DestTableParam.new
|
275
|
-
pvals = apply_values(decls, {'dest-table' => '$s.t'})
|
276
|
-
assert_raise(ParameterError) {
|
277
|
-
pvals.resolve(default_context, default_variables)
|
278
|
-
}
|
279
|
-
end
|
280
|
-
|
281
|
-
# SrcTableParam (9)
|
282
|
-
|
283
|
-
test "SrcTableParam (*.job)" do
|
284
|
-
decls = wrap_decl SrcTableParam.new
|
285
|
-
pvals = apply_values(decls, {'src-tables' => {'a' => '$s.A', 'b' => 'B'}})
|
286
|
-
vars = ResolvedVariables.new
|
287
|
-
vars.add ResolvedVariable.new('s', 'SCH')
|
288
|
-
params = pvals.resolve(default_context, vars)
|
289
|
-
srcs = {'a' => TableSpec.new('SCH', 'A'), 'b' => TableSpec.new(nil, 'B')}
|
290
|
-
assert_equal srcs, params['src-tables']
|
291
|
-
assert_equal 'SCH.A', params.variables['a']
|
292
|
-
assert_equal 'B', params.variables['b']
|
293
|
-
end
|
294
|
-
|
295
|
-
test "SrcTableParam (--opt)" do
|
296
|
-
decls = wrap_decl SrcTableParam.new
|
297
|
-
pvals = apply_options(decls, ['--src-table=a:A', '--src-table=b:B'])
|
298
|
-
params = pvals.resolve(default_context, default_variables)
|
299
|
-
srcs = {'a' => TableSpec.new(nil, 'A'), 'b' => TableSpec.new(nil, 'B')}
|
300
|
-
assert_equal srcs, params['src-tables']
|
301
|
-
assert_equal 'A', params.variables['a']
|
302
|
-
assert_equal 'B', params.variables['b']
|
303
|
-
end
|
304
|
-
|
305
|
-
test "SrcTableParam (default value)" do
|
306
|
-
decls = wrap_decl SrcTableParam.new
|
307
|
-
pvals = apply_values(decls, {})
|
308
|
-
params = pvals.resolve(default_context, default_variables)
|
309
|
-
assert_equal({}, params['src-tables'])
|
310
|
-
assert_false params.variables.bound?('a')
|
311
|
-
assert_false params.variables.bound?('b')
|
312
|
-
end
|
313
|
-
|
314
|
-
# DestFileParam (7)
|
315
|
-
|
316
|
-
test "DestFileParam (*.job)" do
|
317
|
-
decls = wrap_decl DestFileParam.new
|
318
|
-
pvals = apply_values(decls, {'dest-file' => '/some/path.txt'})
|
319
|
-
params = pvals.resolve(default_context, default_variables)
|
320
|
-
assert_equal Pathname.new('/some/path.txt'), params['dest-file']
|
321
|
-
end
|
322
|
-
|
323
|
-
test "DestFileParam (--opt)" do
|
324
|
-
decls = wrap_decl DestFileParam.new
|
325
|
-
pvals = apply_options(decls, ['--dest-file=/some/path.txt'])
|
326
|
-
params = pvals.resolve(default_context, default_variables)
|
327
|
-
assert_equal Pathname.new('/some/path.txt'), params['dest-file']
|
328
|
-
end
|
329
|
-
|
330
|
-
test "DestFileParam (no value error)" do
|
331
|
-
decls = wrap_decl DestFileParam.new
|
332
|
-
pvals = apply_values(decls, {})
|
333
|
-
assert_raise(ParameterError) {
|
334
|
-
pvals.resolve(default_context, default_variables)
|
335
|
-
}
|
336
|
-
end
|
337
|
-
|
338
|
-
# SrcFileParam (2)
|
339
|
-
|
340
|
-
test "SrcFileParam (*.job)" do
|
341
|
-
decls = wrap_decl SrcFileParam.new
|
342
|
-
pvals = apply_values(decls, {'src-file' => '/some/path.txt'})
|
343
|
-
params = pvals.resolve(default_context, default_variables)
|
344
|
-
assert_equal Pathname.new('/some/path.txt'), params['src-file']
|
345
|
-
end
|
346
|
-
|
347
|
-
test "SrcFileParam (--opt)" do
|
348
|
-
decls = wrap_decl SrcFileParam.new
|
349
|
-
pvals = apply_options(decls, ['--src-file=/some/path.txt'])
|
350
|
-
params = pvals.resolve(default_context, default_variables)
|
351
|
-
assert_equal Pathname.new('/some/path.txt'), params['src-file']
|
352
|
-
end
|
353
|
-
|
354
|
-
test "SrcFileParam (no value error)" do
|
355
|
-
decls = wrap_decl SrcFileParam.new
|
356
|
-
pvals = apply_values(decls, {})
|
357
|
-
assert_raise(ParameterError) {
|
358
|
-
pvals.resolve(default_context, default_variables)
|
359
|
-
}
|
360
|
-
end
|
361
|
-
|
362
|
-
# KeyValuePairsParam (3)
|
363
|
-
|
364
|
-
test "KeyValuePairsParam (*.job)" do
|
365
|
-
decls = wrap_decl KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed.')
|
366
|
-
pvals = apply_values(decls, {'grant' => {'on'=>'tbl', 'to'=>'$user'}})
|
367
|
-
vars = ResolvedVariables.new
|
368
|
-
vars.add ResolvedVariable.new('user', 'group gg')
|
369
|
-
params = pvals.resolve(default_context, vars)
|
370
|
-
assert_equal({'on'=>'tbl', 'to'=>'group gg'}, params['grant'])
|
371
|
-
end
|
372
|
-
|
373
|
-
test "KeyValuePairsParam (default value)" do
|
374
|
-
decls = wrap_decl KeyValuePairsParam.new('grant', 'KEY:VALUE', 'GRANT table after SQL is executed.')
|
375
|
-
pvals = apply_values(decls, {})
|
376
|
-
params = pvals.resolve(default_context, default_variables)
|
377
|
-
assert_nil params['grant']
|
378
|
-
end
|
379
|
-
|
380
|
-
# StringListParam (1)
|
381
|
-
|
382
|
-
test "StringListParam (*.job)" do
|
383
|
-
decls = wrap_decl StringListParam.new('args', 'ARG', 'Command line arguments.', publish: true)
|
384
|
-
pvals = apply_values(decls, {'args' => ['a', '$basedir', 'c']})
|
385
|
-
vars = ResolvedVariables.new
|
386
|
-
vars.add ResolvedVariable.new('basedir', '/base/dir')
|
387
|
-
params = pvals.resolve(default_context, vars)
|
388
|
-
assert_equal ['a', '/base/dir', 'c'], params['args']
|
389
|
-
assert_equal 'a /base/dir c', params.variables['args']
|
390
|
-
end
|
391
|
-
|
392
|
-
test "StringListParam (missing value)" do
|
393
|
-
decls = wrap_decl StringListParam.new('args', 'ARG', 'Command line arguments.')
|
394
|
-
pvals = apply_values(decls, {})
|
395
|
-
assert_raise(ParameterError) {
|
396
|
-
pvals.resolve(default_context, default_variables)
|
397
|
-
}
|
398
|
-
end
|
399
|
-
|
400
|
-
end
|
401
|
-
end
|
data/test/test_psqldatasource.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'bricolage/psqldatasource'
|
3
|
-
|
4
|
-
module Bricolage
|
5
|
-
class TestPSQLLoadOptions < Test::Unit::TestCase
|
6
|
-
test "load option is correctly formatted" do
|
7
|
-
assert_equal 'gzip', PSQLLoadOptions::Option.new('gzip', true).to_s
|
8
|
-
assert_equal "json 'auto'", PSQLLoadOptions::Option.new('json', 'auto').to_s
|
9
|
-
assert_equal 'encoding utf16le', PSQLLoadOptions::Option.new('encoding', 'utf16le').to_s
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|