masamune 0.17.10 → 0.17.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f638075056a6d6b8ef776e42e1cd54b0dd8751ca
4
- data.tar.gz: f9bac35901816b810e83da6e7ecbdcbc70e4a110
3
+ metadata.gz: bedd64be2e2081da0dcd22d860eb4f502c83268f
4
+ data.tar.gz: 8ebcbaa4c7c8011b7db7179ab1671e381d35edb4
5
5
  SHA512:
6
- metadata.gz: 293482ddeba0fe77d3e78f04ec9e50f4b26ca3245fec87c32338b0a74946b3e06e8949fd47c256bad14c0af8f4a2faca89d703581c71fbecb6447f1c6fa8d9ec
7
- data.tar.gz: d48aa19c8c17612c4eb044d802bacfd1dd60511be11e5fce33cb6fefd76ea4ae98e05f3c727da8fb87bc4ae287b6a93f64d92a3325f2e1e1375b8100567810a2
6
+ metadata.gz: a952af9940ed6d29d08623df5809b1100b813e3ac602fe4f206c88fc2cc52a9beaedfe4516b40a1ee20af9d665f32716a3e44e5b956a9c442380bdf583ca9e15
7
+ data.tar.gz: cd3d3bebf7a7e09380244120fb25d20cb019c5544a21a52375e937810b052c1f57d5e34c882cb1e523b132d0f8bfae2183a315e24ed34b93cfd41b101c3aeedd
@@ -28,6 +28,7 @@ module Masamune::Schema
28
28
  insert: false,
29
29
  null: false,
30
30
  default: nil,
31
+ unknown: nil,
31
32
  natural_key: false,
32
33
  denormalize: false,
33
34
  multiple: false,
@@ -74,6 +75,14 @@ module Masamune::Schema
74
75
  end
75
76
  end
76
77
 
78
+ def unknown(column = nil)
79
+ return unless @unknown
80
+ return if @unknown == :null
81
+ if unknown_row = @table.rows.detect { |row| row.id == @unknown }
82
+ unknown_row.name(column)
83
+ end
84
+ end
85
+
77
86
  def through=(columns)
78
87
  @through = Array.wrap(columns)
79
88
  end
@@ -40,11 +40,11 @@ SELECT
40
40
  <%- end -%>
41
41
  FROM
42
42
  <%= source.name %>
43
- <%- target.join_conditions(source).each do |table, conditions| -%>
44
- JOIN
43
+ <%- target.join_conditions(source).each do |table, clause| -%>
44
+ <%= clause.type %> JOIN
45
45
  <%= table %>
46
46
  ON
47
- <%= conditions.join(" AND\n ") %>
47
+ <%= clause.conditions.join(" AND\n ") %>
48
48
  <%- end -%>
49
49
  ;
50
50
 
@@ -56,7 +56,8 @@ module Masamune::Transform::Postgres
56
56
  shared_columns(source).values.map do |columns|
57
57
  column = columns.first
58
58
  if !column.degenerate? && reference = column.reference
59
- reference.surrogate_key.qualified_name(column.reference.label)
59
+ value = reference.surrogate_key.qualified_name(column.reference.label)
60
+ column.reference.unknown ? "COALESCE(#{value}, #{column.reference.unknown})" : value
60
61
  else
61
62
  column.qualified_name
62
63
  end
@@ -74,7 +75,7 @@ module Masamune::Transform::Postgres
74
75
  join_columns = join_columns.group_by { |column| column.reference }
75
76
 
76
77
  dependencies = Masamune::TopologicalHash.new
77
- conditions = Hash.new { |h,k| h[k] = [] }
78
+ conditions = Hash.new { |h,k| h[k] = OpenStruct.new(type: 'INNER', conditions: []) }
78
79
  join_columns.each do |reference, columns|
79
80
  reference_name = join_alias(reference)
80
81
  columns.each do |column|
@@ -91,7 +92,7 @@ module Masamune::Transform::Postgres
91
92
 
92
93
  column.reference.auto_surrogate_keys.each do |auto_surrogate_key|
93
94
  next unless auto_surrogate_key.default
