Class: RedshiftConnector::Importer::Upsert

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift_connector/importer/upsert.rb

Instance Method Summary collapse

Constructor Details

#initialize(dao:, columns:, upsert_columns:, logger: RedshiftConnector.logger) ⇒ Upsert

Returns a new instance of Upsert.



6
7
8
9
10
11
# File 'lib/redshift_connector/importer/upsert.rb', line 6

def initialize(dao:, columns:, upsert_columns:, logger: RedshiftConnector.logger)
  @dao = dao
  @columns = columns
  @upsert_columns = upsert_columns
  @logger = logger
end

Instance Method Details

#execute(bundle) ⇒ Object



13
14
15
# File 'lib/redshift_connector/importer/upsert.rb', line 13

def execute(bundle)
  import(bundle)
end

#import(bundle) ⇒ Object



17
18
19
20
21
22
# File 'lib/redshift_connector/importer/upsert.rb', line 17

def import(bundle)
  @logger.info "IMPORT #{bundle.url}* -> #{@dao.table_name} (#{@columns.join(', ')}) upsert (#{@upsert_columns.join(', ')})"
  bundle.each_batch do |rows|
    @dao.import(@columns, rows, on_duplicate_key_update: @upsert_columns)
  end
end