masamune 0.12.1 → 0.12.2

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: 0fa78c46b273926ab7d772334d589a4376532612
4
- data.tar.gz: c95f3122a4c62bd3fa65f1f0bf4b16287917553e
3
+ metadata.gz: 49cf069b1b8b08d4564094cbf3893fd9a5a96d6d
4
+ data.tar.gz: eae59d5b26dcc4b78db6e4024841b53bc48cac6b
5
5
  SHA512:
6
- metadata.gz: 2c61a1654730091053886326dce2a53b313df2041040e5dba0c54c5699c39927eae80299bf4b50333ad1a700a8322144310c6fdb65d6022ab51a26b7cfee0e4a
7
- data.tar.gz: baba5a9769d75196fcf35442084326e0d0c27ab22b71aaf2c4e31826c03953ea23c4b8e9e9af6b4234d0ef8910c22bb8783275405d09d173e6f617867ee3c193
6
+ metadata.gz: 05f7ebbb93c6eeae7b5ede63c098da7d08fb1a5cc616cc0cf31ebfd7eaca7447b70e29d5f9b5e7c54b5217e8689d8270660e349a4e35fb4d4f26467da01aeac0
7
+ data.tar.gz: cd36f48081410e820ed5485820b186b6455ecf456eeec364830f53cd9eb0ff53b1500ac85fbc2dc03d964bd97bfd2f577a064939777a121f573b939b910c2b04
@@ -80,8 +80,6 @@ module Masamune::Schema
80
80
  'uuid_generate_v4()'
81
81
  when :sequence
82
82
  "nextval('#{sequence_id}')"
83
- when :enum
84
- values.first
85
83
  end
86
84
  end
87
85
 
@@ -277,7 +275,7 @@ module Masamune::Schema
277
275
  nil
278
276
  end
279
277
  when :integer
280
- value.nil? ? nil : value.to_i
278
+ value.blank? ? nil : value.to_i
281
279
  when :yaml
282
280
  case value
283
281
  when Hash
@@ -470,6 +468,7 @@ module Masamune::Schema
470
468
  def required_value?
471
469
  return false if reference && (reference.null || !reference.default.nil?)
472
470
  return false if null || !default.nil?
471
+ return false if !strict
473
472
  true
474
473
  end
475
474
 
@@ -20,6 +20,17 @@
20
20
  -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  -- THE SOFTWARE.
22
22
 
23
+ WITH consolidated AS (
24
+ SELECT
25
+ <%- target.insert_view_values(coalesce: true).each do |value| -%>
26
+ <%= value %><%= ',' %>
27
+ <%- end -%>
28
+ parent_id,
29
+ record_id,
30
+ start_at
31
+ FROM
32
+ <%= source.name %>
33
+ )
23
34
  INSERT INTO
24
35
  <%= target.name %> (<%= target.insert_columns.join(', ') %>, parent_id, record_id, start_at)
25
36
  SELECT DISTINCT
@@ -38,13 +49,13 @@ FROM (
38
49
  record_id,
39
50
  start_at,
40
51
  CASE
41
- WHEN <%= target.insert_view_values.map { |value| "(LAG(#{value}) OVER w = #{value})" }.join(' AND ') %> THEN
52
+ WHEN <%= target.duplicate_value_conditions('w').join(' AND ') %> THEN
42
53
  1
43
54
  ELSE
44
55
  0
45
56
  END AS duplicate
46
57
  FROM
47
- <%= source.name %>
58
+ consolidated
48
59
  WINDOW w AS (PARTITION BY <%= target.window.join(', ') %> ORDER BY start_at)
49
60
  ) tmp
50
61
  WHERE
@@ -35,8 +35,26 @@ module Masamune::Transform
35
35
  consolidated_columns.map { |_, column| column.name }
36
36
  end
37
37
 
