masamune 0.17.12 → 0.17.13
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -29,26 +29,26 @@ module Masamune::Tasks
|
|
29
29
|
include Masamune::Actions::AwsEmr
|
30
30
|
include Masamune::Actions::Hive
|
31
31
|
|
32
|
-
# FIXME need to add an unnecessary namespace until this issue is fixed:
|
32
|
+
# FIXME: need to add an unnecessary namespace until this issue is fixed:
|
33
33
|
# https://github.com/wycats/thor/pull/247
|
34
34
|
namespace :hive
|
35
35
|
skip_lock!
|
36
36
|
|
37
37
|
desc 'hive', 'Launch a Hive session'
|
38
|
-
method_option :file, :
|
39
|
-
method_option :exec, :
|
40
|
-
method_option :output, :
|
41
|
-
method_option :delimiter, :
|
42
|
-
method_option :csv, :
|
43
|
-
method_option :variables, :
|
44
|
-
method_option :retry, :
|
45
|
-
method_option :service, :
|
38
|
+
method_option :file, aliases: '-f', desc: 'SQL from files'
|
39
|
+
method_option :exec, aliases: '-e', desc: 'SQL from command line'
|
40
|
+
method_option :output, aliases: '-o', desc: 'Save SQL output to file'
|
41
|
+
method_option :delimiter, desc: 'Hive row format delimiter', default: "\001"
|
42
|
+
method_option :csv, type: :boolean, desc: 'Report SQL output in CSV format', default: false
|
43
|
+
method_option :variables, aliases: '-X', type: :hash, desc: 'Variables to substitute in SQL', default: {}
|
44
|
+
method_option :retry, type: :boolean, desc: 'Retry SQL query in event of failure', default: false
|
45
|
+
method_option :service, desc: 'Start as a service', default: false
|
46
46
|
def hive_exec
|
47
47
|
hive_options = options.dup.with_indifferent_access
|
48
|
-
hive_options
|
49
|
-
hive_options
|
50
|
-
hive_options
|
51
|
-
hive_options
|
48
|
+
hive_options[:print] = true
|
49
|
+
hive_options[:retries] = 0 unless options[:retry]
|
50
|
+
hive_options[:file] = File.expand_path(options[:file]) if options[:file]
|
51
|
+
hive_options[:output] = File.expand_path(options[:output]) if options[:output]
|
52
52
|
hive(hive_options)
|
53
53
|
end
|
54
54
|
default_task :hive_exec
|
@@ -28,21 +28,21 @@ module Masamune::Tasks
|
|
28
28
|
include Masamune::Thor
|
29
29
|
include Masamune::Actions::Postgres
|
30
30
|
|
31
|
-
# FIXME need to add an unnecessary namespace until this issue is fixed:
|
31
|
+
# FIXME: need to add an unnecessary namespace until this issue is fixed:
|
32
32
|
# https://github.com/wycats/thor/pull/247
|
33
33
|
namespace :postgres
|
34
34
|
skip_lock!
|
35
35
|
|
36
36
|
desc 'psql', 'Launch a Postgres session'
|
37
|
-
method_option :file, :
|
38
|
-
method_option :exec, :
|
39
|
-
method_option :output, :
|
40
|
-
method_option :csv, :
|
41
|
-
method_option :retry, :
|
37
|
+
method_option :file, aliases: '-f', desc: 'SQL from files'
|
38
|
+
method_option :exec, aliases: '-e', desc: 'SQL from command line'
|
39
|
+
method_option :output, aliases: '-o', desc: 'Save SQL output to file'
|
40
|
+
method_option :csv, type: :boolean, desc: 'Report SQL output in CSV format', default: false
|
41
|
+
method_option :retry, type: :boolean, desc: 'Retry SQL query in event of failure', default: false
|
42
42
|
def psql_exec
|
43
43
|
postgres_options = options.dup.with_indifferent_access
|
44
|
-
postgres_options
|
45
|
-
postgres_options
|
44
|
+
postgres_options[:print] = true
|
45
|
+
postgres_options[:retries] = 0 unless options[:retry]
|
46
46
|
postgres(postgres_options)
|
47
47
|
end
|
48
48
|
default_task :psql_exec
|
@@ -29,15 +29,15 @@ module Masamune::Tasks
|
|
29
29
|
include Masamune::Thor
|
30
30
|
include Masamune::Actions::DataFlow
|
31
31
|
|
32
|
-
# FIXME need to add an unnecessary namespace until this issue is fixed:
|
32
|
+
# FIXME: need to add an unnecessary namespace until this issue is fixed:
|
33
33
|
# https://github.com/wycats/thor/pull/247
|
34
34
|
namespace :shell
|
35
35
|
skip_lock!
|
36
36
|
|
37
37
|
desc 'shell', 'Launch an interactive shell'
|
38
38
|
skip
|
39
|
-
method_option :prompt, :
|
40
|
-
class_option :start, :
|
39
|
+
method_option :prompt, desc: 'Set shell prompt', default: 'masamune'
|
40
|
+
class_option :start, aliases: '-a', desc: 'Start time', default: '1 month ago'
|
41
41
|
def shell_exec
|
42
42
|
Pry.start self, prompt: proc { options[:prompt] + '> ' }
|
43
43
|
end
|
data/lib/masamune/template.rb
CHANGED
@@ -37,14 +37,14 @@ module Masamune
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
# TODO unify with resolve_path
|
40
|
+
# TODO: unify with resolve_path
|
41
41
|
def resolve_file(partial_file)
|
42
42
|
return partial_file if Pathname.new(partial_file).absolute?
|
43
43
|
@paths.each do |path|
|
44
44
|
file = File.expand_path(File.join(path, partial_file))
|
45
|
-
if File.
|
45
|
+
if File.exist?(file) && File.file?(file)
|
46
46
|
@paths << File.dirname(file)
|
47
|
-
return file
|
47
|
+
return file
|
48
48
|
end
|
49
49
|
end
|
50
50
|
raise IOError, "File not found: #{partial_file}"
|
@@ -59,7 +59,7 @@ module Masamune
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def render_to_string(template, parameters = {})
|
62
|
-
instance =
|
62
|
+
instance = new(File.dirname(template))
|
63
63
|
combine instance.render(template, parameters)
|
64
64
|
end
|
65
65
|
|
data/lib/masamune/thor.rb
CHANGED
@@ -41,15 +41,16 @@ module Masamune
|
|
41
41
|
'/opt/etc/masamune/config.yml',
|
42
42
|
'/opt/etc/masamune/config.yml.erb',
|
43
43
|
"#{ENV['HOME']}/.masamune/config.yml"
|
44
|
-
]
|
44
|
+
].freeze
|
45
45
|
|
46
46
|
module ExtraArguments
|
47
47
|
def parse_extra(argv)
|
48
|
-
|
48
|
+
i = argv.index('--')
|
49
|
+
if i
|
49
50
|
if i > 0
|
50
|
-
[argv[0
|
51
|
+
[argv[0..i - 1], argv[i + 1..-1]]
|
51
52
|
else
|
52
|
-
[[], argv[i+1..-1]]
|
53
|
+
[[], argv[i + 1..-1]]
|
53
54
|
end
|
54
55
|
else
|
55
56
|
[argv, []]
|
@@ -70,14 +71,14 @@ module Masamune
|
|
70
71
|
super
|
71
72
|
rescue SignalException => e
|
72
73
|
raise e unless %w(SIGHUP SIGTERM).include?(e.to_s)
|
73
|
-
instance.logger.debug("Exiting at user request on #{e
|
74
|
+
instance.logger.debug("Exiting at user request on #{e}")
|
74
75
|
exit 0
|
75
76
|
rescue ::Thor::MalformattedArgumentError, ::Thor::RequiredArgumentMissingError => e
|
76
77
|
raise e
|
77
78
|
rescue => e
|
78
79
|
instance.logger.error("#{e.message} (#{e.class}) backtrace:")
|
79
80
|
e.backtrace.each { |x| instance.logger.error(x) }
|
80
|
-
$stderr.puts "For complete debug log see: #{instance.log_file_name
|
81
|
+
$stderr.puts "For complete debug log see: #{instance.log_file_name}"
|
81
82
|
abort e.message
|
82
83
|
end
|
83
84
|
end
|
@@ -94,31 +95,31 @@ module Masamune
|
|
94
95
|
attr_accessor :extra
|
95
96
|
|
96
97
|
namespace :masamune
|
97
|
-
class_option :help, :
|
98
|
-
class_option :quiet, :
|
99
|
-
class_option :verbose, :
|
100
|
-
class_option :debug, :
|
101
|
-
class_option :dry_run, :
|
102
|
-
class_option :config, :
|
103
|
-
class_option :version, :
|
104
|
-
class_option :lock, :
|
105
|
-
class_option :initialize, :
|
106
|
-
class_option :'--', :
|
107
|
-
def initialize(
|
108
|
-
|
109
|
-
|
98
|
+
class_option :help, type: :boolean, aliases: '-h', desc: 'Show help', default: false
|
99
|
+
class_option :quiet, type: :boolean, aliases: '-q', desc: 'Suppress all output', default: false
|
100
|
+
class_option :verbose, type: :boolean, aliases: '-v', desc: 'Print command execution information', default: false
|
101
|
+
class_option :debug, type: :boolean, aliases: '-d', desc: 'Print debugging information', default: false
|
102
|
+
class_option :dry_run, type: :boolean, aliases: '-n', desc: 'Do not execute commands that modify state', default: false
|
103
|
+
class_option :config, desc: 'Configuration file'
|
104
|
+
class_option :version, desc: 'Print version and exit', type: :boolean
|
105
|
+
class_option :lock, desc: 'Optional job lock name', type: :string
|
106
|
+
class_option :initialize, aliases: '--init', desc: 'Initialize configured data stores', type: :boolean, default: false
|
107
|
+
class_option :'--', desc: 'Extra pass through arguments'
|
108
|
+
def initialize(thor_args = [], thor_options = {}, thor_config = {})
|
109
|
+
environment.parent = self
|
110
|
+
filesystem.environment = self
|
110
111
|
self.current_namespace = self.class.namespace unless self.class.namespace == 'masamune'
|
111
|
-
self.current_task_name =
|
112
|
+
self.current_task_name = thor_config[:current_command].try(:name)
|
112
113
|
self.current_command_name = current_namespace ? current_namespace + ':' + current_task_name : current_task_name
|
113
114
|
self.class.instance = self
|
114
115
|
|
115
116
|
define_current_dir
|
116
117
|
|
117
|
-
if
|
118
|
-
|
118
|
+
if thor_options.is_a?(Array)
|
119
|
+
thor_options, self.extra = self.class.parse_extra(thor_options)
|
119
120
|
end
|
120
121
|
|
121
|
-
super
|
122
|
+
super thor_args, thor_options, thor_config
|
122
123
|
|
123
124
|
if display_help?
|
124
125
|
display_help
|
@@ -133,7 +134,7 @@ module Masamune
|
|
133
134
|
begin
|
134
135
|
config.load(config_file)
|
135
136
|
rescue
|
136
|
-
raise
|
137
|
+
raise $ERROR_INFO if options[:debug]
|
137
138
|
raise ::Thor::MalformattedArgumentError, "Could not load file provided for '--config'"
|
138
139
|
end
|
139
140
|
|
@@ -160,7 +161,7 @@ module Masamune
|
|
160
161
|
end
|
161
162
|
|
162
163
|
def top_level?
|
163
|
-
|
164
|
+
current_command_name == ARGV.first
|
164
165
|
end
|
165
166
|
|
166
167
|
def invoke_command(command, *args)
|
@@ -38,14 +38,13 @@ module Masamune::Transform::Common
|
|
38
38
|
TargetPresenter.new(@target)
|
39
39
|
end
|
40
40
|
|
41
|
-
private
|
42
|
-
|
43
41
|
class TargetPresenter < SimpleDelegator
|
44
42
|
include Masamune::LastElement
|
45
43
|
|
46
44
|
def select_columns(column_names)
|
47
45
|
column_names.map do |column_name|
|
48
|
-
|
46
|
+
column = dereference_column_name(column_name)
|
47
|
+
next unless column
|
49
48
|
if column.reference
|
50
49
|
if column.reference.implicit || column.reference.degenerate
|
51
50
|
"#{column.name} AS #{column.name}"
|
@@ -66,8 +65,8 @@ module Masamune::Transform::Common
|
|
66
65
|
def join_conditions(column_names)
|
67
66
|
{}.tap do |conditions|
|
68
67
|
column_names.each do |column_name|
|
69
|
-
|
70
|
-
next unless column.reference
|
68
|
+
column = dereference_column_name(column_name)
|
69
|
+
next unless column && column.reference
|
71
70
|
next if column.reference.degenerate
|
72
71
|
adjacent_reference = references[column.reference.id]
|
73
72
|
next unless adjacent_reference
|
@@ -80,7 +79,8 @@ module Masamune::Transform::Common
|
|
80
79
|
|
81
80
|
def order_by_columns(column_names)
|
82
81
|
column_names.map do |column_name|
|
83
|
-
|
82
|
+
column = dereference_column_name(column_name)
|
83
|
+
next unless column
|
84
84
|
column.name
|
85
85
|
end.compact
|
86
86
|
end
|
@@ -51,8 +51,8 @@ module Masamune::Transform
|
|
51
51
|
private
|
52
52
|
|
53
53
|
def template_eval(template)
|
54
|
-
return File.read(template) if File.
|
55
|
-
template_file = File.
|
54
|
+
return File.read(template) if File.exist?(template.to_s) && template.to_s !~ /erb\Z/
|
55
|
+
template_file = File.exist?(template.to_s) ? template : template_file(template)
|
56
56
|
if template_helper(template)
|
57
57
|
Masamune::Template.render_to_string(template_file, template_helper(template).new(@options).locals)
|
58
58
|
else
|
@@ -63,6 +63,7 @@ module Masamune::Transform
|
|
63
63
|
def template_helper(template_name)
|
64
64
|
"Masamune::Transform::#{template_type.to_s.camelize}::#{template_name.to_s.camelize}".constantize
|
65
65
|
rescue NameError
|
66
|
+
nil
|
66
67
|
end
|
67
68
|
|
68
69
|
def template_file(template_name)
|
@@ -37,8 +37,6 @@ module Masamune::Transform::Postgres
|
|
37
37
|
TargetPresenter.new(@target)
|
38
38
|
end
|
39
39
|
|
40
|
-
private
|
41
|
-
|
42
40
|
class TargetPresenter < SimpleDelegator
|
43
41
|
include Masamune::LastElement
|
44
42
|
|
@@ -59,4 +57,3 @@ module Masamune::Transform::Postgres
|
|
59
57
|
end
|
60
58
|
end
|
61
59
|
end
|
62
|
-
|
@@ -35,10 +35,8 @@ module Masamune::Transform::Postgres
|
|
35
35
|
TargetPresenter.new(@target)
|
36
36
|
end
|
37
37
|
|
38
|
-
private
|
39
|
-
|
40
38
|
class TargetPresenter < SimpleDelegator
|
41
|
-
def insert_columns(
|
39
|
+
def insert_columns(_source = nil)
|
42
40
|
consolidated_columns.map { |_, column| column.name }
|
43
41
|
end
|
44
42
|
|
@@ -61,10 +59,11 @@ module Masamune::Transform::Postgres
|
|
61
59
|
def duplicate_value_conditions(window)
|
62
60
|
[].tap do |result|
|
63
61
|
consolidated_columns.map do |_, column|
|
62
|
+
result <<
|
64
63
|
if column.null
|
65
|
-
|
64
|
+
"((LAG(#{column.name}) OVER #{window} = #{column.name}) OR (LAG(#{column.name}) OVER #{window} IS NULL AND #{column.name} IS NULL))"
|
66
65
|
else
|
67
|
-
|
66
|
+
"(LAG(#{column.name}) OVER #{window} = #{column.name})"
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
@@ -93,4 +92,3 @@ module Masamune::Transform::Postgres
|
|
93
92
|
end
|
94
93
|
end
|
95
94
|
end
|
96
|
-
|
@@ -21,7 +21,7 @@
|
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
23
|
module Masamune::Transform::Postgres
|
24
|
-
class DefineTable
|
24
|
+
class DefineTable
|
25
25
|
def initialize(options = {})
|
26
26
|
@target = options[:target]
|
27
27
|
@files = options[:files] || []
|
@@ -46,7 +46,7 @@ module Masamune::Transform::Postgres
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def skip_indexes?
|
49
|
-
|
49
|
+
@skip_indexes == true
|
50
50
|
end
|
51
51
|
|
52
52
|
def define_types?
|
@@ -39,8 +39,6 @@ module Masamune::Transform::Postgres
|
|
39
39
|
TargetPresenter.new(@target)
|
40
40
|
end
|
41
41
|
|
42
|
-
private
|
43
|
-
|
44
42
|
class TargetPresenter < SimpleDelegator
|
45
43
|
include Masamune::LastElement
|
46
44
|
|
@@ -60,10 +58,9 @@ module Masamune::Transform::Postgres
|
|
60
58
|
method_with_last_element :insert_values
|
61
59
|
|
62
60
|
def insert_constraints(source)
|
63
|
-
source.shared_columns(stage_table).reject { |column, _| column.null || column.default || column.adjacent.try(:default) }.map { |column, _| "#{column.name} IS NOT NULL"}
|
61
|
+
source.shared_columns(stage_table).reject { |column, _| column.null || column.default || column.adjacent.try(:default) }.map { |column, _| "#{column.name} IS NOT NULL" }
|
64
62
|
end
|
65
63
|
method_with_last_element :insert_constraints
|
66
64
|
end
|
67
65
|
end
|
68
66
|
end
|
69
|
-
|
@@ -23,7 +23,7 @@
|
|
23
23
|
module Masamune::Transform::Postgres
|
24
24
|
class RelabelDimension
|
25
25
|
def initialize(options = {})
|
26
|
-
@target
|
26
|
+
@target = options[:target]
|
27
27
|
end
|
28
28
|
|
29
29
|
def locals
|
@@ -34,8 +34,6 @@ module Masamune::Transform::Postgres
|
|
34
34
|
TargetPresenter.new(@target)
|
35
35
|
end
|
36
36
|
|
37
|
-
private
|
38
|
-
|
39
37
|
class TargetPresenter < SimpleDelegator
|
40
38
|
def window(*extra)
|
41
39
|
(columns.values.select { |column| extra.delete(column.name) || column.natural_key || column.auto_reference }.map(&:name) + extra).uniq
|
@@ -36,8 +36,6 @@ module Masamune::Transform::Postgres
|
|
36
36
|
TargetPresenter.new(@target)
|
37
37
|
end
|
38
38
|
|
39
|
-
private
|
40
|
-
|
41
39
|
class TargetPresenter < SimpleDelegator
|
42
40
|
include Masamune::LastElement
|
43
41
|
|
@@ -49,7 +47,7 @@ module Masamune::Transform::Postgres
|
|
49
47
|
next if column.auto_reference
|
50
48
|
values << column.name
|
51
49
|
end
|
52
|
-
measures.each do |_
|
50
|
+
measures.each do |_, measure|
|
53
51
|
values << measure.name
|
54
52
|
end
|
55
53
|
values << time_key.name
|
@@ -66,7 +64,7 @@ module Masamune::Transform::Postgres
|
|
66
64
|
next if column.auto_reference
|
67
65
|
values << column.qualified_name
|
68
66
|
end
|
69
|
-
source.measures.each do |_
|
67
|
+
source.measures.each do |_, measure|
|
70
68
|
values << measure.aggregate_value
|
71
69
|
end
|
72
70
|
values << calculated_time_key(source)
|
@@ -102,7 +100,7 @@ module Masamune::Transform::Postgres
|
|
102
100
|
def calculated_date_key(source)
|
103
101
|
case grain
|
104
102
|
when :hourly, :daily
|
105
|
-
|
103
|
+
source.date_column.qualified_name.to_s
|
106
104
|
when :monthly
|
107
105
|
"to_char(date_trunc('month',#{source.date_column.qualified_name}::text::date),'YYYYMMDD')::integer"
|
108
106
|
end
|
@@ -36,12 +36,10 @@ module Masamune::Transform::Postgres
|
|
36
36
|
TargetPresenter.new(@target)
|
37
37
|
end
|
38
38
|
|
39
|
-
private
|
40
|
-
|
41
39
|
class TargetPresenter < SimpleDelegator
|
42
40
|
include Masamune::LastElement
|
43
41
|
|
44
|
-
def insert_columns(
|
42
|
+
def insert_columns(_source = nil)
|
45
43
|
consolidated_columns.map { |_, column| column.name }
|
46
44
|
end
|
47
45
|
|
@@ -80,4 +78,3 @@ module Masamune::Transform::Postgres
|
|
80
78
|
end
|
81
79
|
end
|
82
80
|
end
|
83
|
-
|