Class: Masamune::Transform::Postgres::DeduplicateDimension::TargetPresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Masamune::Transform::Postgres::DeduplicateDimension::TargetPresenter
- Defined in:
- lib/masamune/transform/postgres/deduplicate_dimension.rb
Instance Method Summary collapse
- #duplicate_value_conditions(window) ⇒ Object
- #insert_columns(_source = nil) ⇒ Object
- #insert_view_last_values(window) ⇒ Object
- #insert_view_values ⇒ Object
- #start_at_with_grain ⇒ Object
- #window(*extra) ⇒ Object
Instance Method Details
#duplicate_value_conditions(window) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/masamune/transform/postgres/deduplicate_dimension.rb', line 59 def duplicate_value_conditions(window) [].tap do |result| consolidated_columns.map do |_, column| result << if column.null "((LAG(#{column.name}) OVER #{window} = #{column.name}) OR (LAG(#{column.name}) OVER #{window} IS NULL AND #{column.name} IS NULL))" else "(LAG(#{column.name}) OVER #{window} = #{column.name})" end end end end |
#insert_columns(_source = nil) ⇒ Object
39 40 41 |
# File 'lib/masamune/transform/postgres/deduplicate_dimension.rb', line 39 def insert_columns(_source = nil) consolidated_columns.map { |_, column| column.name } end |
#insert_view_last_values(window) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/masamune/transform/postgres/deduplicate_dimension.rb', line 49 def insert_view_last_values(window) consolidated_columns.map do |_, column| if column.default.nil? "LAST_VALUE(#{column.name}) OVER #{window} AS #{column.name}" else "COALESCE(LAST_VALUE(#{column.name}) OVER #{window}, #{column.sql_value(column.default)}) AS #{column.name}" end end end |
#insert_view_values ⇒ Object
43 44 45 46 47 |
# File 'lib/masamune/transform/postgres/deduplicate_dimension.rb', line 43 def insert_view_values consolidated_columns.map do |_, column| column.name end end |
#start_at_with_grain ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/masamune/transform/postgres/deduplicate_dimension.rb', line 76 def start_at_with_grain case grain when :hourly "date_trunc('hour', start_at)" when :daily "date_trunc('day', start_at)" when :monthly "date_trunc('month', start_at)" end end |
#window(*extra) ⇒ Object
72 73 74 |
# File 'lib/masamune/transform/postgres/deduplicate_dimension.rb', line 72 def window(*extra) (columns.values.select { |column| extra.delete(column.name) || column.natural_key || column.auto_reference }.map(&:name) + extra).uniq end |