94
- conditions[reference_name] << "#{auto_surrogate_key.qualified_name(reference.label)} = #{auto_surrogate_key.default}"
95
+ conditions[reference_name].conditions << "#{auto_surrogate_key.qualified_name(reference.label)} = #{auto_surrogate_key.default}"
95
96
  end if column.reference
96
97
 
97
98
  if column.reference && !column.reference.default.nil? && column.adjacent.natural_key
@@ -100,7 +101,7 @@ module Masamune::Transform::Postgres
100
101
  coalesce_values << column.adjacent.sql_value(column.adjacent.default)
101
102
  end
102
103
 
103
- conditions[reference_name] << (coalesce_values.any? ?
104
+ conditions[reference_name].conditions << (coalesce_values.any? ?
104
105
  "#{column.foreign_key_name} = COALESCE(#{column.qualified_name}, #{coalesce_values.join(', ')})" :
105
106
  "#{column.foreign_key_name} = #{column.qualified_name}")
106
107
  end
@@ -108,10 +109,11 @@ module Masamune::Transform::Postgres
108
109
  if reference.type == :two || reference.type == :four
109
110
  join_key_a = "TO_TIMESTAMP(#{source.time_key.qualified_name}) BETWEEN #{reference.start_key.qualified_name(reference.label)} AND COALESCE(#{reference.end_key.qualified_name(reference.label)}, 'INFINITY')"
110
111
  join_key_b = "TO_TIMESTAMP(#{source.time_key.qualified_name}) < #{reference.start_key.qualified_name(reference.label)} AND #{reference.version_key.qualified_name(reference.label)} = 1"
111
- conditions[reference_name] << "((#{join_key_a}) OR (#{join_key_b}))"
112
+ conditions[reference_name].conditions << "((#{join_key_a}) OR (#{join_key_b}))"
112
113
  end
113
114
 
114
- conditions[reference_name].uniq!
115
+ conditions[reference_name].type = 'LEFT' if reference.unknown
116
+ conditions[reference_name].conditions.uniq!
115
117
  end
116
118
  conditions.slice(*dependencies.tsort)
117
119
  end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Masamune
24
- VERSION = '0.17.10'
24
+ VERSION = '0.17.11'
25
25
  end
@@ -67,8 +67,9 @@ describe Masamune::Transform::StageFact do
67
67
 
68
68
  column 'tenant_id', type: :integer, natural_key: true
69
69
  column 'group_id', type: :integer, natural_key: true
70
- column 'group_mode', type: :enum, sub_type: 'group_mode', values: %(missing public private), index: true, natural_key: true, default: 'missing'
70
+ column 'group_mode', type: :enum, sub_type: 'group_mode', values: %(missing unknown public private), index: true, natural_key: true, default: 'missing'
71
71
  row group_id: -1, group_mode: 'missing', attributes: {id: :missing}
72
+ row group_id: -2, group_mode: 'unknown', attributes: {id: :unknown}
72
73
  end
73
74
 
74
75
  fact 'visits', partition: 'y%Ym%m', grain: %w(hourly daily monthly) do
@@ -76,8 +77,8 @@ describe Masamune::Transform::StageFact do
76
77
  references :date
77
78
  references :tenant, through: [:user, :from_group, :group]
78
79
  references :user
79
- references :group, label: 'from', default: :missing
80
- references :group, default: :missing
80
+ references :group, label: 'from', default: :missing, unknown: :unknown
81
+ references :group, default: :missing, unknown: :unknown
81
82
  references :user_agent, insert: true
82
83
  references :feature, insert: true
83
84
  references :session, degenerate: true
@@ -127,8 +128,8 @@ describe Masamune::Transform::StageFact do
127
128
  date_dimension.id,
128
129
  tenant_dimension.id,
129
130
  user_dimension.id,
130
- from_group_dimension.id,
131
- group_dimension.id,
131
+ COALESCE(from_group_dimension.id, unknown_group_dimension_id()),
132
+ COALESCE(group_dimension.id, unknown_group_dimension_id()),
132
133
  user_agent_type.id,
133
134
  feature_type.id,
134
135
  visits_hourly_file_fact_stage.session_type_id,
@@ -136,44 +137,44 @@ describe Masamune::Transform::StageFact do
136
137
  visits_hourly_file_fact_stage.time_key
137
138
  FROM
138
139
  visits_hourly_file_fact_stage
139
- JOIN
140
+ INNER JOIN
140
141
  date_dimension
141
142
  ON
142
143
  date_dimension.date_id = visits_hourly_file_fact_stage.date_dimension_date_id
143
- JOIN
144
+ INNER JOIN
144
145
  user_dimension
145
146
  ON
146
147
  user_dimension.cluster_type_id = default_cluster_type_id() AND
147
148
  user_dimension.user_id = visits_hourly_file_fact_stage.user_dimension_user_id AND
148
149
  ((TO_TIMESTAMP(visits_hourly_file_fact_stage.time_key) BETWEEN user_dimension.start_at AND COALESCE(user_dimension.end_at, 'INFINITY')) OR (TO_TIMESTAMP(visits_hourly_file_fact_stage.time_key) < user_dimension.start_at AND user_dimension.version = 1))
149
- JOIN
150
+ LEFT JOIN
150
151
  group_dimension AS from_group_dimension
151
152
  ON
152
153
  from_group_dimension.cluster_type_id = default_cluster_type_id() AND
153
154
  from_group_dimension.group_id = COALESCE(visits_hourly_file_fact_stage.from_group_dimension_group_id, missing_group_dimension_group_id()) AND
154
155
  from_group_dimension.group_mode = COALESCE(visits_hourly_file_fact_stage.from_group_dimension_group_mode, missing_group_dimension_group_mode()) AND
155
156
  ((TO_TIMESTAMP(visits_hourly_file_fact_stage.time_key) BETWEEN from_group_dimension.start_at AND COALESCE(from_group_dimension.end_at, 'INFINITY')) OR (TO_TIMESTAMP(visits_hourly_file_fact_stage.time_key) < from_group_dimension.start_at AND from_group_dimension.version = 1))
156
- JOIN
157
+ LEFT JOIN
157
158
  group_dimension
158
159
  ON
159
160
  group_dimension.cluster_type_id = default_cluster_type_id() AND
160
161
  group_dimension.group_id = COALESCE(visits_hourly_file_fact_stage.group_dimension_group_id, missing_group_dimension_group_id()) AND
161
162
  group_dimension.group_mode = COALESCE(visits_hourly_file_fact_stage.group_dimension_group_mode, missing_group_dimension_group_mode()) AND
162
163
  ((TO_TIMESTAMP(visits_hourly_file_fact_stage.time_key) BETWEEN group_dimension.start_at AND COALESCE(group_dimension.end_at, 'INFINITY')) OR (TO_TIMESTAMP(visits_hourly_file_fact_stage.time_key) < group_dimension.start_at AND group_dimension.version = 1))
163
- JOIN
164
+ INNER JOIN
164
165
  tenant_dimension
165
166
  ON
166
167
  tenant_dimension.cluster_type_id = default_cluster_type_id() AND
167
168
  tenant_dimension.tenant_id = COALESCE(visits_hourly_file_fact_stage.tenant_dimension_tenant_id, user_dimension.tenant_id, from_group_dimension.tenant_id, group_dimension.tenant_id) AND
168
169
  ((TO_TIMESTAMP(visits_hourly_file_fact_stage.time_key) BETWEEN tenant_dimension.start_at AND COALESCE(tenant_dimension.end_at, 'INFINITY')) OR (TO_TIMESTAMP(visits_hourly_file_fact_stage.time_key) < tenant_dimension.start_at AND tenant_dimension.version = 1))
169
- JOIN
170
+ INNER JOIN
170
171
  user_agent_type
171
172
  ON
172
173
  user_agent_type.cluster_type_id = default_cluster_type_id() AND
173
174
  user_agent_type.name = visits_hourly_file_fact_stage.user_agent_type_name AND
174
175
  user_agent_type.version = COALESCE(visits_hourly_file_fact_stage.user_agent_type_version, 'Unknown') AND
175
176
  user_agent_type.mobile = COALESCE(visits_hourly_file_fact_stage.user_agent_type_mobile, FALSE)
176
- JOIN
177
+ INNER JOIN
177
178
  feature_type
178
179
  ON
179
180
  feature_type.name = visits_hourly_file_fact_stage.feature_type_name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: masamune
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.10
4
+ version: 0.17.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Andrews
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor