masamune 0.17.12 → 0.17.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +3 -3
- data/bin/masamune-aws-emr +1 -1
- data/bin/masamune-dump +1 -1
- data/bin/masamune-hive +1 -1
- data/bin/masamune-psql +1 -1
- data/bin/masamune-shell +1 -1
- data/lib/masamune.rb +1 -1
- data/lib/masamune/actions/aws_emr.rb +2 -2
- data/lib/masamune/actions/data_flow.rb +10 -10
- data/lib/masamune/actions/date_parse.rb +4 -6
- data/lib/masamune/actions/execute.rb +3 -3
- data/lib/masamune/actions/filesystem.rb +1 -1
- data/lib/masamune/actions/hadoop_filesystem.rb +2 -2
- data/lib/masamune/actions/hive.rb +5 -5
- data/lib/masamune/actions/invoke_parallel.rb +5 -5
- data/lib/masamune/actions/postgres.rb +6 -6
- data/lib/masamune/actions/postgres_admin.rb +1 -1
- data/lib/masamune/actions/s3cmd.rb +3 -3
- data/lib/masamune/actions/transform.rb +4 -4
- data/lib/masamune/after_initialize_callbacks.rb +4 -4
- data/lib/masamune/cached_filesystem.rb +7 -11
- data/lib/masamune/commands/aws_emr.rb +12 -12
- data/lib/masamune/commands/hadoop_filesystem.rb +8 -8
- data/lib/masamune/commands/hadoop_streaming.rb +16 -16
- data/lib/masamune/commands/hive.rb +31 -35
- data/lib/masamune/commands/postgres.rb +30 -32
- data/lib/masamune/commands/postgres_admin.rb +17 -16
- data/lib/masamune/commands/postgres_common.rb +1 -1
- data/lib/masamune/commands/retry_with_backoff.rb +19 -19
- data/lib/masamune/commands/s3cmd.rb +7 -7
- data/lib/masamune/commands/shell.rb +25 -38
- data/lib/masamune/configuration.rb +8 -9
- data/lib/masamune/data_plan/builder.rb +5 -5
- data/lib/masamune/data_plan/elem.rb +7 -7
- data/lib/masamune/data_plan/engine.rb +12 -15
- data/lib/masamune/data_plan/rule.rb +14 -12
- data/lib/masamune/data_plan/set.rb +13 -13
- data/lib/masamune/environment.rb +3 -3
- data/lib/masamune/filesystem.rb +29 -28
- data/lib/masamune/helpers/postgres.rb +8 -5
- data/lib/masamune/io.rb +2 -2
- data/lib/masamune/last_element.rb +3 -3
- data/lib/masamune/method_logger.rb +1 -1
- data/lib/masamune/schema/catalog.rb +9 -12
- data/lib/masamune/schema/column.rb +12 -10
- data/lib/masamune/schema/dimension.rb +5 -4
- data/lib/masamune/schema/fact.rb +2 -2
- data/lib/masamune/schema/map.rb +9 -13
- data/lib/masamune/schema/row.rb +3 -2
- data/lib/masamune/schema/store.rb +13 -14
- data/lib/masamune/schema/table.rb +24 -28
- data/lib/masamune/schema/table_reference.rb +7 -7
- data/lib/masamune/spec_helper.rb +1 -1
- data/lib/masamune/string_format.rb +1 -1
- data/lib/masamune/tasks/aws_emr_thor.rb +9 -9
- data/lib/masamune/tasks/dump_thor.rb +5 -5
- data/lib/masamune/tasks/hive_thor.rb +13 -13
- data/lib/masamune/tasks/postgres_thor.rb +8 -8
- data/lib/masamune/tasks/shell_thor.rb +3 -3
- data/lib/masamune/template.rb +4 -4
- data/lib/masamune/thor.rb +26 -25
- data/lib/masamune/transform/common/denormalize_table.rb +6 -6
- data/lib/masamune/transform/define_table.rb +1 -1
- data/lib/masamune/transform/hive/define_table.rb +0 -2
- data/lib/masamune/transform/insert_reference_values.rb +1 -1
- data/lib/masamune/transform/operator.rb +3 -2
- data/lib/masamune/transform/postgres/bulk_upsert.rb +0 -3
- data/lib/masamune/transform/postgres/deduplicate_dimension.rb +4 -6
- data/lib/masamune/transform/postgres/define_table.rb +2 -2
- data/lib/masamune/transform/postgres/insert_reference_values.rb +1 -4
- data/lib/masamune/transform/postgres/relabel_dimension.rb +1 -3
- data/lib/masamune/transform/postgres/rollup_fact.rb +3 -5
- data/lib/masamune/transform/postgres/snapshot_dimension.rb +1 -4
- data/lib/masamune/transform/postgres/stage_dimension.rb +8 -10
- data/lib/masamune/transform/postgres/stage_fact.rb +15 -14
- data/lib/masamune/version.rb +1 -1
- data/spec/masamune/actions/aws_emr_spec.rb +8 -8
- data/spec/masamune/actions/execute_spec.rb +6 -6
- data/spec/masamune/actions/hive_spec.rb +20 -15
- data/spec/masamune/actions/postgres_spec.rb +17 -10
- data/spec/masamune/after_initialization_callbacks_spec.rb +13 -7
- data/spec/masamune/commands/aws_emr_spec.rb +10 -10
- data/spec/masamune/commands/hadoop_filesystem_spec.rb +3 -3
- data/spec/masamune/commands/hadoop_streaming_spec.rb +4 -4
- data/spec/masamune/commands/hive_spec.rb +11 -11
- data/spec/masamune/commands/postgres_admin_spec.rb +9 -9
- data/spec/masamune/commands/postgres_spec.rb +15 -15
- data/spec/masamune/commands/retry_with_backoff_spec.rb +10 -7
- data/spec/masamune/commands/s3cmd_spec.rb +3 -3
- data/spec/masamune/commands/shell_spec.rb +16 -16
- data/spec/masamune/data_plan/builder_spec.rb +22 -19
- data/spec/masamune/data_plan/elem_spec.rb +20 -20
- data/spec/masamune/data_plan/engine_spec.rb +41 -33
- data/spec/masamune/data_plan/rule_spec.rb +19 -19
- data/spec/masamune/data_plan/set_spec.rb +8 -6
- data/spec/masamune/environment_spec.rb +5 -5
- data/spec/masamune/filesystem_spec.rb +87 -87
- data/spec/masamune/helpers/postgres_spec.rb +1 -1
- data/spec/masamune/rspec/job_fixture_spec.rb +0 -1
- data/spec/masamune/schema/catalog_spec.rb +16 -16
- data/spec/masamune/schema/column_spec.rb +19 -19
- data/spec/masamune/schema/dimension_spec.rb +2 -2
- data/spec/masamune/schema/fact_spec.rb +3 -3
- data/spec/masamune/schema/map_spec.rb +41 -41
- data/spec/masamune/schema/table_spec.rb +16 -16
- data/spec/masamune/string_format_spec.rb +7 -7
- data/spec/masamune/tasks/dump_thor_spec.rb +6 -6
- data/spec/masamune/tasks/hive_thor_spec.rb +2 -2
- data/spec/masamune/template_spec.rb +3 -2
- data/spec/masamune/thor_spec.rb +8 -8
- data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +3 -3
- data/spec/masamune/transform/define_table.dimension_spec.rb +3 -3
- data/spec/masamune/transform/define_table.fact_spec.rb +5 -5
- data/spec/masamune/transform/define_table.table_spec.rb +6 -6
- data/spec/masamune/transform/denormalize_table_spec.rb +15 -15
- data/spec/masamune/transform/insert_reference_values.dimension_spec.rb +1 -1
- data/spec/masamune/transform/load_dimension_spec.rb +1 -1
- data/spec/masamune/transform/load_fact_spec.rb +1 -1
- data/spec/masamune/transform/rollup_fact_spec.rb +4 -4
- data/spec/masamune/transform/stage_dimension_spec.rb +3 -3
- data/spec/masamune/transform/stage_fact_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/support/masamune/example_group.rb +2 -2
- data/spec/support/masamune/job_example_group.rb +3 -3
- data/spec/support/masamune/job_fixture.rb +4 -4
- data/spec/support/masamune/mock_command.rb +10 -10
- data/spec/support/masamune/mock_delegate.rb +2 -2
- data/spec/support/masamune/mock_filesystem.rb +3 -3
- data/spec/support/masamune/shared_example_group.rb +14 -16
- data/spec/support/masamune/step_example_group.rb +4 -4
- data/spec/support/masamune/step_fixture.rb +1 -1
- data/spec/support/masamune/task_example_group.rb +1 -1
- data/spec/support/masamune/thor_mute.rb +3 -2
- data/spec/support/rspec/example/action_example_group.rb +1 -1
- data/spec/support/rspec/example/task_example_group.rb +7 -4
- data/spec/support/rspec/example/transform_example_group.rb +1 -1
- data/spec/support/shared_examples/postgres_common_examples.rb +2 -2
- metadata +16 -2
data/lib/masamune/environment.rb
CHANGED
@@ -54,7 +54,7 @@ module Masamune
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def with_exclusive_lock(name)
|
57
|
-
raise 'filesystem path :run_dir not defined' unless filesystem.
|
57
|
+
raise 'filesystem path :run_dir not defined' unless filesystem.path?(:run_dir)
|
58
58
|
lock_name = [name, configuration.lock].compact.join(':')
|
59
59
|
logger.debug("acquiring lock '#{lock_name}'")
|
60
60
|
lock_file = lock_file(lock_name)
|
@@ -80,7 +80,7 @@ module Masamune
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def log_file_template
|
83
|
-
@log_file_template || "#{Time.now.to_i}-#{
|
83
|
+
@log_file_template || "#{Time.now.to_i}-#{$PROCESS_ID}.log"
|
84
84
|
end
|
85
85
|
|
86
86
|
def log_file_template=(log_file_template)
|
@@ -149,7 +149,7 @@ module Masamune
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def log_file_io
|
152
|
-
if filesystem.
|
152
|
+
if filesystem.path?(:log_dir)
|
153
153
|
log_file = File.open(log_file_name, 'a')
|
154
154
|
log_file.sync = true
|
155
155
|
configuration.debug ? Masamune::MultiIO.new($stderr, log_file) : log_file
|
data/lib/masamune/filesystem.rb
CHANGED
@@ -54,7 +54,7 @@ module Masamune
|
|
54
54
|
def get_path(symbol, *args)
|
55
55
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
56
56
|
lazy_path = lambda do |fs|
|
57
|
-
fs.
|
57
|
+
fs.path?(symbol) || raise("Path :#{symbol} not defined")
|
58
58
|
path, options = fs.paths[symbol]
|
59
59
|
|
60
60
|
mkdir!(path) if options[:mkdir]
|
@@ -67,15 +67,13 @@ module Masamune
|
|
67
67
|
lazy_path
|
68
68
|
end
|
69
69
|
end
|
70
|
-
alias
|
70
|
+
alias path get_path
|
71
71
|
|
72
|
-
def
|
73
|
-
@paths.
|
72
|
+
def path?(symbol)
|
73
|
+
@paths.key?(symbol)
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
|
-
@paths
|
78
|
-
end
|
76
|
+
attr_reader :paths
|
79
77
|
|
80
78
|
def eval_path(path)
|
81
79
|
path.respond_to?(:call) ? path.call(self) : path
|
@@ -84,7 +82,7 @@ module Masamune
|
|
84
82
|
def expand_params(fs, path)
|
85
83
|
new_path = path.dup
|
86
84
|
fs.environment.configuration.params.each do |key, value|
|
87
|
-
new_path.gsub!("%#{key
|
85
|
+
new_path.gsub!("%#{key}", value.to_s)
|
88
86
|
end
|
89
87
|
new_path
|
90
88
|
end
|
@@ -95,7 +93,8 @@ module Masamune
|
|
95
93
|
end
|
96
94
|
|
97
95
|
def parent_paths(path)
|
98
|
-
|
96
|
+
prefix = remote_prefix(path)
|
97
|
+
if prefix
|
99
98
|
node = path.split(prefix).last
|
100
99
|
else
|
101
100
|
prefix = ''
|
@@ -104,7 +103,7 @@ module Masamune
|
|
104
103
|
|
105
104
|
return [] if prefix.blank? && node.blank?
|
106
105
|
parent_paths = node ? File.expand_path(node, '/').split('/') : []
|
107
|
-
parent_paths.reject!
|
106
|
+
parent_paths.reject!(&:blank?)
|
108
107
|
parent_paths.prepend('/') if node =~ %r{\A/}
|
109
108
|
tmp = []
|
110
109
|
result = []
|
@@ -125,7 +124,7 @@ module Masamune
|
|
125
124
|
end
|
126
125
|
|
127
126
|
def resolve_file(paths = [])
|
128
|
-
Array.wrap(paths).select { |path| File.
|
127
|
+
Array.wrap(paths).select { |path| File.exist?(path) && File.file?(path) }.first
|
129
128
|
end
|
130
129
|
|
131
130
|
def dirname(path)
|
@@ -165,12 +164,12 @@ module Masamune
|
|
165
164
|
when :s3
|
166
165
|
result = Set.new
|
167
166
|
s3cmd('ls', s3b(file), safe: true) do |line|
|
168
|
-
|
167
|
+
_date, _time, _size, name = line.split(/\s+/)
|
169
168
|
result << (name == file)
|
170
169
|
end
|
171
170
|
result.any?
|
172
171
|
when :local
|
173
|
-
File.
|
172
|
+
File.exist?(file)
|
174
173
|
end
|
175
174
|
end
|
176
175
|
|
@@ -218,9 +217,9 @@ module Masamune
|
|
218
217
|
when :hdfs
|
219
218
|
hadoop_fs('-mkdir', '-p', *dir_set)
|
220
219
|
when :s3
|
221
|
-
touch!
|
220
|
+
touch!(*dir_set.map { |dir| File.join(dir, '.not_empty') })
|
222
221
|
when :local
|
223
|
-
missing_dir_set = dir_set.reject { |dir| File.
|
222
|
+
missing_dir_set = dir_set.reject { |dir| File.exist?(dir) }
|
224
223
|
FileUtils.mkdir_p(missing_dir_set, file_util_args) if missing_dir_set.any?
|
225
224
|
end
|
226
225
|
end
|
@@ -230,7 +229,7 @@ module Masamune
|
|
230
229
|
return Set.new(to_enum(:glob, pattern, options)) unless block_given?
|
231
230
|
case type(pattern)
|
232
231
|
when :hdfs
|
233
|
-
|
232
|
+
_file_glob, file_regexp = glob_split(pattern)
|
234
233
|
hadoop_fs('-ls', pattern, safe: true) do |line|
|
235
234
|
next if line =~ /\AFound \d+ items/
|
236
235
|
name = line.split(/\s+/).last
|
@@ -258,7 +257,7 @@ module Masamune
|
|
258
257
|
return to_enum(:glob_sort, pattern, options).to_a unless block_given?
|
259
258
|
case options[:order]
|
260
259
|
when :basename
|
261
|
-
glob(pattern).sort { |x,y| File.basename(x) <=> File.basename(y) }.each do |result|
|
260
|
+
glob(pattern).sort { |x, y| File.basename(x) <=> File.basename(y) }.each do |result|
|
262
261
|
yield result
|
263
262
|
end
|
264
263
|
else
|
@@ -381,7 +380,7 @@ module Masamune
|
|
381
380
|
case type
|
382
381
|
when :local
|
383
382
|
file_set.map do |file|
|
384
|
-
next unless File.
|
383
|
+
next unless File.exist?(file)
|
385
384
|
next if File.directory?(file)
|
386
385
|
buf << File.read(file)
|
387
386
|
end
|
@@ -403,7 +402,8 @@ module Masamune
|
|
403
402
|
|
404
403
|
def chown!(*files)
|
405
404
|
opts = files.last.is_a?(Hash) ? files.pop : {}
|
406
|
-
user
|
405
|
+
user = opts.fetch(:user, current_user)
|
406
|
+
group = opts.fetch(:group, current_group)
|
407
407
|
|
408
408
|
files.group_by { |path| type(path) }.each do |type, file_set|
|
409
409
|
case type
|
@@ -430,12 +430,12 @@ module Masamune
|
|
430
430
|
end
|
431
431
|
|
432
432
|
def glob_split(input, options = {})
|
433
|
-
[
|
433
|
+
[input.include?('*') ? input.split('*').first + '*' : input, glob_to_regexp(input, options)]
|
434
434
|
end
|
435
435
|
|
436
436
|
def glob_to_regexp(input, options = {})
|
437
437
|
if input.include?('*') || options.fetch(:recursive, false)
|
438
|
-
|
438
|
+
/\A#{Regexp.escape(input).gsub('\\*', '.*?').gsub(%r{\/\.\*\?\z}, '/?.*?')}/
|
439
439
|
else
|
440
440
|
/\A#{Regexp.escape(input)}\z/
|
441
441
|
end
|
@@ -472,7 +472,7 @@ module Masamune
|
|
472
472
|
end
|
473
473
|
|
474
474
|
def eager_load_paths?
|
475
|
-
@paths.reject { |key,_| key == :root_dir }.any?
|
475
|
+
@paths.reject { |key, _| key == :root_dir }.any?
|
476
476
|
end
|
477
477
|
|
478
478
|
def type(path)
|
@@ -487,27 +487,27 @@ module Masamune
|
|
487
487
|
end
|
488
488
|
|
489
489
|
def file_util_args
|
490
|
-
{noop: configuration.dry_run, verbose: configuration.verbose}
|
490
|
+
{ noop: configuration.dry_run, verbose: configuration.verbose }
|
491
491
|
end
|
492
492
|
|
493
493
|
def qualify_file(dir, file)
|
494
|
-
if prefix = remote_prefix(dir)
|
494
|
+
if (prefix = remote_prefix(dir)) && file !~ /\A#{Regexp.escape(prefix)}/
|
495
495
|
"#{prefix}/#{file.sub(%r{\A/+}, '')}"
|
496
496
|
else
|
497
497
|
file
|
498
498
|
end
|
499
499
|
end
|
500
|
-
alias
|
500
|
+
alias q qualify_file
|
501
501
|
|
502
502
|
def ensure_dir(dir)
|
503
503
|
File.join(dir, '/')
|
504
504
|
end
|
505
|
-
alias
|
505
|
+
alias d ensure_dir
|
506
506
|
|
507
507
|
def ensure_file(file)
|
508
508
|
file.chomp('/')
|
509
509
|
end
|
510
|
-
alias
|
510
|
+
alias f ensure_file
|
511
511
|
|
512
512
|
def add_immutable_path(path)
|
513
513
|
@immutable_paths[path] = /\A#{Regexp.escape(path)}/
|
@@ -526,6 +526,7 @@ module Masamune
|
|
526
526
|
def current_group
|
527
527
|
Etc.getgrgid(Etc.getpwnam(current_user).gid).name
|
528
528
|
rescue
|
529
|
+
nil
|
529
530
|
end
|
530
531
|
|
531
532
|
def copy_file_helper(src, dst, dir)
|
@@ -569,7 +570,7 @@ module Masamune
|
|
569
570
|
s3cmd('del', src)
|
570
571
|
when [:s3, :hdfs]
|
571
572
|
hadoop_fs('-mv', s3n(src), dst)
|
572
|
-
|
573
|
+
when [:local, :local]
|
573
574
|
FileUtils.mv(src, dst, file_util_args)
|
574
575
|
FileUtils.chmod(FILE_MODE, dst, file_util_args)
|
575
576
|
when [:local, :hdfs]
|
@@ -66,7 +66,7 @@ module Masamune::Helpers
|
|
66
66
|
return unless @cache.empty?
|
67
67
|
postgres(exec: 'SELECT table_name FROM information_schema.tables;', tuple_output: true, retries: 0) do |line|
|
68
68
|
table = line.strip
|
69
|
-
next if table
|
69
|
+
next if table.start_with?('pg_')
|
70
70
|
@cache[table] ||= nil
|
71
71
|
end
|
72
72
|
end
|
@@ -74,11 +74,14 @@ module Masamune::Helpers
|
|
74
74
|
def update_table_last_modified_at(table, column)
|
75
75
|
return if @cache[table].present?
|
76
76
|
postgres(exec: "SELECT MAX(#{column}) FROM #{table};", tuple_output: true, retries: 0) do |line|
|
77
|
-
|
78
|
-
@cache[table] = Time.parse(line.strip).at_beginning_of_minute.utc
|
79
|
-
rescue ArgumentError
|
80
|
-
end
|
77
|
+
@cache[table] = parse_date_time(line.strip)
|
81
78
|
end
|
82
79
|
end
|
80
|
+
|
81
|
+
def parse_date_time(value)
|
82
|
+
Time.parse(value).at_beginning_of_minute.utc
|
83
|
+
rescue ArgumentError
|
84
|
+
nil
|
85
|
+
end
|
83
86
|
end
|
84
87
|
end
|
data/lib/masamune/io.rb
CHANGED
@@ -22,12 +22,12 @@
|
|
22
22
|
|
23
23
|
class IO
|
24
24
|
def wait_readable(timeout = 0)
|
25
|
-
rs,
|
25
|
+
rs, _ws = IO.select([self], [], [], timeout)
|
26
26
|
rs && rs[0]
|
27
27
|
end unless IO.method_defined?(:wait_readable)
|
28
28
|
|
29
29
|
def wait_writable(timeout = 0)
|
30
|
-
|
30
|
+
_rs, ws = IO.select([], [self], [], timeout)
|
31
31
|
ws && ws[0]
|
32
32
|
end unless IO.method_defined?(:wait_writable)
|
33
33
|
end
|
@@ -36,12 +36,12 @@ module Masamune
|
|
36
36
|
|
37
37
|
module ClassMethods
|
38
38
|
def method_with_last_element(method)
|
39
|
-
|
39
|
+
class_eval do
|
40
40
|
new_method = "#{method}_with_last_element"
|
41
41
|
old_method = "#{method}_without_last_element"
|
42
42
|
alias_method old_method, method
|
43
|
-
define_method(new_method) do |*args
|
44
|
-
last_element(old_method,
|
43
|
+
define_method(new_method) do |*args|
|
44
|
+
last_element(old_method, *args)
|
45
45
|
end
|
46
46
|
alias_method method, new_method
|
47
47
|
end
|
@@ -37,7 +37,7 @@ module Masamune::Schema
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def map(options = {})
|
40
|
-
|
40
|
+
maps[options[:to]]
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -66,8 +66,8 @@ module Masamune::Schema
|
|
66
66
|
def initialize(store, options = {})
|
67
67
|
super store
|
68
68
|
@store = store
|
69
|
-
@options = Hash.new { |h,k| h[k] = [] }
|
70
|
-
@options
|
69
|
+
@options = Hash.new { |h, k| h[k] = [] }
|
70
|
+
@options[:store] = @store
|
71
71
|
@options.merge!(options)
|
72
72
|
end
|
73
73
|
|
@@ -83,7 +83,7 @@ module Masamune::Schema
|
|
83
83
|
|
84
84
|
def initialize(environment)
|
85
85
|
self.environment = environment
|
86
|
-
@stores = Hash.new { |h,k| h[k] = Masamune::Schema::Store.new(environment, type: k) }
|
86
|
+
@stores = Hash.new { |h, k| h[k] = Masamune::Schema::Store.new(environment, type: k) }
|
87
87
|
@context = nil
|
88
88
|
end
|
89
89
|
|
@@ -98,7 +98,7 @@ module Masamune::Schema
|
|
98
98
|
stores.each do |id|
|
99
99
|
begin
|
100
100
|
@context = Context.new(@stores[id], options)
|
101
|
-
instance_eval
|
101
|
+
instance_eval(&block)
|
102
102
|
ensure
|
103
103
|
@context = nil
|
104
104
|
end
|
@@ -182,14 +182,11 @@ module Masamune::Schema
|
|
182
182
|
@context.pop
|
183
183
|
end
|
184
184
|
|
185
|
-
def attribute(id, options = {})
|
186
|
-
@context.options[:attributes] << Masamune::Schema::Event::Attribute.new(options.merge(id: id))
|
187
|
-
end
|
188
|
-
|
189
185
|
def map(options = {}, &block)
|
190
|
-
raise ArgumentError,
|
191
|
-
from
|
192
|
-
|
186
|
+
raise ArgumentError, 'invalid map, from: is missing' unless options.is_a?(Hash)
|
187
|
+
from = options.delete(:from)
|
188
|
+
to = options.delete(:to)
|
189
|
+
raise ArgumentError, 'invalid map, from: is missing' unless from && from.try(:id)
|
193
190
|
raise ArgumentError, "invalid map from: '#{from.id}', to: is missing" unless to
|
194
191
|
@context.push(options)
|
195
192
|
@context.options[:function] = block.to_proc if block
|
@@ -47,7 +47,7 @@ module Masamune::Schema
|
|
47
47
|
reference: nil,
|
48
48
|
parent: nil,
|
49
49
|
debug: false
|
50
|
-
}
|
50
|
+
}.freeze
|
51
51
|
|
52
52
|
DEFAULT_ATTRIBUTES.keys.each do |attr|
|
53
53
|
attr_accessor attr
|
@@ -139,7 +139,7 @@ module Masamune::Schema
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def reference_name(label = nil)
|
142
|
-
qualified_name(label).to_s.
|
142
|
+
qualified_name(label).to_s.tr('.', '_').to_sym
|
143
143
|
end
|
144
144
|
|
145
145
|
def sql_type(for_surrogate_key = false)
|
@@ -209,7 +209,11 @@ module Masamune::Schema
|
|
209
209
|
return nil if value.nil?
|
210
210
|
case type
|
211
211
|
when :boolean
|
212
|
-
value
|
212
|
+
if value
|
213
|
+
'TRUE'
|
214
|
+
else
|
215
|
+
hive_encoding? ? nil : 'FALSE'
|
216
|
+
end
|
213
217
|
when :yaml
|
214
218
|
value.to_hash.to_yaml
|
215
219
|
when :json, :key_value
|
@@ -298,14 +302,12 @@ module Masamune::Schema
|
|
298
302
|
|
299
303
|
def default_ruby_value
|
300
304
|
return [] if array_value?
|
301
|
-
return HashWithIndifferentAccess.new { |h,k| h[k] = HashWithIndifferentAccess.new(&h.default_proc) } if hash_value?
|
305
|
+
return HashWithIndifferentAccess.new { |h, k| h[k] = HashWithIndifferentAccess.new(&h.default_proc) } if hash_value?
|
302
306
|
case type
|
303
307
|
when :date
|
304
308
|
Date.new(0)
|
305
309
|
when :timestamp
|
306
310
|
Time.new(0)
|
307
|
-
else
|
308
|
-
nil
|
309
311
|
end
|
310
312
|
end
|
311
313
|
|
@@ -348,7 +350,7 @@ module Masamune::Schema
|
|
348
350
|
end
|
349
351
|
|
350
352
|
def array_value?
|
351
|
-
|
353
|
+
(array || (reference && reference.respond_to?(:multiple) && reference.multiple)) == true
|
352
354
|
end
|
353
355
|
|
354
356
|
def hash_value?
|
@@ -364,7 +366,7 @@ module Masamune::Schema
|
|
364
366
|
end
|
365
367
|
|
366
368
|
def as_hash
|
367
|
-
{id: id}.tap do |hash|
|
369
|
+
{ id: id }.tap do |hash|
|
368
370
|
DEFAULT_ATTRIBUTES.keys.each do |attr|
|
369
371
|
hash[attr] = public_send(attr)
|
370
372
|
end
|
@@ -451,7 +453,7 @@ module Masamune::Schema
|
|
451
453
|
def required_value?
|
452
454
|
return false if reference && (reference.null || !reference.default.nil?)
|
453
455
|
return false if null || !default.nil?
|
454
|
-
return false
|
456
|
+
return false unless strict
|
455
457
|
true
|
456
458
|
end
|
457
459
|
|
@@ -465,7 +467,7 @@ module Masamune::Schema
|
|
465
467
|
|
466
468
|
def sql_default
|
467
469
|
return if default.nil?
|
468
|
-
return
|
470
|
+
return unless strict
|
469
471
|
"DEFAULT #{sql_value(default)}"
|
470
472
|
end
|
471
473
|
|
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
module Masamune::Schema
|
24
24
|
class Dimension < Table
|
25
|
-
SUPPORTED_GRAINS = [:hourly, :daily, :monthly]
|
25
|
+
SUPPORTED_GRAINS = [:hourly, :daily, :monthly].freeze
|
26
26
|
|
27
27
|
def initialize(opts = {})
|
28
28
|
opts.symbolize_keys!
|
@@ -48,7 +48,8 @@ module Masamune::Schema
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def suffix
|
51
|
-
suffix =
|
51
|
+
suffix =
|
52
|
+
case type
|
52
53
|
when :mini
|
53
54
|
'type'
|
54
55
|
when :one, :two, :four, :date
|
@@ -111,7 +112,7 @@ module Masamune::Schema
|
|
111
112
|
end
|
112
113
|
|
113
114
|
def initialize_dimension_columns!
|
114
|
-
# TODO assign index for load_fact
|
115
|
+
# TODO: assign index for load_fact
|
115
116
|
case type
|
116
117
|
when :one, :date
|
117
118
|
initialize_column! id: 'last_modified_at', type: :timestamp, default: 'NOW()'
|
@@ -122,7 +123,7 @@ module Masamune::Schema
|
|
122
123
|
initialize_column! id: 'last_modified_at', type: :timestamp, default: 'NOW()'
|
123
124
|
when :four
|
124
125
|
children << ledger_table
|
125
|
-
# FIXME derive type from from parent
|
126
|
+
# FIXME: derive type from from parent
|
126
127
|
initialize_column! id: 'start_at', type: :timestamp, default: 'TO_TIMESTAMP(0)', index: [:start_at, :natural], unique: :natural
|
127
128
|
initialize_column! id: 'end_at', type: :timestamp, null: true, index: :end_at
|
128
129
|
initialize_column! id: 'version', type: :integer, default: 1, null: true
|