38
- def insert_view_values
39
- consolidated_columns.map { |_, column| column.name }
38
+ def insert_view_values(coalesce: false)
39
+ consolidated_columns.map do |_, column|
40
+ if !column.default.nil? && coalesce
41
+ "COALESCE(#{column.name}, #{column.sql_value(column.default)}) AS #{column.name}"
42
+ else
43
+ column.name
44
+ end
45
+ end
46
+ end
47
+
48
+ def duplicate_value_conditions(window)
49
+ [].tap do |result|
50
+ consolidated_columns.map do |_, column|
51
+ if column.null
52
+ result << "((LAG(#{column.name}) OVER #{window} = #{column.name}) OR (LAG(#{column.name}) OVER #{window} IS NULL AND #{column.name} IS NULL))"
53
+ else
54
+ result << "(LAG(#{column.name}) OVER #{window} = #{column.name})"
55
+ end
56
+ end
57
+ end
40
58
  end
41
59
 
42
60
  def window(*extra)
@@ -27,7 +27,7 @@ SELECT
27
27
  FROM
28
28
  <%= target.name %>
29
29
  <%- target.join_conditions(columns).each do |table, condition| -%>
30
- JOIN
30
+ LEFT JOIN
31
31
  <%= table %>
32
32
  ON
33
33
  <%= condition %>
@@ -0,0 +1,67 @@
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
+ <%- target_tmp = target.stage_table(suffix: 'tmp') %>
24
+
25
+ SELECT pg_advisory_lock(ddl_advisory_lock());
26
+
27
+ DROP TABLE IF EXISTS <%= target_tmp.name %> CASCADE;
28
+
29
+ BEGIN;
30
+ SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
31
+
32
+ ALTER TABLE <%= target.name %> DROP CONSTRAINT IF EXISTS <%= target.name %>_time_key_check;
33
+ <%- target.foreign_key_columns.each do |column| -%>
34
+ <%- if column.reference_constraint -%>
35
+ ALTER TABLE <%= target.name %> DROP CONSTRAINT IF EXISTS <%= target.name %>_<%= column.name %>_fkey CASCADE;
36
+ <%- end -%>
37
+ <%- end -%>
38
+
39
+ <%- target.index_columns.each do |column_names, unique, id| -%>
40
+ <%- index_name = "#{target.name}_#{id}_index" -%>
41
+ DROP INDEX IF EXISTS <%= index_name %>;
42
+ <%- end -%>
43
+
44
+ ALTER TABLE <%= target.name %> RENAME TO <%= target_tmp.name %>;
45
+ ALTER TABLE <%= source.name %> RENAME TO <%= target.name %>;
46
+
47
+ ALTER TABLE <%= target.name %> INHERIT <%= target.parent.name %>;
48
+ ALTER TABLE <%= target.name %> ADD CONSTRAINT <%= target.name %>_time_key_check <%= target.constraints %>;
49
+ <%- target.foreign_key_columns.each do |column| -%>
50
+ <%- if column.reference_constraint -%>
51
+ ALTER TABLE <%= target.name %> ADD CONSTRAINT <%= target.name %>_<%= column.name %>_fkey FOREIGN KEY (<%= column.name %>) <%= column.reference_constraint %> NOT VALID DEFERRABLE INITIALLY DEFERRED;
52
+ <%- end -%>
53
+ <%- end -%>
54
+
55
+ <%- target.index_columns.each do |column_names, unique, id| -%>
56
+ <%- index_name = "#{target.name}_#{id}_index" -%>
57
+ CREATE <%= unique ? 'UNIQUE INDEX' : 'INDEX' %> <%= index_name %> ON <%= target.name %> (<%= column_names.join(', ') %>);
58
+ <%- end -%>
59
+
60
+ ANALYZE <%= target.name %>;
61
+
62
+ COMMIT;
63
+
64
+ DROP TABLE IF EXISTS <%= target_tmp.name %> CASCADE;
65
+ DROP TABLE IF EXISTS <%= source.name %> CASCADE;
66
+
67
+ SELECT pg_advisory_unlock(ddl_advisory_lock());
@@ -25,11 +25,12 @@
25
25
  SELECT pg_advisory_lock(<%= target_stage.lock_id %>);
26
26
 
27
27
  DROP TABLE IF EXISTS <%= target_stage.name %> CASCADE;
28
- DROP TABLE IF EXISTS <%= target_stage.name %>_tmp CASCADE;
29
28
 
30
29
  CREATE TABLE IF NOT EXISTS <%= target.name %> (LIKE <%= target.parent.name %> INCLUDING ALL);
