Class: RedshiftConnector::Importer::RebuildTruncate

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift-connector/importer/rebuild_truncate.rb

Instance Method Summary collapse

Constructor Details

#initialize(dao:, bundle:, columns:, logger: RedshiftConnector.logger) ⇒ RebuildTruncate



6
7
8
9
10
11
# File 'lib/redshift-connector/importer/rebuild_truncate.rb', line 6

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

Instance Method Details

#executeObject



13
14
15
16
# File 'lib/redshift-connector/importer/rebuild_truncate.rb', line 13

def execute
  truncate_table(@dao.table_name)
  import
end

#importObject



24
25
26
27
28
29
# File 'lib/redshift-connector/importer/rebuild_truncate.rb', line 24

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

#truncate_table(table_name) ⇒ Object



18
19
20
21
22
# File 'lib/redshift-connector/importer/rebuild_truncate.rb', line 18

def truncate_table(table_name)
  @logger.info "TRUNCATE #{table_name}"
  @dao.connection.execute("truncate #{table_name}")
  @logger.info "truncated."
end