masamune 0.11.9 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/masamune/actions/transform.rb +31 -16
  3. data/lib/masamune/schema.rb +0 -1
  4. data/lib/masamune/schema/catalog.rb +2 -10
  5. data/lib/masamune/schema/column.rb +16 -30
  6. data/lib/masamune/schema/dimension.rb +2 -9
  7. data/lib/masamune/schema/fact.rb +0 -4
  8. data/lib/masamune/schema/map.rb +1 -1
  9. data/lib/masamune/schema/row.rb +3 -3
  10. data/lib/masamune/schema/store.rb +1 -3
  11. data/lib/masamune/schema/table.rb +28 -2
  12. data/lib/masamune/transform.rb +0 -1
  13. data/lib/masamune/transform/define_schema.rb +0 -6
  14. data/lib/masamune/transform/define_table.hql.erb +7 -6
  15. data/lib/masamune/transform/define_table.rb +1 -0
  16. data/lib/masamune/transform/{define_event_view.hql.erb → denormalize_table.hql.erb} +8 -26
  17. data/lib/masamune/transform/denormalize_table.psql.erb +1 -1
  18. data/lib/masamune/transform/denormalize_table.rb +13 -4
  19. data/lib/masamune/transform/snapshot_dimension.rb +1 -1
  20. data/lib/masamune/transform/stage_fact.rb +1 -1
  21. data/lib/masamune/version.rb +1 -1
  22. data/spec/masamune/actions/transform_spec.rb +50 -18
  23. data/spec/masamune/schema/catalog_spec.rb +0 -53
  24. data/spec/masamune/schema/column_spec.rb +9 -41
  25. data/spec/masamune/schema/fact_spec.rb +3 -1
  26. data/spec/masamune/schema/map_spec.rb +187 -189
  27. data/spec/masamune/schema/table_spec.rb +8 -0
  28. data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +4 -6
  29. data/spec/masamune/transform/define_schema_spec.rb +5 -6
  30. data/spec/masamune/transform/define_table.dimension_spec.rb +101 -2
  31. data/spec/masamune/transform/define_table.fact_spec.rb +2 -0
  32. data/spec/masamune/transform/denormalize_table_spec.rb +170 -14
  33. data/spec/masamune/transform/snapshot_dimension_spec.rb +1 -1
  34. data/spec/masamune/transform/stage_dimension_spec.rb +3 -3
  35. metadata +3 -9
  36. data/lib/masamune/schema/event.rb +0 -121
  37. data/lib/masamune/transform/define_event_view.rb +0 -60
  38. data/spec/masamune/schema/event_spec.rb +0 -75
  39. data/spec/masamune/transform/define_event_view_spec.rb +0 -84
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.9
4
+ version: 0.12.0
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-20 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -245,7 +245,6 @@ files:
245
245
  - lib/masamune/schema/catalog.rb
246
246
  - lib/masamune/schema/column.rb
247
247
  - lib/masamune/schema/dimension.rb
248
- - lib/masamune/schema/event.rb
249
248
  - lib/masamune/schema/fact.rb
250
249
  - lib/masamune/schema/map.rb
251
250
  - lib/masamune/schema/row.rb
@@ -268,8 +267,6 @@ files:
268
267
  - lib/masamune/transform/consolidate_dimension.rb
269
268
  - lib/masamune/transform/deduplicate_dimension.psql.erb
270
269
  - lib/masamune/transform/deduplicate_dimension.rb
271
- - lib/masamune/transform/define_event_view.hql.erb
272
- - lib/masamune/transform/define_event_view.rb
273
270
  - lib/masamune/transform/define_index.psql.erb
274
271
  - lib/masamune/transform/define_schema.hql.erb
275
272
  - lib/masamune/transform/define_schema.psql.erb
@@ -278,6 +275,7 @@ files:
278
275
  - lib/masamune/transform/define_table.psql.erb
279
276
  - lib/masamune/transform/define_table.rb
280
277
  - lib/masamune/transform/define_unique.psql.erb
278
+ - lib/masamune/transform/denormalize_table.hql.erb
281
279
  - lib/masamune/transform/denormalize_table.psql.erb
282
280
  - lib/masamune/transform/denormalize_table.rb
283
281
  - lib/masamune/transform/insert_reference_values.psql.erb
@@ -334,7 +332,6 @@ files:
334
332
  - spec/masamune/schema/catalog_spec.rb
335
333
  - spec/masamune/schema/column_spec.rb
336
334
  - spec/masamune/schema/dimension_spec.rb
337
- - spec/masamune/schema/event_spec.rb
338
335
  - spec/masamune/schema/fact_spec.rb
339
336
  - spec/masamune/schema/map_spec.rb
340
337
  - spec/masamune/schema/row_spec.rb
@@ -350,7 +347,6 @@ files:
350
347
  - spec/masamune/transform/bulk_upsert.dimension_spec.rb
351
348
  - spec/masamune/transform/consolidate_dimension_spec.rb