31
30
  CREATE TABLE IF NOT EXISTS <%= target_stage.name %> (LIKE <%= target.parent.name %> INCLUDING ALL);
32
31
 
32
+ BEGIN;
33
+
33
34
  INSERT INTO
34
35
  <%= target_stage.name %> (<%= target.insert_columns(source).join(', ') %>)
35
36
  SELECT
@@ -50,46 +51,8 @@ GROUP BY
50
51
  <%- end -%>
51
52
  ;
52
53
 
53
- SELECT pg_advisory_lock(ddl_advisory_lock());
54
-
55
- BEGIN;
56
- SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
57
-
58
- ALTER TABLE <%= target.name %> DROP CONSTRAINT IF EXISTS <%= target.name %>_time_key_check;
59
- <%- target.foreign_key_columns.each do |column| -%>
60
- <%- if column.reference_constraint -%>
61
- ALTER TABLE <%= target.name %> DROP CONSTRAINT IF EXISTS <%= target.name %>_<%= column.name %>_fkey CASCADE;
62
- <%- end -%>
63
- <%- end -%>
64
-
65
- <%- target.index_columns.each do |column_names, unique, id| -%>
66
- <%- index_name = "#{target.name}_#{id}_index" -%>
67
- DROP INDEX IF EXISTS <%= index_name %>;
68
- <%- end -%>
69
-
70
- ALTER TABLE <%= target.name %> RENAME TO <%= target_stage.name %>_tmp;
71
- ALTER TABLE <%= target_stage.name %> RENAME TO <%= target.name %>;
72
-
73
- ALTER TABLE <%= target.name %> INHERIT <%= target.parent.name %>;
74
- ALTER TABLE <%= target.name %> ADD CONSTRAINT <%= target.name %>_time_key_check <%= target.constraints %>;
75
- <%- target.foreign_key_columns.each do |column| -%>
76
- <%- if column.reference_constraint -%>
77
- ALTER TABLE <%= target.name %> ADD CONSTRAINT <%= target.name %>_<%= column.name %>_fkey FOREIGN KEY (<%= column.name %>) <%= column.reference_constraint %> NOT VALID DEFERRABLE INITIALLY DEFERRED;
78
- <%- end -%>
79
- <%- end -%>
80
-
81
- <%- target.index_columns.each do |column_names, unique, id| -%>
82
- <%- index_name = "#{target.name}_#{id}_index" -%>
83
- CREATE <%= unique ? 'UNIQUE INDEX' : 'INDEX' %> <%= index_name %> ON <%= target.name %> (<%= column_names.join(', ') %>);
84
- <%- end -%>
85
-
86
- ANALYZE <%= target.name %>;
87
-
88
54
  COMMIT;
89
55
 
90
- DROP TABLE IF EXISTS <%= target_stage.name %>_tmp CASCADE;
91
- DROP TABLE IF EXISTS <%= target_stage.name %> CASCADE;
92
-
93
- SELECT pg_advisory_unlock(ddl_advisory_lock());
56
+ <%= render 'replace_table.psql.erb', source: target_stage, target: target %>
94
57
 
95
58
  SELECT pg_advisory_unlock(<%= target_stage.lock_id %>);
@@ -42,7 +42,7 @@ module Masamune::Transform
42
42
  end
43
43
 
44
44
  def insert_view_constraints
45
- consolidated_columns.reject { |_, column| column.null }.map { |_, column| "#{column.name} IS NOT NULL" }
45
+ consolidated_columns.reject { |_, column| !column.default.nil? || column.null }.map { |_, column| "#{column.name} IS NOT NULL" }
46
46
  end
47
47
  method_with_last_element :insert_view_constraints
48
48
 
@@ -26,11 +26,12 @@
26
26
  SELECT pg_advisory_lock(<%= target_partition.lock_id %>);
27
27
 
28
28
  DROP TABLE IF EXISTS <%= target_stage.name %> CASCADE;
29
- DROP TABLE IF EXISTS <%= target_partition.name %>_tmp CASCADE;
30
29
 
31
30
  CREATE TABLE IF NOT EXISTS <%= target_stage.name %> (LIKE <%= target.name %> INCLUDING ALL);
