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
data/lib/masamune/schema/fact.rb
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
module Masamune::Schema
|
24
24
|
class Fact < Table
|
25
|
-
SUPPORTED_GRAINS = [:transaction, :hourly, :daily, :monthly]
|
25
|
+
SUPPORTED_GRAINS = [:transaction, :hourly, :daily, :monthly].freeze
|
26
26
|
|
27
27
|
attr_accessor :grain
|
28
28
|
attr_accessor :partition
|
@@ -96,7 +96,7 @@ module Masamune::Schema
|
|
96
96
|
def partition_tables(start_date = nil, stop_date = nil)
|
97
97
|
return unless partition
|
98
98
|
return unless start_date && stop_date
|
99
|
-
(start_date
|
99
|
+
(start_date..stop_date).each do |date|
|
100
100
|
next unless date.day == 1
|
101
101
|
yield partition_table(date)
|
102
102
|
end
|
data/lib/masamune/schema/map.rb
CHANGED
@@ -72,7 +72,7 @@ module Masamune::Schema
|
|
72
72
|
|
73
73
|
def quote(buffer)
|
74
74
|
return buffer if buffer =~ /\A".*"\z/
|
75
|
-
%
|
75
|
+
%("#{buffer.gsub('"', '""')}")
|
76
76
|
end
|
77
77
|
|
78
78
|
def separator
|
@@ -101,10 +101,10 @@ module Masamune::Schema
|
|
101
101
|
@csv = nil
|
102
102
|
end
|
103
103
|
|
104
|
-
def each
|
104
|
+
def each
|
105
105
|
raise 'must call Buffer#bind first' unless @io
|
106
106
|
CSV.parse(JSONEncoder.new(@io, @store), options.merge(headers: @store.headers || @table.columns.keys)) do |data|
|
107
|
-
next if data.to_s
|
107
|
+
next if data.to_s.start_with?('#')
|
108
108
|
row = safe_row(data)
|
109
109
|
yield row.to_hash if row
|
110
110
|
@line += 1
|
@@ -142,14 +142,12 @@ module Masamune::Schema
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
|
146
|
-
@line
|
147
|
-
end
|
145
|
+
attr_reader :line
|
148
146
|
|
149
147
|
private
|
150
148
|
|
151
149
|
def options
|
152
|
-
{skip_blanks: true}.tap do |
|
150
|
+
{ skip_blanks: true }.tap do |opts|
|
153
151
|
opts[:col_sep] = "\t" if @store.format == :tsv
|
154
152
|
end
|
155
153
|
end
|
@@ -178,7 +176,7 @@ module Masamune::Schema
|
|
178
176
|
distinct: false,
|
179
177
|
fail_fast: false,
|
180
178
|
debug: false
|
181
|
-
}
|
179
|
+
}.freeze
|
182
180
|
|
183
181
|
DEFAULT_ATTRIBUTES.keys.each do |attr|
|
184
182
|
attr_accessor attr
|
@@ -194,9 +192,7 @@ module Masamune::Schema
|
|
194
192
|
@skipped = 0
|
195
193
|
end
|
196
194
|
|
197
|
-
|
198
|
-
@source = source
|
199
|
-
end
|
195
|
+
attr_writer :source
|
200
196
|
|
201
197
|
# FIXME: avoid implict conversions
|
202
198
|
def target=(target)
|
@@ -229,7 +225,7 @@ module Masamune::Schema
|
|
229
225
|
intermediate
|
230
226
|
end
|
231
227
|
|
232
|
-
def open_stream(file, mode
|
228
|
+
def open_stream(file, mode)
|
233
229
|
case file
|
234
230
|
when IO, StringIO
|
235
231
|
file.flush
|
@@ -295,7 +291,7 @@ module Masamune::Schema
|
|
295
291
|
output_buffer.flush
|
296
292
|
end
|
297
293
|
|
298
|
-
def safe_apply_function(input_buffer, input
|
294
|
+
def safe_apply_function(input_buffer, input)
|
299
295
|
return unless input
|
300
296
|
Array.wrap(function.call(input, input_buffer.line)).each do |output|
|
301
297
|
yield output
|
data/lib/masamune/schema/row.rb
CHANGED
@@ -30,7 +30,7 @@ module Masamune::Schema
|
|
30
30
|
strict: true,
|
31
31
|
parent: nil,
|
32
32
|
debug: false
|
33
|
-
}
|
33
|
+
}.freeze
|
34
34
|
|
35
35
|
DEFAULT_ATTRIBUTES.keys.each do |attr|
|
36
36
|
attr_accessor attr
|
@@ -128,7 +128,8 @@ module Masamune::Schema
|
|
128
128
|
@columns = {}
|
129
129
|
values.each do |key, value|
|
130
130
|
next unless key
|
131
|
-
|
131
|
+
column = parent.dereference_column_name(key)
|
132
|
+
if column
|
132
133
|
@columns[column.compact_name] = column
|
133
134
|
result[column.compact_name] = column.ruby_value(value)
|
134
135
|
elsif strict
|
@@ -28,7 +28,7 @@ module Masamune::Schema
|
|
28
28
|
class Store
|
29
29
|
include Masamune::HasEnvironment
|
30
30
|
|
31
|
-
SUPPORTED_ATTRIBUTES = %(table dimension fact file)
|
31
|
+
SUPPORTED_ATTRIBUTES = %(table dimension fact file).freeze
|
32
32
|
|
33
33
|
DEFAULT_ATTRIBUTES =
|
34
34
|
{
|
@@ -37,7 +37,7 @@ module Masamune::Schema
|
|
37
37
|
json_encoding: ->(store) { default_json_encoding(store) },
|
38
38
|
headers: ->(store) { default_headers(store) },
|
39
39
|
debug: false
|
40
|
-
}
|
40
|
+
}.freeze
|
41
41
|
|
42
42
|
DEFAULT_ATTRIBUTES.keys.each do |attr|
|
43
43
|
attr_accessor attr
|
@@ -72,26 +72,25 @@ module Masamune::Schema
|
|
72
72
|
@extra = []
|
73
73
|
end
|
74
74
|
|
75
|
-
def method_missing(method, *
|
75
|
+
def method_missing(method, *_args)
|
76
76
|
if type == :files
|
77
77
|
files[method]
|
78
78
|
else
|
79
79
|
*attribute_name, attribute_type = method.to_s.split('_')
|
80
80
|
raise ArgumentError, "unknown attribute type '#{attribute_type}'" unless SUPPORTED_ATTRIBUTES.include?(attribute_type)
|
81
|
-
|
81
|
+
send(attribute_type.pluralize)[attribute_name.join('_')]
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
def dereference_column(id, options = {})
|
86
86
|
column_id, reference_id = id.to_s.split(/\./).reverse
|
87
87
|
column_options = options.dup
|
88
|
-
column_options
|
88
|
+
column_options[:id] = column_id
|
89
89
|
|
90
|
-
if
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end if reference_id
|
90
|
+
if reference_id
|
91
|
+
raise ArgumentError, "dimension #{reference_id} not defined" unless references[reference_id]
|
92
|
+
column_options[:reference] = references[reference_id]
|
93
|
+
end
|
95
94
|
|
96
95
|
Masamune::Schema::Column.new(column_options)
|
97
96
|
end
|
@@ -105,16 +104,16 @@ module Masamune::Schema
|
|
105
104
|
number = filename.split('_').first.to_i
|
106
105
|
result << file if number <= 0 && order == :pre
|
107
106
|
result << file if number > 0 && order == :post
|
108
|
-
|
109
|
-
result << file
|
107
|
+
elsif order == :pre
|
108
|
+
result << file
|
110
109
|
end
|
111
110
|
end
|
112
111
|
result.to_a
|
113
112
|
end
|
114
113
|
|
115
|
-
private
|
116
|
-
|
117
114
|
class << self
|
115
|
+
private
|
116
|
+
|
118
117
|
def default_format(store)
|
119
118
|
case store.type
|
120
119
|
when :postgres then :csv
|
@@ -43,7 +43,7 @@ module Masamune::Schema
|
|
43
43
|
inherit: false,
|
44
44
|
debug: false,
|
45
45
|
properties: {}
|
46
|
-
}
|
46
|
+
}.freeze
|
47
47
|
|
48
48
|
DEFAULT_ATTRIBUTES.keys.each do |attr|
|
49
49
|
attr_accessor attr
|
@@ -76,8 +76,8 @@ module Masamune::Schema
|
|
76
76
|
columns = (instance.is_a?(Hash) ? instance.values : instance).compact
|
77
77
|
raise ArgumentError, "table #{name} contains reserved columns" if columns.any? { |column| reserved_column_ids.include?(column.id) }
|
78
78
|
|
79
|
-
initialize_surrogate_key_column! unless columns.any?
|
80
|
-
initialize_reference_columns! unless columns.any?
|
79
|
+
initialize_surrogate_key_column! unless columns.any?(&:surrogate_key)
|
80
|
+
initialize_reference_columns! unless columns.any?(&:reference)
|
81
81
|
columns.each do |column|
|
82
82
|
initialize_column!(column)
|
83
83
|
end
|
@@ -104,7 +104,7 @@ module Masamune::Schema
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def surrogate_key
|
107
|
-
columns.values.detect
|
107
|
+
columns.values.detect(&:surrogate_key)
|
108
108
|
end
|
109
109
|
|
110
110
|
def primary_keys
|
@@ -112,11 +112,11 @@ module Masamune::Schema
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def natural_keys
|
115
|
-
columns.values.select
|
115
|
+
columns.values.select(&:natural_key)
|
116
116
|
end
|
117
117
|
|
118
118
|
def defined_columns
|
119
|
-
columns.values.reject
|
119
|
+
columns.values.reject(&:partition)
|
120
120
|
end
|
121
121
|
method_with_last_element :defined_columns
|
122
122
|
|
@@ -150,11 +150,11 @@ module Masamune::Schema
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def reference_columns
|
153
|
-
columns.values.select
|
153
|
+
columns.values.select(&:reference)
|
154
154
|
end
|
155
155
|
|
156
156
|
def foreign_key_columns
|
157
|
-
columns.values.select { |
|
157
|
+
columns.values.select { |column| !column.degenerate? && column.reference && column.reference.foreign_key }
|
158
158
|
end
|
159
159
|
|
160
160
|
def partitions
|
@@ -166,7 +166,7 @@ module Masamune::Schema
|
|
166
166
|
end
|
167
167
|
|
168
168
|
def aliased_rows
|
169
|
-
rows.select
|
169
|
+
rows.select(&:name)
|
170
170
|
end
|
171
171
|
|
172
172
|
def insert_references
|
@@ -225,7 +225,7 @@ module Masamune::Schema
|
|
225
225
|
end
|
226
226
|
|
227
227
|
def shared_columns(other)
|
228
|
-
Hash.new { |h,k| h[k] = [] }.tap do |shared|
|
228
|
+
Hash.new { |h, k| h[k] = [] }.tap do |shared|
|
229
229
|
columns.each do |_, column|
|
230
230
|
other.columns.each do |_, other_column|
|
231
231
|
shared[column] << other_column if column.references?(other_column)
|
@@ -235,13 +235,13 @@ module Masamune::Schema
|
|
235
235
|
end
|
236
236
|
|
237
237
|
def dereference_column_name(name)
|
238
|
-
reference_name, column_name = Column
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
elsif
|
244
|
-
|
238
|
+
reference_name, column_name = Column.dereference_column_name(name)
|
239
|
+
reference = references[reference_name]
|
240
|
+
if reference
|
241
|
+
column = reference.columns[column_name]
|
242
|
+
dereference_column(column.dup, reference) if column
|
243
|
+
elsif columns[column_name]
|
244
|
+
columns[column_name]
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
@@ -287,17 +287,13 @@ module Masamune::Schema
|
|
287
287
|
column = dereference_column_name(name)
|
288
288
|
next unless column
|
289
289
|
next if inherit && parent.reserved_column_ids.include?(column.id)
|
290
|
-
if column.parent == self
|
291
|
-
|
292
|
-
result[name] = column
|
293
|
-
else
|
294
|
-
result[name] = column
|
295
|
-
end
|
290
|
+
next if column.parent == self && column.surrogate_key
|
291
|
+
result[name] = column
|
296
292
|
end
|
297
293
|
end
|
298
294
|
end
|
299
295
|
|
300
|
-
def stage_table_references(
|
296
|
+
def stage_table_references(_parent, selected = [])
|
301
297
|
selected = references.keys if selected.empty?
|
302
298
|
{}.tap do |result|
|
303
299
|
selected.each do |name|
|
@@ -325,7 +321,7 @@ module Masamune::Schema
|
|
325
321
|
initialize_column! id: column.id, type: column.type, reference: reference, default: reference.default, null: reference.null, natural_key: reference.natural_key
|
326
322
|
end
|
327
323
|
elsif reference.foreign_key
|
328
|
-
# FIXME column.reference should point to reference.surrogate_key, only allow column references to Columns
|
324
|
+
# FIXME: column.reference should point to reference.surrogate_key, only allow column references to Columns
|
329
325
|
initialize_column! id: reference.foreign_key_name, type: reference.foreign_key_type, reference: reference, default: reference.default, null: reference.null, natural_key: reference.natural_key
|
330
326
|
end
|
331
327
|
end
|
@@ -342,7 +338,7 @@ module Masamune::Schema
|
|
342
338
|
|
343
339
|
def index_column_map
|
344
340
|
@index_column_map ||= begin
|
345
|
-
map = Hash.new { |h,k| h[k] = [] }
|
341
|
+
map = Hash.new { |h, k| h[k] = [] }
|
346
342
|
columns.each do |_, column|
|
347
343
|
column.index.each do |index|
|
348
344
|
map[index] << column.name
|
@@ -355,7 +351,7 @@ module Masamune::Schema
|
|
355
351
|
|
356
352
|
def unique_constraints_map
|
357
353
|
@unique_constraints_map ||= begin
|
358
|
-
map = Hash.new { |h,k| h[k] = [] }
|
354
|
+
map = Hash.new { |h, k| h[k] = [] }
|
359
355
|
columns.each do |_, column|
|
360
356
|
next if column.auto_reference
|
361
357
|
column.unique.each do |unique|
|
@@ -369,7 +365,7 @@ module Masamune::Schema
|
|
369
365
|
end
|
370
366
|
|
371
367
|
def reverse_unique_constraints_map
|
372
|
-
@reverse_unique_constraints_map ||= Hash[unique_constraints_map.to_a.map { |k,v| [v.sort, k] }]
|
368
|
+
@reverse_unique_constraints_map ||= Hash[unique_constraints_map.to_a.map { |k, v| [v.sort, k] }]
|
373
369
|
end
|
374
370
|
|
375
371
|
def short_md5(*a)
|
@@ -34,7 +34,7 @@ module Masamune::Schema
|
|
34
34
|
multiple: false,
|
35
35
|
through: [],
|
36
36
|
degenerate: false
|
37
|
-
}
|
37
|
+
}.freeze
|
38
38
|
|
39
39
|
DEFAULT_ATTRIBUTES.keys.each do |attr|
|
40
40
|
attr_accessor attr
|
@@ -70,17 +70,17 @@ module Masamune::Schema
|
|
70
70
|
|
71
71
|
def default(column = nil)
|
72
72
|
return if @default == :null
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
default_row = @table.rows.detect { |row| @default ? row.id == @default : row.default }
|
74
|
+
return unless default_row
|
75
|
+
default_row.name(column)
|
76
76
|
end
|
77
77
|
|
78
78
|
def unknown(column = nil)
|
79
79
|
return unless @unknown
|
80
80
|
return if @unknown == :null
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
unknown_row = @table.rows.detect { |row| row.id == @unknown }
|
82
|
+
return unless unknown_row
|
83
|
+
unknown_row.name(column)
|
84
84
|
end
|
85
85
|
|
86
86
|
def through=(columns)
|
data/lib/masamune/spec_helper.rb
CHANGED
@@ -20,4 +20,4 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
Dir["#{File.dirname(__FILE__)}/../../spec/support/masamune/**/*.rb"].each {|f| require f}
|
23
|
+
Dir["#{File.dirname(__FILE__)}/../../spec/support/masamune/**/*.rb"].each { |f| require f }
|
@@ -28,36 +28,36 @@ module Masamune::Tasks
|
|
28
28
|
include Masamune::Thor
|
29
29
|
include Masamune::Actions::AwsEmr
|
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 :aws_emr
|
34
34
|
skip_lock!
|
35
35
|
|
36
|
-
REQUIRE_CLUSTER_ID_ACTIONS =
|
36
|
+
REQUIRE_CLUSTER_ID_ACTIONS =
|
37
37
|
{
|
38
38
|
'describe-cluster' => 'Describe an AWS EMR cluster',
|
39
39
|
'list-instances' => 'List instances for an AWS EMR cluster',
|
40
40
|
'add-instance-groups' => 'Add instances to an AWS EMR cluster',
|
41
41
|
'ssh' => 'Launch an AWS EMR ssh session',
|
42
42
|
'wait' => 'Wait for an AWS EMR cluster to start'
|
43
|
-
}
|
43
|
+
}.freeze
|
44
44
|
|
45
45
|
REQUIRE_CLUSTER_ID_ACTIONS.each do |action, description|
|
46
46
|
desc action, description
|
47
|
-
method_option :cluster_id, :
|
47
|
+
method_option :cluster_id, desc: 'AWS EMR cluster_id ID (Hint: `masamune-emr-aws list-clusters`)'
|
48
48
|
define_method(action.underscore) do
|
49
49
|
raise Thor::RequiredArgumentMissingError, "No value provided for required options '--cluster-id'" unless options[:cluster_id]
|
50
50
|
aws_emr(aws_emr_options(action))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
NO_REQUIRE_CLUSTER_ID_ACTIONS =
|
54
|
+
NO_REQUIRE_CLUSTER_ID_ACTIONS =
|
55
55
|
{
|
56
56
|
'create-cluster' => 'Create an AWS EMR cluster',
|
57
57
|
'list-clusters' => 'List existing AWS EMR clusters',
|
58
58
|
'modify-instance-groups' => 'Modify instance groups for an AWS EMR cluster',
|
59
59
|
'terminate-clusters' => 'Terminate one or more AWS EMR clusters'
|
60
|
-
}
|
60
|
+
}.freeze
|
61
61
|
|
62
62
|
NO_REQUIRE_CLUSTER_ID_ACTIONS.each do |action, description|
|
63
63
|
desc action, description
|
@@ -69,9 +69,9 @@ module Masamune::Tasks
|
|
69
69
|
no_tasks do
|
70
70
|
def aws_emr_options(action)
|
71
71
|
options.dup.with_indifferent_access.tap do |opts|
|
72
|
-
opts
|
73
|
-
opts
|
74
|
-
opts.merge!(extra:
|
72
|
+
opts[:interactive] = true
|
73
|
+
opts[:action] = action
|
74
|
+
opts.merge!(extra: extra)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -29,16 +29,16 @@ module Masamune::Tasks
|
|
29
29
|
include Masamune::Actions::DateParse
|
30
30
|
include Masamune::Transform::DefineSchema
|
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 :dump
|
35
35
|
skip_lock!
|
36
36
|
|
37
37
|
desc 'dump', 'Dump schema'
|
38
|
-
method_option :type, :
|
39
|
-
method_option :section, :
|
40
|
-
method_option :exclude, :
|
41
|
-
method_option :skip_indexes, :
|
38
|
+
method_option :type, enum: %w(psql hql), desc: 'Schema type', default: 'psql'
|
39
|
+
method_option :section, enum: %w(pre post all), desc: 'Schema section', default: 'all'
|
40
|
+
method_option :exclude, type: :array, desc: 'Exclude tables matching globs', default: []
|
41
|
+
method_option :skip_indexes, type: :boolean, desc: 'Disable indexes', default: false
|
42
42
|
def dump_exec
|
43
43
|
print_catalog
|
44
44
|
exit
|