Class: Etl::Integrations::Source::Redshift::Client

Inherits:
SourceConnector
  • Object
show all
Defined in:
lib/etl/integrations/source/redshift/client.rb

Instance Method Summary collapse

Instance Method Details

#check_connection(connection_config) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/etl/integrations/source/redshift/client.rb', line 9

def check_connection(connection_config)
  connection_config = connection_config.with_indifferent_access
  create_connection(connection_config)
  ConnectionStatus.new(
    status: ConnectionStatusType["succeeded"]
  ).to_multiwoven_message
rescue PG::Error => e
  ConnectionStatus.new(
    status: ConnectionStatusType["failed"], message: e.message
  ).to_multiwoven_message
end

#discover(connection_config) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/etl/integrations/source/redshift/client.rb', line 21

def discover(connection_config)
  connection_config = connection_config.with_indifferent_access
  query = "SELECT table_name, column_name, data_type, is_nullable
           FROM information_schema.columns
           WHERE table_schema = '#{connection_config[:schema]}' AND table_catalog = '#{connection_config[:database]}'
           ORDER BY table_name, ordinal_position;"

  db = create_connection(connection_config)
  records = db.exec(query) do |result|
    result.map do |row|
      row
    end
  end
  catalog = Catalog.new(streams: create_streams(records))
  catalog.to_multiwoven_message
rescue StandardError => e
  handle_exception(
    "REDSHIFT:DISCOVER:EXCEPTION",
    "error",
    e
  )
ensure
  db&.close
end

#read(sync_config) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/etl/integrations/source/redshift/client.rb', line 46

def read(sync_config)
  connection_config = sync_config.source.connection_specification
  connection_config = connection_config.with_indifferent_access
  query = sync_config.model.query
  query = batched_query(query, sync_config.limit, sync_config.offset) unless sync_config.limit.nil? && sync_config.offset.nil?

  db = create_connection(connection_config)

  query(db, query)
rescue StandardError => e
  handle_exception(
    "REDSHIFT:READ:EXCEPTION",
    "error",
    e
  )
ensure
  db&.close
end