32
31
  CREATE TABLE IF NOT EXISTS <%= target_partition.name %> (LIKE <%= target.name %> INCLUDING ALL);
33
32
 
33
+ BEGIN;
34
+
34
35
  INSERT INTO
35
36
  <%= target_stage.name %> (<%= target.insert_columns(source).join(', ') %>)
36
37
  SELECT
@@ -47,46 +48,8 @@ ON
47
48
  <%- end -%>
48
49
  ;
49
50
 
50
- SELECT pg_advisory_lock(ddl_advisory_lock());
51
-
52
- BEGIN;
53
- SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
54
-
55
- ALTER TABLE <%= target_partition.name %> DROP CONSTRAINT IF EXISTS <%= target_partition.name %>_time_key_check;
56
- <%- target.foreign_key_columns.each do |column| -%>
57
- <%- if column.reference_constraint -%>
58
- ALTER TABLE <%= target_partition.name %> DROP CONSTRAINT IF EXISTS <%= target_partition.name %>_<%= column.name %>_fkey CASCADE;
59
- <%- end -%>
60
- <%- end -%>
61
-
62
- <%- target_partition.index_columns.each do |column_names, unique, id| -%>
63
- <%- index_name = "#{target_partition.name}_#{id}_index" -%>
64
- DROP INDEX IF EXISTS <%= index_name %>;
65
- <%- end -%>
66
-
67
- ALTER TABLE <%= target_partition.name %> RENAME TO <%= target_partition.name %>_tmp;
68
- ALTER TABLE <%= target_stage.name %> RENAME TO <%= target_partition.name %>;
69
-
70
- ALTER TABLE <%= target_partition.name %> INHERIT <%= target.name %>;
71
- ALTER TABLE <%= target_partition.name %> ADD CONSTRAINT <%= target_partition.name %>_time_key_check <%= target_partition.constraints %>;
72
- <%- target.foreign_key_columns.each do |column| -%>
73
- <%- if column.reference_constraint -%>
74
- ALTER TABLE <%= target_partition.name %> ADD CONSTRAINT <%= target_partition.name %>_<%= column.name %>_fkey FOREIGN KEY (<%= column.name %>) <%= column.reference_constraint %> NOT VALID DEFERRABLE INITIALLY DEFERRED;
75
- <%- end -%>
76
- <%- end -%>
77
-
78
- <%- target_partition.index_columns.each do |column_names, unique, id| -%>
79
- <%- index_name = "#{target_partition.name}_#{id}_index" -%>
80
- CREATE <%= unique ? 'UNIQUE INDEX' : 'INDEX' %> <%= index_name %> ON <%= target_partition.name %> (<%= column_names.join(', ') %>);
81
- <%- end -%>
82
-
83
- ANALYZE <%= target_partition.name %>;
84
-
85
51
  COMMIT;
86
52
 
87
- DROP TABLE IF EXISTS <%= target_partition.name %>_tmp CASCADE;
88
- DROP TABLE IF EXISTS <%= target_stage.name %> CASCADE;
89
-
90
- SELECT pg_advisory_unlock(ddl_advisory_lock());
53
+ <%= render 'replace_table.psql.erb', source: target_stage, target: target_partition %>
91
54
 
92
55
  SELECT pg_advisory_unlock(<%= target_partition.lock_id %>);
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Masamune
24
- VERSION = '0.12.1'
24
+ VERSION = '0.12.2'
25
25
  end
@@ -65,7 +65,7 @@ describe Masamune::Schema::Column do
65
65
 
66
66
  context '#default' do
67
67
  subject { column.default }
68
- it { is_expected.to eq('public') }
68
+ it { is_expected.to be_nil }
69
69
  end
70
70
 
71
71
  context '#sql_type' do
@@ -342,6 +342,30 @@ describe Masamune::Schema::Column do
342
342
  end
343
343
  end
344
344
 
