masamune 0.13.8 → 0.14.0
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/lib/masamune.rb +8 -5
- data/lib/masamune/actions.rb +1 -13
- data/lib/masamune/actions/data_flow.rb +2 -1
- data/lib/masamune/actions/date_parse.rb +0 -1
- data/lib/masamune/actions/elastic_mapreduce.rb +0 -2
- data/lib/masamune/actions/filesystem.rb +0 -2
- data/lib/masamune/actions/hive.rb +0 -2
- data/lib/masamune/actions/invoke_parallel.rb +2 -1
- data/lib/masamune/actions/postgres.rb +0 -1
- data/lib/masamune/actions/s3cmd.rb +2 -0
- data/lib/masamune/actions/transform.rb +0 -2
- data/lib/masamune/after_initialize_callbacks.rb +0 -2
- data/lib/masamune/commands.rb +1 -11
- data/lib/masamune/commands/postgres.rb +1 -0
- data/lib/masamune/commands/postgres_admin.rb +2 -0
- data/lib/masamune/configuration.rb +2 -0
- data/lib/masamune/data_plan/engine.rb +2 -0
- data/lib/masamune/filesystem.rb +2 -0
- data/lib/masamune/helpers.rb +1 -1
- data/lib/masamune/last_element.rb +0 -2
- data/lib/masamune/schema/dimension.rb +1 -3
- data/lib/masamune/schema/store.rb +2 -0
- data/lib/masamune/schema/table.rb +2 -0
- data/lib/masamune/template.rb +4 -1
- data/lib/masamune/thor.rb +1 -1
- data/lib/masamune/transform.rb +1 -21
- data/lib/masamune/transform/bulk_upsert.rb +1 -22
- data/lib/masamune/transform/common.rb +27 -0
- data/lib/masamune/transform/common/denormalize_table.rb +90 -0
- data/lib/masamune/transform/deduplicate_dimension.rb +1 -41
- data/lib/masamune/transform/define_table.rb +1 -113
- data/lib/masamune/transform/denormalize_table.rb +1 -50
- data/lib/masamune/transform/hive.rb +27 -0
- data/lib/masamune/transform/{define_schema.hql.erb → hive/define_schema.hql.erb} +0 -0
- data/lib/masamune/transform/{define_table.hql.erb → hive/define_table.hql.erb} +0 -0
- data/lib/masamune/transform/hive/define_table.rb +46 -0
- data/lib/masamune/transform/{denormalize_table.hql.erb → hive/denormalize_table.hql.erb} +0 -0
- data/lib/masamune/transform/hive/denormalize_table.rb +27 -0
- data/lib/masamune/transform/insert_reference_values.rb +1 -30
- data/lib/masamune/transform/operator.rb +36 -37
- data/lib/masamune/transform/postgres.rb +27 -0
- data/lib/masamune/transform/{bulk_upsert.psql.erb → postgres/bulk_upsert.psql.erb} +0 -0
- data/lib/masamune/transform/postgres/bulk_upsert.rb +62 -0
- data/lib/masamune/transform/{deduplicate_dimension.psql.erb → postgres/deduplicate_dimension.psql.erb} +1 -7
- data/lib/masamune/transform/postgres/deduplicate_dimension.rb +79 -0
- data/lib/masamune/transform/{define_foreign_key.psql.erb → postgres/define_foreign_key.psql.erb} +0 -0
- data/lib/masamune/transform/{define_index.psql.erb → postgres/define_index.psql.erb} +0 -0
- data/lib/masamune/transform/{define_inheritance.psql.erb → postgres/define_inheritance.psql.erb} +0 -0
- data/lib/masamune/transform/{define_schema.psql.erb → postgres/define_schema.psql.erb} +0 -0
- data/lib/masamune/transform/{define_table.psql.erb → postgres/define_table.psql.erb} +0 -0
- data/lib/masamune/transform/postgres/define_table.rb +142 -0
- data/lib/masamune/transform/{define_unique.psql.erb → postgres/define_unique.psql.erb} +0 -0
- data/lib/masamune/transform/{denormalize_table.psql.erb → postgres/denormalize_table.psql.erb} +0 -0
- data/lib/masamune/transform/postgres/denormalize_table.rb +27 -0
- data/lib/masamune/transform/{insert_reference_values.psql.erb → postgres/insert_reference_values.psql.erb} +1 -1
- data/lib/masamune/transform/postgres/insert_reference_values.rb +69 -0
- data/lib/masamune/transform/{relabel_dimension.psql.erb → postgres/relabel_dimension.psql.erb} +4 -1
- data/lib/masamune/transform/postgres/relabel_dimension.rb +45 -0
- data/lib/masamune/transform/{replace_table.psql.erb → postgres/replace_table.psql.erb} +0 -0
- data/lib/masamune/transform/{rollup_fact.psql.erb → postgres/rollup_fact.psql.erb} +0 -0
- data/lib/masamune/transform/postgres/rollup_fact.rb +123 -0
- data/lib/masamune/transform/{snapshot_dimension.psql.erb → postgres/snapshot_dimension.psql.erb} +3 -10
- data/lib/masamune/transform/postgres/snapshot_dimension.rb +83 -0
- data/lib/masamune/transform/{stage_dimension.psql.erb → postgres/stage_dimension.psql.erb} +0 -0
- data/lib/masamune/transform/postgres/stage_dimension.rb +90 -0
- data/lib/masamune/transform/{stage_fact.psql.erb → postgres/stage_fact.psql.erb} +0 -0
- data/lib/masamune/transform/postgres/stage_fact.rb +134 -0
- data/lib/masamune/transform/relabel_dimension.rb +1 -9
- data/lib/masamune/transform/rollup_fact.rb +1 -86
- data/lib/masamune/transform/snapshot_dimension.rb +1 -44
- data/lib/masamune/transform/stage_dimension.rb +1 -53
- data/lib/masamune/transform/stage_fact.rb +1 -96
- data/lib/masamune/version.rb +1 -1
- data/spec/masamune/template_spec.rb +1 -1
- data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +1 -3
- data/spec/masamune/transform/deduplicate_dimension_spec.rb +1 -7
- data/spec/masamune/transform/define_table.dimension_spec.rb +0 -14
- data/spec/masamune/transform/denormalize_table_spec.rb +34 -0
- data/spec/masamune/transform/relabel_dimension_spec.rb +6 -1
- data/spec/masamune/transform/snapshot_dimension_spec.rb +3 -10
- metadata +37 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: feca9f373a42ecd946e9682b08213c3357ce7437
|
4
|
+
data.tar.gz: 51cf1a4d353fb1f607299937e60c66437213d35c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e1d3c79fbe068bb79cb653cb746845dbaf7c33bc4525727cfa569b40407578b970418ee701ecb4ed0ed15004fb48d183c14398c03e6267fa8f5429d0184d0cf
|
7
|
+
data.tar.gz: f62cd40539a9ac2036ee312e9abf9055792463f3340faaed9857bd2dfb16d06cf3fe12e32ba41bc1b3676b23e512641abcaf07c929fe3e0e70bc5b4240d002ea
|
data/lib/masamune.rb
CHANGED
@@ -20,26 +20,29 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
+
require 'active_support/concern'
|
24
|
+
|
23
25
|
module Masamune
|
24
26
|
require 'masamune/environment'
|
25
27
|
require 'masamune/has_environment'
|
26
28
|
require 'masamune/io'
|
27
29
|
require 'masamune/template'
|
28
|
-
require 'masamune/commands'
|
29
30
|
require 'masamune/last_element'
|
30
|
-
require 'masamune/actions'
|
31
|
-
require 'masamune/helpers'
|
32
31
|
require 'masamune/configuration'
|
33
|
-
require 'masamune/data_plan'
|
34
32
|
require 'masamune/thor'
|
35
33
|
require 'masamune/thor_loader'
|
36
34
|
require 'masamune/filesystem'
|
37
35
|
require 'masamune/cached_filesystem'
|
38
36
|
require 'masamune/method_logger'
|
39
37
|
require 'masamune/after_initialize_callbacks'
|
38
|
+
require 'masamune/topological_hash'
|
39
|
+
|
40
|
+
require 'masamune/data_plan'
|
41
|
+
require 'masamune/commands'
|
42
|
+
require 'masamune/actions'
|
43
|
+
require 'masamune/helpers'
|
40
44
|
require 'masamune/schema'
|
41
45
|
require 'masamune/transform'
|
42
|
-
require 'masamune/topological_hash'
|
43
46
|
|
44
47
|
extend self
|
45
48
|
extend Masamune::HasEnvironment
|
data/lib/masamune/actions.rb
CHANGED
@@ -22,18 +22,6 @@
|
|
22
22
|
|
23
23
|
module Masamune
|
24
24
|
module Actions
|
25
|
-
require
|
26
|
-
require 'masamune/actions/s3cmd'
|
27
|
-
require 'masamune/actions/hadoop_streaming'
|
28
|
-
require 'masamune/actions/hadoop_filesystem'
|
29
|
-
require 'masamune/actions/postgres'
|
30
|
-
require 'masamune/actions/postgres_admin'
|
31
|
-
require 'masamune/actions/filesystem'
|
32
|
-
require 'masamune/actions/date_parse'
|
33
|
-
require 'masamune/actions/data_flow'
|
34
|
-
require 'masamune/actions/elastic_mapreduce'
|
35
|
-
require 'masamune/actions/execute'
|
36
|
-
require 'masamune/actions/transform'
|
37
|
-
require 'masamune/actions/invoke_parallel'
|
25
|
+
Dir["#{File.dirname(__FILE__)}/actions/*.rb"].each { |f| require f }
|
38
26
|
end
|
39
27
|
end
|
@@ -20,9 +20,10 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require 'active_support/concern'
|
24
23
|
require 'parallel'
|
25
24
|
|
25
|
+
require 'masamune/actions/execute'
|
26
|
+
|
26
27
|
module Masamune::Actions
|
27
28
|
module InvokeParallel
|
28
29
|
extend ActiveSupport::Concern
|
data/lib/masamune/commands.rb
CHANGED
@@ -22,16 +22,6 @@
|
|
22
22
|
|
23
23
|
module Masamune
|
24
24
|
module Commands
|
25
|
-
require
|
26
|
-
require 'masamune/commands/s3cmd'
|
27
|
-
require 'masamune/commands/hadoop_streaming'
|
28
|
-
require 'masamune/commands/hadoop_filesystem'
|
29
|
-
require 'masamune/commands/elastic_mapreduce'
|
30
|
-
require 'masamune/commands/postgres_common'
|
31
|
-
require 'masamune/commands/postgres'
|
32
|
-
require 'masamune/commands/postgres_admin'
|
33
|
-
require 'masamune/commands/interactive'
|
34
|
-
require 'masamune/commands/shell'
|
35
|
-
require 'masamune/commands/retry_with_backoff'
|
25
|
+
Dir["#{File.dirname(__FILE__)}/commands/*.rb"].each { |f| require f }
|
36
26
|
end
|
37
27
|
end
|
data/lib/masamune/filesystem.rb
CHANGED
data/lib/masamune/helpers.rb
CHANGED
@@ -62,7 +62,7 @@ module Masamune::Schema
|
|
62
62
|
when :two
|
63
63
|
[:start_at, :end_at, :version, :last_modified_at]
|
64
64
|
when :four
|
65
|
-
[:
|
65
|
+
[:start_at, :end_at, :version, :last_modified_at]
|
66
66
|
when :ledger
|
67
67
|
[:source_kind, :source_uuid, :start_at, :last_modified_at, :delta]
|
68
68
|
else
|
@@ -103,8 +103,6 @@ module Masamune::Schema
|
|
103
103
|
when :four
|
104
104
|
children << ledger_table
|
105
105
|
# FIXME derive type from from parent
|
106
|
-
initialize_column! id: 'parent_id', type: :integer, null: true, reference: TableReference.new(ledger_table)
|
107
|
-
initialize_column! id: 'record_id', type: :integer, null: true, reference: TableReference.new(ledger_table)
|
108
106
|
initialize_column! id: 'start_at', type: :timestamp, default: 'TO_TIMESTAMP(0)', index: [:start_at, :natural], unique: :natural
|
109
107
|
initialize_column! id: 'end_at', type: :timestamp, null: true, index: :end_at
|
110
108
|
initialize_column! id: 'version', type: :integer, default: 1, null: true
|
data/lib/masamune/template.rb
CHANGED
@@ -42,7 +42,10 @@ module Masamune
|
|
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
|
-
|
45
|
+
if File.exists?(file) && File.file?(file)
|
46
|
+
@paths << File.dirname(file)
|
47
|
+
return file
|
48
|
+
end
|
46
49
|
end
|
47
50
|
raise IOError, "File not found: #{partial_file}"
|
48
51
|
end
|
data/lib/masamune/thor.rb
CHANGED
data/lib/masamune/transform.rb
CHANGED
@@ -22,26 +22,6 @@
|
|
22
22
|
|
23
23
|
module Masamune
|
24
24
|
module Transform
|
25
|
-
require
|
26
|
-
|
27
|
-
require 'masamune/transform/define_table'
|
28
|
-
require 'masamune/transform/define_schema'
|
29
|
-
require 'masamune/transform/denormalize_table'
|
30
|
-
|
31
|
-
require 'masamune/transform/bulk_upsert'
|
32
|
-
require 'masamune/transform/insert_reference_values'
|
33
|
-
|
34
|
-
require 'masamune/transform/stage_dimension'
|
35
|
-
require 'masamune/transform/stage_fact'
|
36
|
-
|
37
|
-
require 'masamune/transform/load_dimension'
|
38
|
-
require 'masamune/transform/load_fact'
|
39
|
-
|
40
|
-
require 'masamune/transform/snapshot_dimension'
|
41
|
-
require 'masamune/transform/deduplicate_dimension'
|
42
|
-
require 'masamune/transform/consolidate_dimension'
|
43
|
-
require 'masamune/transform/relabel_dimension'
|
44
|
-
|
45
|
-
require 'masamune/transform/rollup_fact'
|
25
|
+
Dir["#{File.dirname(__FILE__)}/transform/*.rb"].each { |f| require f }
|
46
26
|
end
|
47
27
|
end
|
@@ -25,28 +25,7 @@ module Masamune::Transform
|
|
25
25
|
extend ActiveSupport::Concern
|
26
26
|
|
27
27
|
def bulk_upsert(source, target)
|
28
|
-
Operator.new(__method__, source: source, target: target
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
class Postgres < SimpleDelegator
|
34
|
-
include Masamune::LastElement
|
35
|
-
|
36
|
-
def update_columns
|
37
|
-
columns.values.reject { |column| reserved_column_ids.include?(column.id) || column.surrogate_key || column.natural_key || column.unique.any? || column.auto_reference || column.ignore }
|
38
|
-
end
|
39
|
-
method_with_last_element :update_columns
|
40
|
-
|
41
|
-
def insert_columns
|
42
|
-
columns.values.reject { |column| column.surrogate_key || column.auto_reference || column.ignore }
|
43
|
-
end
|
44
|
-
method_with_last_element :insert_columns
|
45
|
-
|
46
|
-
def unique_columns
|
47
|
-
columns.values.select { |column| column.unique.any? && !column.null }
|
48
|
-
end
|
49
|
-
method_with_last_element :unique_columns
|
28
|
+
Operator.new(__method__, source: source, target: target)
|
50
29
|
end
|
51
30
|
end
|
52
31
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
module Masamune::Transform
|
24
|
+
module Common
|
25
|
+
Dir["#{File.dirname(__FILE__)}/common/*.rb"].each { |f| require f }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'masamune/last_element'
|
24
|
+
|
25
|
+
module Masamune::Transform::Common
|
26
|
+
class DenormalizeTable
|
27
|
+
def initialize(options = {})
|
28
|
+
@target = options[:target]
|
29
|
+
@columns = options[:columns]
|
30
|
+
@order_by = options[:order_by]
|
31
|
+
end
|
32
|
+
|
33
|
+
def locals
|
34
|
+
{ target: target, columns: @columns, order_by: @order_by }
|
35
|
+
end
|
36
|
+
|
37
|
+
def target
|
38
|
+
TargetPresenter.new(@target)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
class TargetPresenter < SimpleDelegator
|
44
|
+
include Masamune::LastElement
|
45
|
+
|
46
|
+
def select_columns(column_names)
|
47
|
+
column_names.map do |column_name|
|
48
|
+
next unless column = dereference_column_name(column_name)
|
49
|
+
if column.reference
|
50
|
+
if column.reference.implicit || column.reference.degenerate
|
51
|
+
"#{column.name} AS #{column.name}"
|
52
|
+
else
|
53
|
+
"#{column.foreign_key_name} AS #{column.name}"
|
54
|
+
end
|
55
|
+
else
|
56
|
+
column.qualified_name
|
57
|
+
end
|
58
|
+
end.compact
|
59
|
+
end
|
60
|
+
method_with_last_element :select_columns
|
61
|
+
|
62
|
+
def join_alias(reference)
|
63
|
+
reference.label ? "#{reference.name} AS #{[reference.label, reference.name].compact.join('_')}" : reference.name
|
64
|
+
end
|
65
|
+
|
66
|
+
def join_conditions(column_names)
|
67
|
+
{}.tap do |conditions|
|
68
|
+
column_names.each do |column_name|
|
69
|
+
next unless column = dereference_column_name(column_name)
|
70
|
+
next unless column.reference
|
71
|
+
next if column.reference.degenerate
|
72
|
+
adjacent_reference = references[column.reference.id]
|
73
|
+
next unless adjacent_reference
|
74
|
+
adjacent_column = columns[adjacent_reference.foreign_key_name]
|
75
|
+
next unless adjacent_column
|
76
|
+
conditions[join_alias(column.reference)] = "#{column.reference.surrogate_key.qualified_name(column.reference.label)} = #{adjacent_column.qualified_name}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def order_by_columns(column_names)
|
82
|
+
column_names.map do |column_name|
|
83
|
+
next unless column = dereference_column_name(column_name)
|
84
|
+
column.name
|
85
|
+
end.compact
|
86
|
+
end
|
87
|
+
method_with_last_element :order_by_columns
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|