Class: RedshiftConnector::Importer::RebuildTruncate
- Inherits:
-
Object
- Object
- RedshiftConnector::Importer::RebuildTruncate
- Defined in:
- lib/redshift_connector/importer/rebuild_truncate.rb
Instance Method Summary collapse
- #execute(bundle) ⇒ Object
- #import(bundle) ⇒ Object
-
#initialize(dao:, columns:, logger: RedshiftConnector.logger) ⇒ RebuildTruncate
constructor
A new instance of RebuildTruncate.
- #truncate_table(table_name) ⇒ Object
Constructor Details
#initialize(dao:, columns:, logger: RedshiftConnector.logger) ⇒ RebuildTruncate
Returns a new instance of RebuildTruncate.
6 7 8 9 10 |
# File 'lib/redshift_connector/importer/rebuild_truncate.rb', line 6 def initialize(dao:, columns:, logger: RedshiftConnector.logger) @dao = dao @columns = columns @logger = logger end |
Instance Method Details
#execute(bundle) ⇒ Object
12 13 14 15 |
# File 'lib/redshift_connector/importer/rebuild_truncate.rb', line 12 def execute(bundle) truncate_table(@dao.table_name) import(bundle) end |
#import(bundle) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/redshift_connector/importer/rebuild_truncate.rb', line 23 def import(bundle) @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
17 18 19 20 21 |
# File 'lib/redshift_connector/importer/rebuild_truncate.rb', line 17 def truncate_table(table_name) @logger.info "TRUNCATE #{table_name}" @dao.connection.execute("truncate #{table_name}") @logger.info "truncated." end |