345
+ context 'with type :integer' do
346
+ let(:column) { described_class.new(id: 'integer', type: :integer) }
347
+
348
+ context 'when nil' do
349
+ let(:value) { nil }
350
+ it { is_expected.to be(nil) }
351
+ end
352
+
353
+ context 'when blank' do
354
+ let(:value) { '' }
355
+ it { is_expected.to be(nil) }
356
+ end
357
+
358
+ context 'when String encoded Integer' do
359
+ let(:value) { "1" }
360
+ it { is_expected.to eq(1) }
361
+ end
362
+
363
+ context 'when Integer' do
364
+ let(:value) { 1 }
365
+ it { is_expected.to eq(1) }
366
+ end
367
+ end
368
+
345
369
  context 'with type :timestamp' do
346
370
  let(:column) { described_class.new(id: 'timestamp', type: :timestamp) }
347
371
 
@@ -635,6 +659,16 @@ describe Masamune::Schema::Column do
635
659
  it { is_expected.to eq(false) }
636
660
  end
637
661
 
662
+ context 'when :strict true' do
663
+ let(:column) { described_class.new id: 'name', type: :string, strict: true }
664
+ it { is_expected.to eq(true) }
665
+ end
666
+
667
+ context 'when :strict false' do
668
+ let(:column) { described_class.new id: 'name', type: :string, strict: false }
669
+ it { is_expected.to eq(false) }
670
+ end
671
+
638
672
  context 'when column has default' do
639
673
  let(:column) { described_class.new id: 'name', type: :string, default: 'missing' }
640
674
  it { is_expected.to eq(false) }
@@ -46,6 +46,18 @@ describe Masamune::Transform::DeduplicateDimension do
46
46
 
47
47
  it 'should render deduplicate_dimension template' do
48
48
  is_expected.to eq <<-EOS.strip_heredoc
49
+ WITH consolidated AS (
50
+ SELECT
51
+ user_account_state_type_id,
52
+ tenant_id,
53
+ user_id,
54
+ preferences,
55
+ parent_id,
56
+ record_id,
57
+ start_at
58
+ FROM
59
+ user_consolidated_dimension_stage
60
+ )
49
61
  INSERT INTO
50
62
  user_deduplicated_dimension_stage (user_account_state_type_id, tenant_id, user_id, preferences, parent_id, record_id, start_at)
51
63
  SELECT DISTINCT
@@ -66,13 +78,13 @@ describe Masamune::Transform::DeduplicateDimension do
66
78
  record_id,
67
79
  start_at,
68
80
  CASE
69
- WHEN (LAG(user_account_state_type_id) OVER w = user_account_state_type_id) AND (LAG(tenant_id) OVER w = tenant_id) AND (LAG(user_id) OVER w = user_id) AND (LAG(preferences) OVER w = preferences) THEN
81
+ WHEN (LAG(user_account_state_type_id) OVER w = user_account_state_type_id) AND (LAG(tenant_id) OVER w = tenant_id) AND (LAG(user_id) OVER w = user_id) AND ((LAG(preferences) OVER w = preferences) OR (LAG(preferences) OVER w IS NULL AND preferences IS NULL)) THEN
70
82
  1
71
83
  ELSE
72
84
  0
73
85
  END AS duplicate
74
86
  FROM
75
- user_consolidated_dimension_stage
87
+ consolidated
76
88
  WINDOW w AS (PARTITION BY tenant_id, user_id ORDER BY start_at)
77
89
  ) tmp
78
90
  WHERE
@@ -97,19 +97,19 @@ describe Masamune::Transform::DenormalizeTable do
97
97
  visits_fact.time_key
98
98
  FROM
99
99
  visits_fact
100
- JOIN
100
+ LEFT JOIN
101
101
  date_dimension
102
102
  ON
103
103
  date_dimension.id = visits_fact.date_dimension_id
104
- JOIN
104
+ LEFT JOIN
105
105
  tenant_dimension
106
106
  ON
107
107
  tenant_dimension.id = visits_fact.tenant_dimension_id
108
- JOIN
108
+ LEFT JOIN
109
109
  user_dimension
110
110
  ON
111
111
  user_dimension.id = visits_fact.user_dimension_id
112
- JOIN
112
+ LEFT JOIN
113
113
  user_agent_type
114
114
  ON
115
115
  user_agent_type.id = visits_fact.user_agent_type_id
@@ -152,19 +152,19 @@ describe Masamune::Transform::DenormalizeTable do
152
152
  visits_fact.time_key
