Class: RedshiftConnector::Importer::RebuildRename
- Inherits:
-
Object
- Object
- RedshiftConnector::Importer::RebuildRename
- Defined in:
- lib/redshift-connector/importer/rebuild_rename.rb
Instance Method Summary collapse
- #exec_update(query) ⇒ Object
- #execute ⇒ Object
- #import(dao) ⇒ Object
-
#initialize(dao:, bundle:, columns:, logger: RedshiftConnector.logger) ⇒ RebuildRename
constructor
A new instance of RebuildRename.
Constructor Details
#initialize(dao:, bundle:, columns:, logger: RedshiftConnector.logger) ⇒ RebuildRename
6 7 8 9 10 11 |
# File 'lib/redshift-connector/importer/rebuild_rename.rb', line 6 def initialize(dao:, bundle:, columns:, logger: RedshiftConnector.logger) @dao = dao @bundle = bundle @columns = columns @logger = logger end |
Instance Method Details
#exec_update(query) ⇒ Object
29 30 31 32 |
# File 'lib/redshift-connector/importer/rebuild_rename.rb', line 29 def exec_update(query) @logger.info query @dao.connection.execute(query) end |
#execute ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/redshift-connector/importer/rebuild_rename.rb', line 13 def execute dest_table = @dao.table_name tmp_table = "#{dest_table}_new" old_table = "#{dest_table}_old" tmp_dao = @dao.dup tmp_dao.table_name = tmp_table exec_update "drop table if exists #{tmp_table}" exec_update "create table #{tmp_table} like #{dest_table}" import(tmp_dao) exec_update "drop table if exists #{old_table}" # Atomic table exchange exec_update "rename table #{dest_table} to #{old_table}, #{tmp_table} to #{dest_table}" end |
#import(dao) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/redshift-connector/importer/rebuild_rename.rb', line 34 def import(dao) @logger.info "IMPORT #{@bundle.url}* -> #{dao.table_name} (#{@columns.join(', ')})" @bundle.each_batch do |rows| dao.import(@columns, rows) end end |