Module: RedshiftConnector::Importer

Defined in:
lib/redshift_connector/importer.rb,
lib/redshift_connector/importer.rb

Defined Under Namespace

Classes: InsertDelta, RebuildRename, RebuildTruncate, Upsert

Class Method Summary collapse

Class Method Details

.for_delta_upsert(table:, columns:, delete_cond: nil, upsert_columns: nil, logger: RedshiftConnector.logger) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/redshift_connector/importer.rb', line 15

def Importer.for_delta_upsert(table:, columns:, delete_cond: nil, upsert_columns: nil, logger: RedshiftConnector.logger)
  if delete_cond and upsert_columns
    raise ArgumentError, "delete_cond and upsert_columns are exclusive"
  end
  importer =
    if delete_cond
      Importer::InsertDelta.new(
        dao: table.classify.constantize,
        columns: columns,
        delete_cond: delete_cond,
        logger: logger
      )
    elsif upsert_columns
      Importer::Upsert.new(
        dao: table.classify.constantize,
        columns: columns,
        upsert_columns: upsert_columns,
        logger: logger
      )
    else
      raise ArgumentError, "either of delete_cond or upsert_columns is required for delta import"
    end
  importer
end

.for_rebuild(strategy: 'rename', table:, columns:, logger: RedshiftConnector.logger) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/redshift_connector/importer.rb', line 40

def Importer.for_rebuild(strategy: 'rename', table:, columns:, logger: RedshiftConnector.logger)
  c = get_rebuild_class(strategy)
  c.new(
    dao: table.classify.constantize,
    columns: columns,
    logger: logger
  )
end

.get_rebuild_class(strategy) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/redshift_connector/importer.rb', line 49

def Importer.get_rebuild_class(strategy)
  case strategy.to_s
  when 'rename' then RebuildRename
  when 'truncate' then RebuildTruncate
  else
    raise ArgumentError, "unsupported rebuild strategy: #{strategy.inspect}"
  end
end