153
153
  FROM
154
154
  visits_fact
155
- JOIN
155
+ LEFT JOIN
156
156
  date_dimension
157
157
  ON
158
158
  date_dimension.id = visits_fact.date_dimension_id
159
- JOIN
159
+ LEFT JOIN
160
160
  tenant_dimension
161
161
  ON
162
162
  tenant_dimension.id = visits_fact.tenant_dimension_id
163
- JOIN
163
+ LEFT JOIN
164
164
  user_dimension
165
165
  ON
166
166
  user_dimension.id = visits_fact.user_dimension_id
167
- JOIN
167
+ LEFT JOIN
168
168
  user_agent_type
169
169
  ON
170
170
  user_agent_type.id = visits_fact.user_agent_type_id
@@ -95,11 +95,12 @@ describe Masamune::Transform::RollupFact do
95
95
  SELECT pg_advisory_lock(42);
96
96
 
97
97
  DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage CASCADE;
98
- DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage_tmp CASCADE;
99
98
 
100
99
  CREATE TABLE IF NOT EXISTS visits_hourly_fact_y2014m08 (LIKE visits_hourly_fact INCLUDING ALL);
101
100
  CREATE TABLE IF NOT EXISTS visits_hourly_fact_y2014m08_stage (LIKE visits_hourly_fact INCLUDING ALL);
102
101
 
102
+ BEGIN;
103
+
103
104
  INSERT INTO
104
105
  visits_hourly_fact_y2014m08_stage (date_dimension_id, tenant_dimension_id, user_dimension_id, user_agent_type_id, feature_type_id, total, time_key)
105
106
  SELECT
@@ -125,8 +126,12 @@ describe Masamune::Transform::RollupFact do
125
126
  (visits_transaction_fact_y2014m08.time_key - (visits_transaction_fact_y2014m08.time_key % 3600))
126
127
  ;
127
128
 
129
+ COMMIT;
130
+
128
131
  SELECT pg_advisory_lock(ddl_advisory_lock());
129
132
 
133
+ DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage_tmp CASCADE;
134
+
130
135
  BEGIN;
131
136
  SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
132
137
 
@@ -192,11 +197,12 @@ describe Masamune::Transform::RollupFact do
192
197
  SELECT pg_advisory_lock(42);
193
198
 
194
199
  DROP TABLE IF EXISTS visits_daily_fact_y2014m08_stage CASCADE;
195
- DROP TABLE IF EXISTS visits_daily_fact_y2014m08_stage_tmp CASCADE;
196
200
 
197
201
  CREATE TABLE IF NOT EXISTS visits_daily_fact_y2014m08 (LIKE visits_daily_fact INCLUDING ALL);
198
202
  CREATE TABLE IF NOT EXISTS visits_daily_fact_y2014m08_stage (LIKE visits_daily_fact INCLUDING ALL);
199
203
 
204
+ BEGIN;
205
+
200
206
  INSERT INTO
201
207
  visits_daily_fact_y2014m08_stage (date_dimension_id, tenant_dimension_id, user_dimension_id, user_agent_type_id, feature_type_id, total, time_key)
202
208
  SELECT
@@ -221,8 +227,12 @@ describe Masamune::Transform::RollupFact do
221
227
  visits_hourly_fact_y2014m08.feature_type_id
222
228
  ;
223
229
 
230
+ COMMIT;
231
+
224
232
  SELECT pg_advisory_lock(ddl_advisory_lock());
225
233
 
234
+ DROP TABLE IF EXISTS visits_daily_fact_y2014m08_stage_tmp CASCADE;
235
+
226
236
  BEGIN;
227
237
  SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
228
238
 
@@ -288,11 +298,12 @@ describe Masamune::Transform::RollupFact do
288
298
  SELECT pg_advisory_lock(42);
289
299
 
290
300
  DROP TABLE IF EXISTS visits_monthly_fact_y2014m08_stage CASCADE;
291
- DROP TABLE IF EXISTS visits_monthly_fact_y2014m08_stage_tmp CASCADE;
292
301
 
