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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/lib/masamune.rb +8 -5
  3. data/lib/masamune/actions.rb +1 -13
  4. data/lib/masamune/actions/data_flow.rb +2 -1
  5. data/lib/masamune/actions/date_parse.rb +0 -1
  6. data/lib/masamune/actions/elastic_mapreduce.rb +0 -2
  7. data/lib/masamune/actions/filesystem.rb +0 -2
  8. data/lib/masamune/actions/hive.rb +0 -2
  9. data/lib/masamune/actions/invoke_parallel.rb +2 -1
  10. data/lib/masamune/actions/postgres.rb +0 -1
  11. data/lib/masamune/actions/s3cmd.rb +2 -0
  12. data/lib/masamune/actions/transform.rb +0 -2
  13. data/lib/masamune/after_initialize_callbacks.rb +0 -2
  14. data/lib/masamune/commands.rb +1 -11
  15. data/lib/masamune/commands/postgres.rb +1 -0
  16. data/lib/masamune/commands/postgres_admin.rb +2 -0
  17. data/lib/masamune/configuration.rb +2 -0
  18. data/lib/masamune/data_plan/engine.rb +2 -0
  19. data/lib/masamune/filesystem.rb +2 -0
  20. data/lib/masamune/helpers.rb +1 -1
  21. data/lib/masamune/last_element.rb +0 -2
  22. data/lib/masamune/schema/dimension.rb +1 -3
  23. data/lib/masamune/schema/store.rb +2 -0
  24. data/lib/masamune/schema/table.rb +2 -0
  25. data/lib/masamune/template.rb +4 -1
  26. data/lib/masamune/thor.rb +1 -1
  27. data/lib/masamune/transform.rb +1 -21
  28. data/lib/masamune/transform/bulk_upsert.rb +1 -22
  29. data/lib/masamune/transform/common.rb +27 -0
  30. data/lib/masamune/transform/common/denormalize_table.rb +90 -0
  31. data/lib/masamune/transform/deduplicate_dimension.rb +1 -41
  32. data/lib/masamune/transform/define_table.rb +1 -113
  33. data/lib/masamune/transform/denormalize_table.rb +1 -50
  34. data/lib/masamune/transform/hive.rb +27 -0
  35. data/lib/masamune/transform/{define_schema.hql.erb → hive/define_schema.hql.erb} +0 -0
  36. data/lib/masamune/transform/{define_table.hql.erb → hive/define_table.hql.erb} +0 -0
  37. data/lib/masamune/transform/hive/define_table.rb +46 -0
  38. data/lib/masamune/transform/{denormalize_table.hql.erb → hive/denormalize_table.hql.erb} +0 -0
  39. data/lib/masamune/transform/hive/denormalize_table.rb +27 -0
  40. data/lib/masamune/transform/insert_reference_values.rb +1 -30
  41. data/lib/masamune/transform/operator.rb +36 -37
  42. data/lib/masamune/transform/postgres.rb +27 -0
  43. data/lib/masamune/transform/{bulk_upsert.psql.erb → postgres/bulk_upsert.psql.erb} +0 -0
  44. data/lib/masamune/transform/postgres/bulk_upsert.rb +62 -0
  45. data/lib/masamune/transform/{deduplicate_dimension.psql.erb → postgres/deduplicate_dimension.psql.erb} +1 -7
  46. data/lib/masamune/transform/postgres/deduplicate_dimension.rb +79 -0
  47. data/lib/masamune/transform/{define_foreign_key.psql.erb → postgres/define_foreign_key.psql.erb} +0 -0
  48. data/lib/masamune/transform/{define_index.psql.erb → postgres/define_index.psql.erb} +0 -0
  49. data/lib/masamune/transform/{define_inheritance.psql.erb → postgres/define_inheritance.psql.erb} +0 -0
  50. data/lib/masamune/transform/{define_schema.psql.erb → postgres/define_schema.psql.erb} +0 -0
  51. data/lib/masamune/transform/{define_table.psql.erb → postgres/define_table.psql.erb} +0 -0
  52. data/lib/masamune/transform/postgres/define_table.rb +142 -0
  53. data/lib/masamune/transform/{define_unique.psql.erb → postgres/define_unique.psql.erb} +0 -0
  54. data/lib/masamune/transform/{denormalize_table.psql.erb → postgres/denormalize_table.psql.erb} +0 -0
  55. data/lib/masamune/transform/postgres/denormalize_table.rb +27 -0
  56. data/lib/masamune/transform/{insert_reference_values.psql.erb → postgres/insert_reference_values.psql.erb} +1 -1
  57. data/lib/masamune/transform/postgres/insert_reference_values.rb +69 -0
  58. data/lib/masamune/transform/{relabel_dimension.psql.erb → postgres/relabel_dimension.psql.erb} +4 -1
  59. data/lib/masamune/transform/postgres/relabel_dimension.rb +45 -0
  60. data/lib/masamune/transform/{replace_table.psql.erb → postgres/replace_table.psql.erb} +0 -0
  61. data/lib/masamune/transform/{rollup_fact.psql.erb → postgres/rollup_fact.psql.erb} +0 -0
  62. data/lib/masamune/transform/postgres/rollup_fact.rb +123 -0
  63. data/lib/masamune/transform/{snapshot_dimension.psql.erb → postgres/snapshot_dimension.psql.erb} +3 -10
  64. data/lib/masamune/transform/postgres/snapshot_dimension.rb +83 -0
  65. data/lib/masamune/transform/{stage_dimension.psql.erb → postgres/stage_dimension.psql.erb} +0 -0
  66. data/lib/masamune/transform/postgres/stage_dimension.rb +90 -0
  67. data/lib/masamune/transform/{stage_fact.psql.erb → postgres/stage_fact.psql.erb} +0 -0
  68. data/lib/masamune/transform/postgres/stage_fact.rb +134 -0
  69. data/lib/masamune/transform/relabel_dimension.rb +1 -9
  70. data/lib/masamune/transform/rollup_fact.rb +1 -86
  71. data/lib/masamune/transform/snapshot_dimension.rb +1 -44
  72. data/lib/masamune/transform/stage_dimension.rb +1 -53
  73. data/lib/masamune/transform/stage_fact.rb +1 -96
  74. data/lib/masamune/version.rb +1 -1
  75. data/spec/masamune/template_spec.rb +1 -1
  76. data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +1 -3
  77. data/spec/masamune/transform/deduplicate_dimension_spec.rb +1 -7
  78. data/spec/masamune/transform/define_table.dimension_spec.rb +0 -14
  79. data/spec/masamune/transform/denormalize_table_spec.rb +34 -0
  80. data/spec/masamune/transform/relabel_dimension_spec.rb +6 -1
  81. data/spec/masamune/transform/snapshot_dimension_spec.rb +3 -10
  82. metadata +37 -21