352
349
  - spec/masamune/transform/deduplicate_dimension_spec.rb
353
- - spec/masamune/transform/define_event_view_spec.rb
354
350
  - spec/masamune/transform/define_schema_spec.rb
355
351
  - spec/masamune/transform/define_table.dimension_spec.rb
356
352
  - spec/masamune/transform/define_table.fact_spec.rb
@@ -438,7 +434,6 @@ test_files:
438
434
  - spec/masamune/schema/catalog_spec.rb
439
435
  - spec/masamune/schema/column_spec.rb
440
436
  - spec/masamune/schema/dimension_spec.rb
441
- - spec/masamune/schema/event_spec.rb
442
437
  - spec/masamune/schema/fact_spec.rb
443
438
  - spec/masamune/schema/map_spec.rb
444
439
  - spec/masamune/schema/row_spec.rb
@@ -454,7 +449,6 @@ test_files:
454
449
  - spec/masamune/transform/bulk_upsert.dimension_spec.rb
455
450
  - spec/masamune/transform/consolidate_dimension_spec.rb
456
451
  - spec/masamune/transform/deduplicate_dimension_spec.rb
457
- - spec/masamune/transform/define_event_view_spec.rb
458
452
  - spec/masamune/transform/define_schema_spec.rb
459
453
  - spec/masamune/transform/define_table.dimension_spec.rb
460
454
  - spec/masamune/transform/define_table.fact_spec.rb
