masamune 0.11.6 → 0.11.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/masamune/schema/fact.rb +7 -6
- data/lib/masamune/transform/rollup_fact.psql.erb +1 -5
- data/lib/masamune/transform/stage_fact.psql.erb +1 -5
- data/lib/masamune/version.rb +1 -1
- data/spec/masamune/schema/fact_spec.rb +10 -0
- data/spec/masamune/transform/rollup_fact_spec.rb +77 -87
- data/spec/masamune/transform/stage_fact_spec.rb +33 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 089f245bbbb77dd701c5179c0ddfd39bd8a6268a
|
4
|
+
data.tar.gz: 05d83327ec4635886d81c342194de1b2d6215375
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c94f89286c6910fe8f84a61966614ea67a645ff30f30fc2f0f16fe3651ff78def7d7c486a31785aae98ffcb66ee39832f84817488573ad8543ca095a39bced1e
|
7
|
+
data.tar.gz: 6bb39f3a29afdcba70ad493de7c6e0128bf302442a52ea0e3b2f0423ad4d736e4aa82598096b74e4494cdab913085480ff034d3e19a7757fa673f1481869f9e3
|
data/lib/masamune/schema/fact.rb
CHANGED
@@ -63,12 +63,13 @@ module Masamune::Schema
|
|
63
63
|
columns.values.detect { |column| column.id == :time_key }
|
64
64
|
end
|
65
65
|
|
66
|
-
def stage_table(
|
67
|
-
super.tap do |stage|
|
68
|
-
stage.id
|
69
|
-
stage.
|
70
|
-
stage.
|
71
|
-
stage.
|
66
|
+
def stage_table(options = {})
|
67
|
+
super(options).tap do |stage|
|
68
|
+
stage.id = @id
|
69
|
+
stage.suffix = options[:suffix]
|
70
|
+
stage.store = store
|
71
|
+
stage.range = range
|
72
|
+
stage.grain = grain
|
72
73
|
stage.columns.each do |_, column|
|
73
74
|
column.unique = false
|
74
75
|
end
|
@@ -20,9 +20,7 @@
|
|
20
20
|
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
-- THE SOFTWARE.
|
22
22
|
|
23
|
-
<%- target_stage = target.stage_table %>
|
24
|
-
|
25
|
-
BEGIN;
|
23
|
+
<%- target_stage = target.stage_table(suffix: Process.pid) %>
|
26
24
|
|
27
25
|
DROP TABLE IF EXISTS <%= target_stage.name %> CASCADE;
|
28
26
|
CREATE TABLE IF NOT EXISTS <%= target_stage.name %> (LIKE <%= target.parent.name %> INCLUDING ALL);
|
@@ -57,8 +55,6 @@ GROUP BY
|
|
57
55
|
CREATE <%= unique ? 'UNIQUE INDEX' : 'INDEX' %> <%= index_name %> ON <%= target_stage.name %> (<%= column_names.join(', ') %>);
|
58
56
|
<%- end -%>
|
59
57
|
|
60
|
-
COMMIT;
|
61
|
-
|
62
58
|
BEGIN;
|
63
59
|
|
64
60
|
DROP TABLE IF EXISTS <%= target.name %>;
|
@@ -21,9 +21,7 @@
|
|
21
21
|
-- THE SOFTWARE.
|
22
22
|
|
23
23
|
<%- target_partition = target.partition_table(date) %>
|
24
|
-
<%- target_stage = target_partition.stage_table %>
|
25
|
-
|
26
|
-
BEGIN;
|
24
|
+
<%- target_stage = target_partition.stage_table(suffix: Process.pid) %>
|
27
25
|
|
28
26
|
DROP TABLE IF EXISTS <%= target_stage.name %> CASCADE;
|
29
27
|
CREATE TABLE IF NOT EXISTS <%= target_stage.name %> (LIKE <%= target.name %> INCLUDING ALL);
|
@@ -56,8 +54,6 @@ ON
|
|
56
54
|
CREATE <%= unique ? 'UNIQUE INDEX' : 'INDEX' %> <%= index_name %> ON <%= target_stage.name %> (<%= column_names.join(', ') %>);
|
57
55
|
<%- end -%>
|
58
56
|
|
59
|
-
COMMIT;
|
60
|
-
|
61
57
|
BEGIN;
|
62
58
|
|
63
59
|
DROP TABLE IF EXISTS <%= target_partition.name %>;
|
data/lib/masamune/version.rb
CHANGED
@@ -68,6 +68,16 @@ describe Masamune::Schema::Fact do
|
|
68
68
|
it { expect(stage_table.store.id).to eq(store.id) }
|
69
69
|
it { expect(stage_table.name).to eq('visits_fact_y2015m01_stage') }
|
70
70
|
it { expect(stage_table.range.start_date).to eq(date.utc.to_date) }
|
71
|
+
|
72
|
+
context 'with optional suffix' do
|
73
|
+
subject(:stage_table) { partition_table.stage_table(suffix: 'tmp') }
|
74
|
+
|
75
|
+
it 'should append suffix to id' do
|
76
|
+
expect(stage_table.store.id).to eq(store.id)
|
77
|
+
expect(stage_table.name).to eq('visits_fact_y2015m01_stage_tmp')
|
78
|
+
expect(stage_table.range.start_date).to eq(date.utc.to_date)
|
79
|
+
end
|
80
|
+
end
|
71
81
|
end
|
72
82
|
end
|
73
83
|
|
@@ -24,6 +24,8 @@ require 'spec_helper'
|
|
24
24
|
|
25
25
|
describe Masamune::Transform::RollupFact do
|
26
26
|
before do
|
27
|
+
allow(Process).to receive(:pid).and_return('PID')
|
28
|
+
|
27
29
|
catalog.schema :postgres do
|
28
30
|
dimension 'cluster', type: :mini do
|
29
31
|
column 'id', type: :sequence, surrogate_key: true, auto: true
|
@@ -90,21 +92,19 @@ describe Masamune::Transform::RollupFact do
|
|
90
92
|
|
91
93
|
it 'should eq render rollup_fact template' do
|
92
94
|
is_expected.to eq <<-EOS.strip_heredoc
|
93
|
-
|
95
|
+
DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage_PID CASCADE;
|
96
|
+
CREATE TABLE IF NOT EXISTS visits_hourly_fact_y2014m08_stage_PID (LIKE visits_hourly_fact INCLUDING ALL);
|
94
97
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
ALTER TABLE
|
99
|
-
ALTER TABLE
|
100
|
-
ALTER TABLE
|
101
|
-
ALTER TABLE
|
102
|
-
ALTER TABLE visits_hourly_fact_y2014m08_stage ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_user_dimension_id_fkey FOREIGN KEY (user_dimension_id) REFERENCES user_dimension(id);
|
103
|
-
ALTER TABLE visits_hourly_fact_y2014m08_stage ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id);
|
104
|
-
ALTER TABLE visits_hourly_fact_y2014m08_stage ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id);
|
98
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_time_key_check CHECK (time_key >= 1406851200 AND time_key < 1409529600);
|
99
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_cluster_type_id_fkey FOREIGN KEY (cluster_type_id) REFERENCES cluster_type(id);
|
100
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_date_dimension_id_fkey FOREIGN KEY (date_dimension_id) REFERENCES date_dimension(id);
|
101
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_tenant_dimension_id_fkey FOREIGN KEY (tenant_dimension_id) REFERENCES tenant_dimension(id);
|
102
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_user_dimension_id_fkey FOREIGN KEY (user_dimension_id) REFERENCES user_dimension(id);
|
103
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id);
|
104
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id);
|
105
105
|
|
106
106
|
INSERT INTO
|
107
|
-
|
107
|
+
visits_hourly_fact_y2014m08_stage_PID (date_dimension_id, tenant_dimension_id, user_dimension_id, user_agent_type_id, feature_type_id, total, time_key)
|
108
108
|
SELECT
|
109
109
|
(SELECT id FROM date_dimension d WHERE d.date_epoch = date_dimension.date_epoch ORDER BY d.date_id LIMIT 1),
|
110
110
|
visits_transaction_fact_y2014m08.tenant_dimension_id,
|
@@ -128,20 +128,18 @@ describe Masamune::Transform::RollupFact do
|
|
128
128
|
(visits_transaction_fact_y2014m08.time_key - (visits_transaction_fact_y2014m08.time_key % 3600))
|
129
129
|
;
|
130
130
|
|
131
|
-
CREATE INDEX
|
132
|
-
CREATE INDEX
|
133
|
-
CREATE INDEX
|
134
|
-
CREATE INDEX
|
135
|
-
CREATE INDEX
|
136
|
-
CREATE INDEX
|
137
|
-
CREATE INDEX
|
138
|
-
|
139
|
-
COMMIT;
|
131
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_cluster_type_id_index ON visits_hourly_fact_y2014m08_stage_PID (cluster_type_id);
|
132
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_date_dimension_id_index ON visits_hourly_fact_y2014m08_stage_PID (date_dimension_id);
|
133
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_tenant_dimension_id_index ON visits_hourly_fact_y2014m08_stage_PID (tenant_dimension_id);
|
134
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_user_dimension_id_index ON visits_hourly_fact_y2014m08_stage_PID (user_dimension_id);
|
135
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_user_agent_type_id_index ON visits_hourly_fact_y2014m08_stage_PID (user_agent_type_id);
|
136
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_feature_type_id_index ON visits_hourly_fact_y2014m08_stage_PID (feature_type_id);
|
137
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_time_key_index ON visits_hourly_fact_y2014m08_stage_PID (time_key);
|
140
138
|
|
141
139
|
BEGIN;
|
142
140
|
|
143
141
|
DROP TABLE IF EXISTS visits_hourly_fact_y2014m08;
|
144
|
-
ALTER TABLE
|
142
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID RENAME TO visits_hourly_fact_y2014m08;
|
145
143
|
|
146
144
|
ALTER TABLE visits_hourly_fact_y2014m08 INHERIT visits_hourly_fact;
|
147
145
|
ALTER TABLE visits_hourly_fact_y2014m08 ADD CONSTRAINT visits_hourly_fact_y2014m08_time_key_check CHECK (time_key >= 1406851200 AND time_key < 1409529600) NOT VALID;
|
@@ -152,13 +150,13 @@ describe Masamune::Transform::RollupFact do
|
|
152
150
|
ALTER TABLE visits_hourly_fact_y2014m08 ADD CONSTRAINT visits_hourly_fact_y2014m08_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id) NOT VALID;
|
153
151
|
ALTER TABLE visits_hourly_fact_y2014m08 ADD CONSTRAINT visits_hourly_fact_y2014m08_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id) NOT VALID;
|
154
152
|
|
155
|
-
ALTER INDEX
|
156
|
-
ALTER INDEX
|
157
|
-
ALTER INDEX
|
158
|
-
ALTER INDEX
|
159
|
-
ALTER INDEX
|
160
|
-
ALTER INDEX
|
161
|
-
ALTER INDEX
|
153
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_cluster_type_id_index RENAME TO visits_hourly_fact_y2014m08_cluster_type_id_index;
|
154
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_date_dimension_id_index RENAME TO visits_hourly_fact_y2014m08_date_dimension_id_index;
|
155
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_tenant_dimension_id_index RENAME TO visits_hourly_fact_y2014m08_tenant_dimension_id_index;
|
156
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_user_dimension_id_index RENAME TO visits_hourly_fact_y2014m08_user_dimension_id_index;
|
157
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_user_agent_type_id_index RENAME TO visits_hourly_fact_y2014m08_user_agent_type_id_index;
|
158
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_feature_type_id_index RENAME TO visits_hourly_fact_y2014m08_feature_type_id_index;
|
159
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_time_key_index RENAME TO visits_hourly_fact_y2014m08_time_key_index;
|
162
160
|
|
163
161
|
COMMIT;
|
164
162
|
EOS
|
@@ -174,21 +172,19 @@ describe Masamune::Transform::RollupFact do
|
|
174
172
|
|
175
173
|
it 'should eq render rollup_fact template' do
|
176
174
|
is_expected.to eq <<-EOS.strip_heredoc
|
177
|
-
|
178
|
-
|
179
|
-
DROP TABLE IF EXISTS visits_daily_fact_y2014m08_stage CASCADE;
|
180
|
-
CREATE TABLE IF NOT EXISTS visits_daily_fact_y2014m08_stage (LIKE visits_daily_fact INCLUDING ALL);
|
175
|
+
DROP TABLE IF EXISTS visits_daily_fact_y2014m08_stage_PID CASCADE;
|
176
|
+
CREATE TABLE IF NOT EXISTS visits_daily_fact_y2014m08_stage_PID (LIKE visits_daily_fact INCLUDING ALL);
|
181
177
|
|
182
|
-
ALTER TABLE
|
183
|
-
ALTER TABLE
|
184
|
-
ALTER TABLE
|
185
|
-
ALTER TABLE
|
186
|
-
ALTER TABLE
|
187
|
-
ALTER TABLE
|
188
|
-
ALTER TABLE
|
178
|
+
ALTER TABLE visits_daily_fact_y2014m08_stage_PID ADD CONSTRAINT visits_daily_fact_y2014m08_stage_PID_time_key_check CHECK (time_key >= 1406851200 AND time_key < 1409529600);
|
179
|
+
ALTER TABLE visits_daily_fact_y2014m08_stage_PID ADD CONSTRAINT visits_daily_fact_y2014m08_stage_PID_cluster_type_id_fkey FOREIGN KEY (cluster_type_id) REFERENCES cluster_type(id);
|
180
|
+
ALTER TABLE visits_daily_fact_y2014m08_stage_PID ADD CONSTRAINT visits_daily_fact_y2014m08_stage_PID_date_dimension_id_fkey FOREIGN KEY (date_dimension_id) REFERENCES date_dimension(id);
|
181
|
+
ALTER TABLE visits_daily_fact_y2014m08_stage_PID ADD CONSTRAINT visits_daily_fact_y2014m08_stage_PID_tenant_dimension_id_fkey FOREIGN KEY (tenant_dimension_id) REFERENCES tenant_dimension(id);
|
182
|
+
ALTER TABLE visits_daily_fact_y2014m08_stage_PID ADD CONSTRAINT visits_daily_fact_y2014m08_stage_PID_user_dimension_id_fkey FOREIGN KEY (user_dimension_id) REFERENCES user_dimension(id);
|
183
|
+
ALTER TABLE visits_daily_fact_y2014m08_stage_PID ADD CONSTRAINT visits_daily_fact_y2014m08_stage_PID_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id);
|
184
|
+
ALTER TABLE visits_daily_fact_y2014m08_stage_PID ADD CONSTRAINT visits_daily_fact_y2014m08_stage_PID_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id);
|
189
185
|
|
190
186
|
INSERT INTO
|
191
|
-
|
187
|
+
visits_daily_fact_y2014m08_stage_PID (date_dimension_id, tenant_dimension_id, user_dimension_id, user_agent_type_id, feature_type_id, total, time_key)
|
192
188
|
SELECT
|
193
189
|
(SELECT id FROM date_dimension d WHERE d.date_epoch = date_dimension.date_epoch ORDER BY d.date_id LIMIT 1),
|
194
190
|
visits_hourly_fact_y2014m08.tenant_dimension_id,
|
@@ -211,20 +207,18 @@ describe Masamune::Transform::RollupFact do
|
|
211
207
|
visits_hourly_fact_y2014m08.feature_type_id
|
212
208
|
;
|
213
209
|
|
214
|
-
CREATE INDEX
|
215
|
-
CREATE INDEX
|
216
|
-
CREATE INDEX
|
217
|
-
CREATE INDEX
|
218
|
-
CREATE INDEX
|
219
|
-
CREATE INDEX
|
220
|
-
CREATE INDEX
|
221
|
-
|
222
|
-
COMMIT;
|
210
|
+
CREATE INDEX visits_daily_fact_y2014m08_stage_PID_cluster_type_id_index ON visits_daily_fact_y2014m08_stage_PID (cluster_type_id);
|
211
|
+
CREATE INDEX visits_daily_fact_y2014m08_stage_PID_date_dimension_id_index ON visits_daily_fact_y2014m08_stage_PID (date_dimension_id);
|
212
|
+
CREATE INDEX visits_daily_fact_y2014m08_stage_PID_tenant_dimension_id_index ON visits_daily_fact_y2014m08_stage_PID (tenant_dimension_id);
|
213
|
+
CREATE INDEX visits_daily_fact_y2014m08_stage_PID_user_dimension_id_index ON visits_daily_fact_y2014m08_stage_PID (user_dimension_id);
|
214
|
+
CREATE INDEX visits_daily_fact_y2014m08_stage_PID_user_agent_type_id_index ON visits_daily_fact_y2014m08_stage_PID (user_agent_type_id);
|
215
|
+
CREATE INDEX visits_daily_fact_y2014m08_stage_PID_feature_type_id_index ON visits_daily_fact_y2014m08_stage_PID (feature_type_id);
|
216
|
+
CREATE INDEX visits_daily_fact_y2014m08_stage_PID_time_key_index ON visits_daily_fact_y2014m08_stage_PID (time_key);
|
223
217
|
|
224
218
|
BEGIN;
|
225
219
|
|
226
220
|
DROP TABLE IF EXISTS visits_daily_fact_y2014m08;
|
227
|
-
ALTER TABLE
|
221
|
+
ALTER TABLE visits_daily_fact_y2014m08_stage_PID RENAME TO visits_daily_fact_y2014m08;
|
228
222
|
|
229
223
|
ALTER TABLE visits_daily_fact_y2014m08 INHERIT visits_daily_fact;
|
230
224
|
ALTER TABLE visits_daily_fact_y2014m08 ADD CONSTRAINT visits_daily_fact_y2014m08_time_key_check CHECK (time_key >= 1406851200 AND time_key < 1409529600) NOT VALID;
|
@@ -235,13 +229,13 @@ describe Masamune::Transform::RollupFact do
|
|
235
229
|
ALTER TABLE visits_daily_fact_y2014m08 ADD CONSTRAINT visits_daily_fact_y2014m08_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id) NOT VALID;
|
236
230
|
ALTER TABLE visits_daily_fact_y2014m08 ADD CONSTRAINT visits_daily_fact_y2014m08_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id) NOT VALID;
|
237
231
|
|
238
|
-
ALTER INDEX
|
239
|
-
ALTER INDEX
|
240
|
-
ALTER INDEX
|
241
|
-
ALTER INDEX
|
242
|
-
ALTER INDEX
|
243
|
-
ALTER INDEX
|
244
|
-
ALTER INDEX
|
232
|
+
ALTER INDEX visits_daily_fact_y2014m08_stage_PID_cluster_type_id_index RENAME TO visits_daily_fact_y2014m08_cluster_type_id_index;
|
233
|
+
ALTER INDEX visits_daily_fact_y2014m08_stage_PID_date_dimension_id_index RENAME TO visits_daily_fact_y2014m08_date_dimension_id_index;
|
234
|
+
ALTER INDEX visits_daily_fact_y2014m08_stage_PID_tenant_dimension_id_index RENAME TO visits_daily_fact_y2014m08_tenant_dimension_id_index;
|
235
|
+
ALTER INDEX visits_daily_fact_y2014m08_stage_PID_user_dimension_id_index RENAME TO visits_daily_fact_y2014m08_user_dimension_id_index;
|
236
|
+
ALTER INDEX visits_daily_fact_y2014m08_stage_PID_user_agent_type_id_index RENAME TO visits_daily_fact_y2014m08_user_agent_type_id_index;
|
237
|
+
ALTER INDEX visits_daily_fact_y2014m08_stage_PID_feature_type_id_index RENAME TO visits_daily_fact_y2014m08_feature_type_id_index;
|
238
|
+
ALTER INDEX visits_daily_fact_y2014m08_stage_PID_time_key_index RENAME TO visits_daily_fact_y2014m08_time_key_index;
|
245
239
|
|
246
240
|
COMMIT;
|
247
241
|
EOS
|
@@ -257,21 +251,19 @@ describe Masamune::Transform::RollupFact do
|
|
257
251
|
|
258
252
|
it 'should eq render rollup_fact template' do
|
259
253
|
is_expected.to eq <<-EOS.strip_heredoc
|
260
|
-
|
254
|
+
DROP TABLE IF EXISTS visits_monthly_fact_y2014m08_stage_PID CASCADE;
|
255
|
+
CREATE TABLE IF NOT EXISTS visits_monthly_fact_y2014m08_stage_PID (LIKE visits_monthly_fact INCLUDING ALL);
|
261
256
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
ALTER TABLE
|
266
|
-
ALTER TABLE
|
267
|
-
ALTER TABLE
|
268
|
-
ALTER TABLE
|
269
|
-
ALTER TABLE visits_monthly_fact_y2014m08_stage ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_user_dimension_id_fkey FOREIGN KEY (user_dimension_id) REFERENCES user_dimension(id);
|
270
|
-
ALTER TABLE visits_monthly_fact_y2014m08_stage ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id);
|
271
|
-
ALTER TABLE visits_monthly_fact_y2014m08_stage ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id);
|
257
|
+
ALTER TABLE visits_monthly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_PID_time_key_check CHECK (time_key >= 1406851200 AND time_key < 1409529600);
|
258
|
+
ALTER TABLE visits_monthly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_PID_cluster_type_id_fkey FOREIGN KEY (cluster_type_id) REFERENCES cluster_type(id);
|
259
|
+
ALTER TABLE visits_monthly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_PID_date_dimension_id_fkey FOREIGN KEY (date_dimension_id) REFERENCES date_dimension(id);
|
260
|
+
ALTER TABLE visits_monthly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_PID_tenant_dimension_id_fkey FOREIGN KEY (tenant_dimension_id) REFERENCES tenant_dimension(id);
|
261
|
+
ALTER TABLE visits_monthly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_PID_user_dimension_id_fkey FOREIGN KEY (user_dimension_id) REFERENCES user_dimension(id);
|
262
|
+
ALTER TABLE visits_monthly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_PID_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id);
|
263
|
+
ALTER TABLE visits_monthly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_monthly_fact_y2014m08_stage_PID_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id);
|
272
264
|
|
273
265
|
INSERT INTO
|
274
|
-
|
266
|
+
visits_monthly_fact_y2014m08_stage_PID (date_dimension_id, tenant_dimension_id, user_dimension_id, user_agent_type_id, feature_type_id, total, time_key)
|
275
267
|
SELECT
|
276
268
|
(SELECT id FROM date_dimension d WHERE d.month_epoch = date_dimension.month_epoch ORDER BY d.date_id LIMIT 1),
|
277
269
|
visits_daily_fact_y2014m08.tenant_dimension_id,
|
@@ -294,20 +286,18 @@ describe Masamune::Transform::RollupFact do
|
|
294
286
|
visits_daily_fact_y2014m08.feature_type_id
|
295
287
|
;
|
296
288
|
|
297
|
-
CREATE INDEX
|
298
|
-
CREATE INDEX
|
299
|
-
CREATE INDEX
|
300
|
-
CREATE INDEX
|
301
|
-
CREATE INDEX
|
302
|
-
CREATE INDEX
|
303
|
-
CREATE INDEX
|
304
|
-
|
305
|
-
COMMIT;
|
289
|
+
CREATE INDEX visits_monthly_fact_y2014m08_stage_PID_cluster_type_id_index ON visits_monthly_fact_y2014m08_stage_PID (cluster_type_id);
|
290
|
+
CREATE INDEX visits_monthly_fact_y2014m08_stage_PID_date_dimension_id_index ON visits_monthly_fact_y2014m08_stage_PID (date_dimension_id);
|
291
|
+
CREATE INDEX visits_monthly_fact_y2014m08_stage_PID_tenant_dimension_id_index ON visits_monthly_fact_y2014m08_stage_PID (tenant_dimension_id);
|
292
|
+
CREATE INDEX visits_monthly_fact_y2014m08_stage_PID_user_dimension_id_index ON visits_monthly_fact_y2014m08_stage_PID (user_dimension_id);
|
293
|
+
CREATE INDEX visits_monthly_fact_y2014m08_stage_PID_user_agent_type_id_index ON visits_monthly_fact_y2014m08_stage_PID (user_agent_type_id);
|
294
|
+
CREATE INDEX visits_monthly_fact_y2014m08_stage_PID_feature_type_id_index ON visits_monthly_fact_y2014m08_stage_PID (feature_type_id);
|
295
|
+
CREATE INDEX visits_monthly_fact_y2014m08_stage_PID_time_key_index ON visits_monthly_fact_y2014m08_stage_PID (time_key);
|
306
296
|
|
307
297
|
BEGIN;
|
308
298
|
|
309
299
|
DROP TABLE IF EXISTS visits_monthly_fact_y2014m08;
|
310
|
-
ALTER TABLE
|
300
|
+
ALTER TABLE visits_monthly_fact_y2014m08_stage_PID RENAME TO visits_monthly_fact_y2014m08;
|
311
301
|
|
312
302
|
ALTER TABLE visits_monthly_fact_y2014m08 INHERIT visits_monthly_fact;
|
313
303
|
ALTER TABLE visits_monthly_fact_y2014m08 ADD CONSTRAINT visits_monthly_fact_y2014m08_time_key_check CHECK (time_key >= 1406851200 AND time_key < 1409529600) NOT VALID;
|
@@ -318,13 +308,13 @@ describe Masamune::Transform::RollupFact do
|
|
318
308
|
ALTER TABLE visits_monthly_fact_y2014m08 ADD CONSTRAINT visits_monthly_fact_y2014m08_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id) NOT VALID;
|
319
309
|
ALTER TABLE visits_monthly_fact_y2014m08 ADD CONSTRAINT visits_monthly_fact_y2014m08_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id) NOT VALID;
|
320
310
|
|
321
|
-
ALTER INDEX
|
322
|
-
ALTER INDEX
|
323
|
-
ALTER INDEX
|
324
|
-
ALTER INDEX
|
325
|
-
ALTER INDEX
|
326
|
-
ALTER INDEX
|
327
|
-
ALTER INDEX
|
311
|
+
ALTER INDEX visits_monthly_fact_y2014m08_stage_PID_cluster_type_id_index RENAME TO visits_monthly_fact_y2014m08_cluster_type_id_index;
|
312
|
+
ALTER INDEX visits_monthly_fact_y2014m08_stage_PID_date_dimension_id_index RENAME TO visits_monthly_fact_y2014m08_date_dimension_id_index;
|
313
|
+
ALTER INDEX visits_monthly_fact_y2014m08_stage_PID_tenant_dimension_id_index RENAME TO visits_monthly_fact_y2014m08_tenant_dimension_id_index;
|
314
|
+
ALTER INDEX visits_monthly_fact_y2014m08_stage_PID_user_dimension_id_index RENAME TO visits_monthly_fact_y2014m08_user_dimension_id_index;
|
315
|
+
ALTER INDEX visits_monthly_fact_y2014m08_stage_PID_user_agent_type_id_index RENAME TO visits_monthly_fact_y2014m08_user_agent_type_id_index;
|
316
|
+
ALTER INDEX visits_monthly_fact_y2014m08_stage_PID_feature_type_id_index RENAME TO visits_monthly_fact_y2014m08_feature_type_id_index;
|
317
|
+
ALTER INDEX visits_monthly_fact_y2014m08_stage_PID_time_key_index RENAME TO visits_monthly_fact_y2014m08_time_key_index;
|
328
318
|
|
329
319
|
COMMIT;
|
330
320
|
EOS
|
@@ -24,6 +24,8 @@ require 'spec_helper'
|
|
24
24
|
|
25
25
|
describe Masamune::Transform::StageFact do
|
26
26
|
before do
|
27
|
+
allow(Process).to receive(:pid).and_return('PID')
|
28
|
+
|
27
29
|
catalog.schema :postgres do
|
28
30
|
dimension 'cluster', type: :mini do
|
29
31
|
column 'id', type: :sequence, surrogate_key: true, auto: true
|
@@ -100,22 +102,20 @@ describe Masamune::Transform::StageFact do
|
|
100
102
|
|
101
103
|
it 'should eq render stage_fact template' do
|
102
104
|
is_expected.to eq <<-EOS.strip_heredoc
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
ALTER TABLE
|
109
|
-
ALTER TABLE
|
110
|
-
ALTER TABLE
|
111
|
-
ALTER TABLE
|
112
|
-
ALTER TABLE
|
113
|
-
ALTER TABLE
|
114
|
-
ALTER TABLE visits_hourly_fact_y2014m08_stage ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id);
|
115
|
-
ALTER TABLE visits_hourly_fact_y2014m08_stage ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id);
|
105
|
+
DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage_PID CASCADE;
|
106
|
+
CREATE TABLE IF NOT EXISTS visits_hourly_fact_y2014m08_stage_PID (LIKE visits_hourly_fact INCLUDING ALL);
|
107
|
+
|
108
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_time_key_check CHECK (time_key >= 1406851200 AND time_key < 1409529600);
|
109
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_cluster_type_id_fkey FOREIGN KEY (cluster_type_id) REFERENCES cluster_type(id);
|
110
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_date_dimension_id_fkey FOREIGN KEY (date_dimension_id) REFERENCES date_dimension(id);
|
111
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_tenant_dimension_id_fkey FOREIGN KEY (tenant_dimension_id) REFERENCES tenant_dimension(id);
|
112
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_user_dimension_id_fkey FOREIGN KEY (user_dimension_id) REFERENCES user_dimension(id);
|
113
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_group_dimension_id_fkey FOREIGN KEY (group_dimension_id) REFERENCES group_dimension(id);
|
114
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id);
|
115
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID ADD CONSTRAINT visits_hourly_fact_y2014m08_stage_PID_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id);
|
116
116
|
|
117
117
|
INSERT INTO
|
118
|
-
|
118
|
+
visits_hourly_fact_y2014m08_stage_PID (date_dimension_id, tenant_dimension_id, user_dimension_id, group_dimension_id, user_agent_type_id, feature_type_id, session_type_id, total, time_key)
|
119
119
|
SELECT
|
120
120
|
date_dimension.id,
|
121
121
|
tenant_dimension.id,
|
@@ -160,22 +160,20 @@ describe Masamune::Transform::StageFact do
|
|
160
160
|
feature_type.name = visits_hourly_file_fact_stage.feature_type_name
|
161
161
|
;
|
162
162
|
|
163
|
-
CREATE INDEX
|
164
|
-
CREATE INDEX
|
165
|
-
CREATE INDEX
|
166
|
-
CREATE INDEX
|
167
|
-
CREATE INDEX
|
168
|
-
CREATE INDEX
|
169
|
-
CREATE INDEX
|
170
|
-
CREATE INDEX
|
171
|
-
CREATE INDEX
|
172
|
-
|
173
|
-
COMMIT;
|
163
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_cluster_type_id_index ON visits_hourly_fact_y2014m08_stage_PID (cluster_type_id);
|
164
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_date_dimension_id_index ON visits_hourly_fact_y2014m08_stage_PID (date_dimension_id);
|
165
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_tenant_dimension_id_index ON visits_hourly_fact_y2014m08_stage_PID (tenant_dimension_id);
|
166
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_user_dimension_id_index ON visits_hourly_fact_y2014m08_stage_PID (user_dimension_id);
|
167
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_group_dimension_id_index ON visits_hourly_fact_y2014m08_stage_PID (group_dimension_id);
|
168
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_user_agent_type_id_index ON visits_hourly_fact_y2014m08_stage_PID (user_agent_type_id);
|
169
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_feature_type_id_index ON visits_hourly_fact_y2014m08_stage_PID (feature_type_id);
|
170
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_session_type_id_index ON visits_hourly_fact_y2014m08_stage_PID (session_type_id);
|
171
|
+
CREATE INDEX visits_hourly_fact_y2014m08_stage_PID_time_key_index ON visits_hourly_fact_y2014m08_stage_PID (time_key);
|
174
172
|
|
175
173
|
BEGIN;
|
176
174
|
|
177
175
|
DROP TABLE IF EXISTS visits_hourly_fact_y2014m08;
|
178
|
-
ALTER TABLE
|
176
|
+
ALTER TABLE visits_hourly_fact_y2014m08_stage_PID RENAME TO visits_hourly_fact_y2014m08;
|
179
177
|
|
180
178
|
ALTER TABLE visits_hourly_fact_y2014m08 INHERIT visits_hourly_fact;
|
181
179
|
ALTER TABLE visits_hourly_fact_y2014m08 ADD CONSTRAINT visits_hourly_fact_y2014m08_time_key_check CHECK (time_key >= 1406851200 AND time_key < 1409529600) NOT VALID;
|
@@ -187,15 +185,15 @@ describe Masamune::Transform::StageFact do
|
|
187
185
|
ALTER TABLE visits_hourly_fact_y2014m08 ADD CONSTRAINT visits_hourly_fact_y2014m08_user_agent_type_id_fkey FOREIGN KEY (user_agent_type_id) REFERENCES user_agent_type(id) NOT VALID;
|
188
186
|
ALTER TABLE visits_hourly_fact_y2014m08 ADD CONSTRAINT visits_hourly_fact_y2014m08_feature_type_id_fkey FOREIGN KEY (feature_type_id) REFERENCES feature_type(id) NOT VALID;
|
189
187
|
|
190
|
-
ALTER INDEX
|
191
|
-
ALTER INDEX
|
192
|
-
ALTER INDEX
|
193
|
-
ALTER INDEX
|
194
|
-
ALTER INDEX
|
195
|
-
ALTER INDEX
|
196
|
-
ALTER INDEX
|
197
|
-
ALTER INDEX
|
198
|
-
ALTER INDEX
|
188
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_cluster_type_id_index RENAME TO visits_hourly_fact_y2014m08_cluster_type_id_index;
|
189
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_date_dimension_id_index RENAME TO visits_hourly_fact_y2014m08_date_dimension_id_index;
|
190
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_tenant_dimension_id_index RENAME TO visits_hourly_fact_y2014m08_tenant_dimension_id_index;
|
191
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_user_dimension_id_index RENAME TO visits_hourly_fact_y2014m08_user_dimension_id_index;
|
192
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_group_dimension_id_index RENAME TO visits_hourly_fact_y2014m08_group_dimension_id_index;
|
193
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_user_agent_type_id_index RENAME TO visits_hourly_fact_y2014m08_user_agent_type_id_index;
|
194
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_feature_type_id_index RENAME TO visits_hourly_fact_y2014m08_feature_type_id_index;
|
195
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_session_type_id_index RENAME TO visits_hourly_fact_y2014m08_session_type_id_index;
|
196
|
+
ALTER INDEX visits_hourly_fact_y2014m08_stage_PID_time_key_index RENAME TO visits_hourly_fact_y2014m08_time_key_index;
|
199
197
|
|
200
198
|
COMMIT;
|
201
199
|
EOS
|
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.11.
|
4
|
+
version: 0.11.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Andrews
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|