Class: RedshiftConnector::Importer::InsertDelta

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

Instance Method Summary collapse

Constructor Details

#initialize(dao:, columns:, delete_cond:, logger: RedshiftConnector.logger) ⇒ InsertDelta

Returns a new instance of InsertDelta.



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

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

Instance Method Details

#delete_rows(cond_expr) ⇒ Object



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

def delete_rows(cond_expr)
  @logger.info "DELETE #{@dao.table_name} where (#{cond_expr})"
  @dao.connection.execute("delete from #{@dao.table_name} where #{cond_expr}")
  @logger.info "deleted."
end

#execute(bundle) ⇒ Object



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

def execute(bundle)
  delete_rows(@delete_cond)
  import(bundle)
end

#import(bundle) ⇒ Object



24
25
26
27
28
29
# File 'lib/redshift_connector/importer/insert_delta.rb', line 24

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