@@ -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 Postgres
25
+ Dir["#{File.dirname(__FILE__)}/postgres/*.rb"].each { |f| require f }
26
+ end
27
+ end
@@ -0,0 +1,62 @@
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::Postgres
26
+ class BulkUpsert
27
+ def initialize(options = {})
28
+ @target = options[:target]
29
+ @source = options[:source]
30
+ end
31
+
32
+ def locals
33
+ { target: target, source: @source }
34
+ end
35
+
36
+ def target
37
+ TargetPresenter.new(@target)
38
+ end
39
+
40
+ private
41
+
42
+ class TargetPresenter < SimpleDelegator
43
+ include Masamune::LastElement
44
+
45
+ def update_columns
46
+ columns.values.reject { |column| reserved_column_ids.include?(column.id) || column.surrogate_key || column.natural_key || column.unique.any? || column.auto_reference || column.ignore }
47
+ end
48
+ method_with_last_element :update_columns
49
+
50
+ def insert_columns
51
+ columns.values.reject { |column| column.surrogate_key || column.auto_reference || column.ignore }
52
+ end
53
+ method_with_last_element :insert_columns
54
+
55
+ def unique_columns
56
+ columns.values.select { |column| column.unique.any? && !column.null }
57
+ end
58
+ method_with_last_element :unique_columns
59
+ end
60
+ end
61
+ end
62
+
@@ -25,28 +25,22 @@ WITH consolidated AS (
25
25
  <%- target.insert_view_values(coalesce: true).each do |value| -%>
26
26
  <%= value %><%= ',' %>
27
27
  <%- end -%>
28
- parent_id,
29
- record_id,
30
28
  start_at
31
29
  FROM
32
30
  <%= source.name %>
33
31
  )