293
302
  CREATE TABLE IF NOT EXISTS visits_monthly_fact_y2014m08 (LIKE visits_monthly_fact INCLUDING ALL);
294
303
  CREATE TABLE IF NOT EXISTS visits_monthly_fact_y2014m08_stage (LIKE visits_monthly_fact INCLUDING ALL);
295
304
 
305
+ BEGIN;
306
+
296
307
  INSERT INTO
297
308
  visits_monthly_fact_y2014m08_stage (date_dimension_id, tenant_dimension_id, user_dimension_id, user_agent_type_id, feature_type_id, total, time_key)
298
309
  SELECT
@@ -317,8 +328,12 @@ describe Masamune::Transform::RollupFact do
317
328
  visits_daily_fact_y2014m08.feature_type_id
318
329
  ;
319
330
 
331
+ COMMIT;
332
+
320
333
  SELECT pg_advisory_lock(ddl_advisory_lock());
321
334
 
335
+ DROP TABLE IF EXISTS visits_monthly_fact_y2014m08_stage_tmp CASCADE;
336
+
322
337
  BEGIN;
323
338
  SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
324
339
 
@@ -105,11 +105,12 @@ describe Masamune::Transform::StageFact do
105
105
  SELECT pg_advisory_lock(42);
106
106
 
107
107
  DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage CASCADE;
108
- DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_tmp CASCADE;
109
108
 
110
109
  CREATE TABLE IF NOT EXISTS visits_hourly_fact_y2014m08_stage (LIKE visits_hourly_fact INCLUDING ALL);
111
110
  CREATE TABLE IF NOT EXISTS visits_hourly_fact_y2014m08 (LIKE visits_hourly_fact INCLUDING ALL);
112
111
 
112
+ BEGIN;
113
+
113
114
  INSERT INTO
114
115
  visits_hourly_fact_y2014m08_stage (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)
115
116
  SELECT
@@ -156,8 +157,12 @@ describe Masamune::Transform::StageFact do
156
157
  feature_type.name = visits_hourly_file_fact_stage.feature_type_name
157
158
  ;
158
159
 
160
+ COMMIT;
161
+
159
162
  SELECT pg_advisory_lock(ddl_advisory_lock());
160
163
 
164
+ DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage_tmp CASCADE;
165
+
161
166
  BEGIN;
162
167
  SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
163
168
 
@@ -180,7 +185,7 @@ describe Masamune::Transform::StageFact do
180
185
  DROP INDEX IF EXISTS visits_hourly_fact_y2014m08_422efee_index;
181
186
  DROP INDEX IF EXISTS visits_hourly_fact_y2014m08_6444ed3_index;
182
187
 
183
- ALTER TABLE visits_hourly_fact_y2014m08 RENAME TO visits_hourly_fact_y2014m08_tmp;
188
+ ALTER TABLE visits_hourly_fact_y2014m08 RENAME TO visits_hourly_fact_y2014m08_stage_tmp;
184
189
  ALTER TABLE visits_hourly_fact_y2014m08_stage RENAME TO visits_hourly_fact_y2014m08;
185
190
 
186
191
  ALTER TABLE visits_hourly_fact_y2014m08 INHERIT visits_hourly_fact;
@@ -207,7 +212,7 @@ describe Masamune::Transform::StageFact do
207
212
 
208
213
  COMMIT;
209
214
 
210
- DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_tmp CASCADE;
215
+ DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage_tmp CASCADE;
211
216
  DROP TABLE IF EXISTS visits_hourly_fact_y2014m08_stage CASCADE;
212
217
 
213
218
  SELECT pg_advisory_unlock(ddl_advisory_lock());
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.12.1
4
+ version: 0.12.2
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-08-14 00:00:00.000000000 Z
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -285,6 +285,7 @@ files:
285
285
  - lib/masamune/transform/operator.rb
286
286
  - lib/masamune/transform/relabel_dimension.psql.erb
287
287
  - lib/masamune/transform/relabel_dimension.rb
288
+ - lib/masamune/transform/replace_table.psql.erb
288
289
  - lib/masamune/transform/rollup_fact.psql.erb
289
290
  - lib/masamune/transform/rollup_fact.rb
290
291
  - lib/masamune/transform/snapshot_dimension.psql.erb