@@ -1,121 +0,0 @@
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::Schema
24
- class Event
25
- class Attribute
26
- attr_accessor :id
27
- attr_accessor :type
28
- attr_accessor :array
29
- attr_accessor :immutable
30
-
31
- def initialize(opts = {})
32
- opts.symbolize_keys!
33
- raise ArgumentError, 'required parameter id: missing' unless opts.key?(:id)
34
- self.id = opts[:id].to_sym
35
- self.type = opts.fetch(:type, :integer).to_sym
36
- self.array = opts.fetch(:array, false)
37
- self.immutable = opts.fetch(:immutable, false)
38
- end
39
-
40
- def as_columns(event, &block)
41
- column_ids = immutable ? [id] : [:"#{id}_now", :"#{id}_was"]
42
- column_ids.each do |id|
43
- yield [id, Column.new(id: id, type: type, array: array, parent: event)]
44
- end
45
- end
46
- end
47
-
48
- DEFAULT_ATTRIBUTES =
49
- {
50
- id: nil,
51
- store: nil,
52
- attributes: [],
53
- debug: false
54
- }
55
-
56
- DEFAULT_ATTRIBUTES.keys.each do |attr|
57
- attr_accessor attr
58
- end
59
-
60
- def initialize(opts = {})
61
- opts.symbolize_keys!
62
- raise ArgumentError, 'required parameter id: missing' unless opts.key?(:id)
63
- DEFAULT_ATTRIBUTES.merge(opts).each do |name, value|
64
- public_send("#{name}=", value)
65
- end
66
- end
67
-
68
- def name
69
- @name || [id, suffix].compact.join('_')
70
- end
71
-
72
- def suffix
73
- 'event'
74
- end
75
-
76
- def attributes=(attributes)
77
- @attributes = {}
78
- attributes.each do |attribute|
79
- @attributes[attribute.id] = attribute
80
- end
81
- end
82
-
83
- def columns
84
- @columns ||= {}.tap do |columns|
85
- columns[:uuid] = Column.new id: :uuid, type: :uuid, parent: self
86
- columns[:type] = Column.new id: :type, type: :string, parent: self
87
- attributes.map do |_, attribute|
88
- attribute.as_columns(self) do |id, column|
89
- columns[id] = column
90
- end
91
- end
92
- columns[:delta] = Column.new id: :delta, type: :integer, parent: self
93
- columns[:created_at] = Column.new id: :created_at, type: :timestamp, parent: self
94
- end
95
- end
96
-
97
- def reserved_column_ids
98
- @reserved_column_ids ||= [:uuid, :type, :delta, :created_at]
99
- end
100
-
101
- def unreserved_columns
102
- columns.reject { |_, column| reserved_column_ids.include?(column.id) }
103
- end
104
-
105
- def create_type
106
- @create_type ||= "#{id}_create"
107
- end
108
-
109
- def update_type
110
- @update_type ||= "#{id}_update"
111
- end
112
-
113
- def delete_type
114
- @delete_type ||= "#{id}_delete"
115
- end
116
-
117
- def dereference_column_name(name)
118
- columns[name.to_sym]
119
- end
120
- end
121
- end
@@ -1,60 +0,0 @@
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 DefineEventView
25
- extend ActiveSupport::Concern
26
-
27
- def define_event_view(target)
28
- Operator.new(__method__, target: target, presenters: { hive: Hive }).tap do |operator|
29
- logger.debug("#{target.id}\n" + operator.to_s) if target.debug
30
- end
31
- end
32
-
33
- private
34
-
35
- class Hive < SimpleDelegator
36
- def view_name
37
- "#{id}_events"
38
- end
39
-
40
- def view_columns
41
- unreserved_columns.map do |_, column|
42
- column.name
43
- end
44
- end
45
-
46
- def view_values
47
- unreserved_columns.map do |_, column|
48
- case column.type
49
- when :json
50
- # NOTE could just use split "\t" to parse tsv output
51
- %Q{CONCAT('"', REGEXP_REPLACE(#{column.name}, '"', '""'), '"') AS #{column.name}}
52
- else
53
- column.name
54
- end
55
- end
56
- end
57
-
58
- end
59
- end
60
- end
@@ -1,75 +0,0 @@
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 'spec_helper'
24
-
25
- describe Masamune::Schema::Event do
26
- context 'without id' do
27
- subject(:event) { described_class.new }
28
- it { expect { event }.to raise_error ArgumentError }
29
- end
30
-
31
- context 'with attributes' do
32
- let(:event) do
33
- described_class.new id: 'user',
34
- attributes: [
35
- Masamune::Schema::Event::Attribute.new(id: 'tenant_id', type: :integer),
36
- Masamune::Schema::Event::Attribute.new(id: 'user_id', type: :integer)
37
- ]
38
- end
39
-
40
- it { expect(event.attributes).to include :tenant_id }
41
- it { expect(event.attributes).to include :user_id }
42
- it { expect(event.attributes[:tenant_id].type).to eq(:integer) }
43
- it { expect(event.attributes[:user_id].type).to eq(:integer) }
44
- end
45
-
46
- context 'with array attributes' do
47
- let(:event) do
48
- described_class.new id: 'user',
49
- attributes: [
50
- Masamune::Schema::Event::Attribute.new(id: 'group_id', type: :integer, array: true),
51
- ]
52
- end
53
-
54
- it { expect(event.attributes).to include :group_id }
55
- it { expect(event.attributes[:group_id].type).to eq(:integer) }
56
- it { expect(event.attributes[:group_id].array).to be(true) }
57
- end
58
-
59
-
60
- describe Masamune::Schema::Event::Attribute do
61
- context 'without id' do
62
- subject(:attribute) { described_class.new }
63
- it { expect { attribute }.to raise_error ArgumentError }
64
- end
65
-
66
- subject(:attribute) { described_class.new id: 'id' }
67
-
68
- it do
69
- expect(attribute.id).to eq(:id)
70
- expect(attribute.type).to eq(:integer)
71
- expect(attribute.immutable).to eq(false)
72
- expect(attribute.array).to eq(false)
73
- end
74
- end
75
- end
@@ -1,84 +0,0 @@
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 'spec_helper'
24
-
25
- describe Masamune::Transform::DefineEventView do
26
- before do
27
- catalog.schema :hive do
28
- event 'tenant' do
29
- attribute 'tenant_id', type: :integer, immutable: true
30
- attribute 'account_state', type: :string
31
- attribute 'premium_type', type: :string
32
- attribute 'preferences', type: :json
33
- end
34
- end
35
- end
36
-
37
- let(:target) { catalog.hive.tenant_event }
38
-
39
- context 'with hive event' do
40
- subject(:result) { transform.define_event_view(target).to_s }
41
-
42
- it 'should render define_event_view template' do
43
- is_expected.to eq <<-EOS.strip_heredoc
44
- DROP VIEW IF EXISTS tenant_events;
45
- CREATE VIEW IF NOT EXISTS tenant_events (
46
- uuid,
47
- type,
48
- tenant_id,
49
- account_state_now,
50
- account_state_was,
51
- premium_type_now,
52
- premium_type_was,
53
- preferences_now,
54
- preferences_was,
55
- delta,
56
- created_at,
57
- y, m, d ,h
58
- ) PARTITIONED ON (y, m, d, h) AS
59
- SELECT DISTINCT
60
- uuid,
61
- type,
62
- tenant_id,
63
- account_state_now,
64
- account_state_was,
65
- premium_type_now,
66
- premium_type_was,
67
- CONCAT('"', REGEXP_REPLACE(preferences_now, '"', '""'), '"') AS preferences_now,
68
- CONCAT('"', REGEXP_REPLACE(preferences_was, '"', '""'), '"') AS preferences_was,
69
- IF(type = 'tenant_update', 1, 0) AS delta,
70
- ctime_iso8601 AS created_at,
71
- y, m, d ,h
72
- FROM
73
- events
74
- LATERAL VIEW
75
- json_tuple(events.json, 'tenant_id', 'account_state_now', 'account_state_was', 'premium_type_now', 'premium_type_was', 'preferences_now', 'preferences_was') event_data AS tenant_id, account_state_now, account_state_was, premium_type_now, premium_type_was, preferences_now, preferences_was
76
- WHERE
77
- type = 'tenant_create' OR
78
- type = 'tenant_update' OR
79
- type = 'tenant_delete'
80
- ;
81
- EOS
82
- end
83
- end
84
- end