34
32
  INSERT INTO
35
- <%= target.name %> (<%= target.insert_columns.join(', ') %>, parent_id, record_id, start_at)
33
+ <%= target.name %> (<%= target.insert_columns.join(', ') %>, start_at)
36
34
  SELECT DISTINCT
37
35
  <%- target.insert_view_values.each do |value| -%>
38
36
  <%= value %><%= ',' %>
39
37
  <%- end -%>
40
- parent_id,
41
- record_id,
42
38
  start_at
43
39
  FROM (
44
40
  SELECT
45
41
  <%- target.insert_view_values.each do |value| -%>
46
42
  <%= value %><%= ',' %>
47
43
  <%- end -%>
48
- parent_id,
49
- record_id,
50
44
  start_at,
51
45
  CASE
52
46
  WHEN <%= target.duplicate_value_conditions('w').join(' AND ') %> THEN
@@ -0,0 +1,79 @@
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::Postgres
24
+ class DeduplicateDimension
25
+ def initialize(options = {})
26
+ @target = options[:target]
27
+ @source = options[:source]
28
+ end
29
+
30
+ def locals
31
+ { target: target, source: @source }
32
+ end
33
+
34
+ def target
35
+ TargetPresenter.new(@target)
36
+ end
37
+
38
+ private
39
+
40
+ class TargetPresenter < SimpleDelegator
41
+ def insert_columns(source = nil)
42
+ consolidated_columns.map { |_, column| column.name }
43
+ end
44
+
45
+ def insert_view_values(coalesce: false)
46
+ consolidated_columns.map do |_, column|
47
+ if !column.default.nil? && coalesce
48
+ "COALESCE(#{column.name}, #{column.sql_value(column.default)}) AS #{column.name}"
49
+ else
50
+ column.name
51
+ end
52
+ end
53
+ end
54
+
55
+ def duplicate_value_conditions(window)
56
+ [].tap do |result|
57
+ consolidated_columns.map do |_, column|
58
+ if column.null
59
+ result << "((LAG(#{column.name}) OVER #{window} = #{column.name}) OR (LAG(#{column.name}) OVER #{window} IS NULL AND #{column.name} IS NULL))"
60
+ else
61
+ result << "(LAG(#{column.name}) OVER #{window} = #{column.name})"
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def window(*extra)
68
+ (columns.values.select { |column| extra.delete(column.name) || column.natural_key || column.auto_reference }.map(&:name) + extra).uniq
69
+ end
70
+
71
+ private
72
+
73
+ def consolidated_columns
74
+ unreserved_columns.reject { |_, column| column.surrogate_key }
75
+ end
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,142 @@
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::Postgres
24
+ class DefineTable
25
+ def initialize(options = {})
26
+ @target = options[:target]
27
+ @files = options[:files] || []
28
+ @section = options[:section]
29
+ end
30
+
31
+ def locals
32
+ { target: target, files: files, helper: self }
33
+ end
34
+
35
+ def target
36
+ TargetPresenter.new(@target)
37
+ end
38
+
39
+ def files
40
+ Masamune::Schema::Map.convert_files(@files)
41
+ end
42
+
43
+ def section
44
+ @section || :all
45
+ end
46
+
47
+ def define_types?
48
+ !post_section?
49
+ end
50
+
51
+ def define_tables?
52
+ !post_section?
53
+ end
54
+
55
+ def define_functions?
56
+ !post_section?
57
+ end
58
+
59
+ def define_sequences?
60
+ !post_section?
61
+ end
62
+
63
+ def define_primary_keys?
64
+ !pre_section? && !(target.temporary? || target.primary_keys.empty?)
65
+ end
66
+
67
+ def define_inheritance?
68
+ return false unless target.inherited?
69
+ return false if pre_section?
70
+ return true if post_section?
71
+ !target.delay_indexes?
72
+ end
73
+
74
+ def define_indexes?
75
+ return false if pre_section?
76
+ return true if post_section?
77
+ !target.delay_indexes?
78
+ end
79
+
80
+ def define_foreign_keys?
81
+ return false if pre_section?
82
+ return true if post_section?
83
+ !target.delay_foreign_keys?
84
+ end
85
+
86
+ def define_unique_constraints?
87
+ return false if pre_section?
88
+ return true if post_section?
89
+ !target.delay_unique_constraints?
90
+ end
91
+
92
+ def insert_rows?
93
+ !post_section?
94
+ end
95
+
96
+ def load_files?
97
+ all_section?
98
+ end
99
+
100
+ def perform_analyze?
101
+ return false if pre_section?
102
+ return true if post_section?
103
+ files.any? || target.insert_rows.any?
104
+ end
105
+
106
+ private
107
+
108
+ def all_section?
109
+ section == :all
110
+ end
111
+
112
+ def pre_section?
113
+ section == :pre
114
+ end
115
+
116
+ def post_section?
117
+ section == :post
118
+ end
119
+
120
+ class TargetPresenter < SimpleDelegator
121
+ def children
122
+ super.map { |child| self.class.new(child) }
123
+ end
124
+
125
+ def inherited?
126
+ type == :fact && inheritance_constraints
127
+ end
128
+
129
+ def delay_indexes?
130
+ type == :fact
131
+ end
132
+
133
+ def delay_foreign_keys?
134
+ type == :fact
135
+ end
136
+
137
+ def delay_unique_constraints?
138
+ type == :fact
139
+ end
140
+ end
141
+ end
142
+ 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
+ require 'masamune/transform/common/denormalize_table'
24
+
25
+ module Masamune::Transform::Postgres
26
+ DenormalizeTable = Masamune::Transform::Common::DenormalizeTable
27
+ end
@@ -41,5 +41,5 @@ WHERE
41
41
 
42
42
  ANALYZE <%= target.stage_table.name %>;
43
43
 
44
- <%= target.bulk_upsert(target.stage_table, target) %>
44
+ <%= helper.bulk_upsert(target.stage_table, target) %>
45
45
  <%- end -%>
@@ -0,0 +1,69 @@
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/transform/bulk_upsert'
24
+
25
+ module Masamune::Transform::Postgres
26
+ class InsertReferenceValues
27
+ include Masamune::Transform::BulkUpsert
28
+
29
+ def initialize(options = {})
30
+ @target = options[:target]
31
+ @source = options[:source]
32
+ end
33
+
34
+ def locals
35
+ { target: target, source: @source, helper: self }
36
+ end
37
+
38
+ def target
39
+ TargetPresenter.new(@target)
40
+ end
41
+
42
+ private
43
+
44
+ class TargetPresenter < SimpleDelegator
45
+ include Masamune::LastElement
46
+
47
+ def insert_columns(source)
48
+ source.shared_columns(stage_table).map { |_, columns| columns.first.name }
49
+ end
50
+
51
+ def insert_values(source)
52
+ source.shared_columns(stage_table).map do |column, _|
53
+ if column.adjacent.try(:default)
54
+ "COALESCE(#{column.name}, #{column.adjacent.sql_value(column.adjacent.default)})"
55
+ else
56
+ column.name
57
+ end
58
+ end
59
+ end
60
+ method_with_last_element :insert_values
61
+
62
+ def insert_constraints(source)
63
+ source.shared_columns(stage_table).reject { |column, _| column.null || column.default || column.adjacent.try(:default) }.map { |column, _| "#{column.name} IS NOT NULL"}
64
+ end
65
+ method_with_last_element :insert_constraints
66
+ end
67
+ end
68
+ end
69
+