Class: Outhad::Integrations::Source::WatsonxData::Client

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

Instance Method Summary collapse

Instance Method Details

#check_connection(connection_config) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/outhad/integrations/source/watsonx_data/client.rb', line 8

def check_connection(connection_config)
  create_connection(connection_config)
  response = execute_query(connection_config, "show catalogs")
  success?(response) ? success_status : failure_status(nil)
rescue StandardError => e
  handle_exception(e, { context: "WATSONX DATA:CHECK_CONNECTION:EXCEPTION", type: "error" })
  failure_status(e)
end

#discover(connection_config) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/outhad/integrations/source/watsonx_data/client.rb', line 17

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"
  response = execute_query(connection_config, query)
  records = JSON.parse(response.body)["response"]["result"]
  catalog = Catalog.new(streams: create_streams(records))
  catalog.to_outhad_message
rescue StandardError => e
  handle_exception(e, { context: "WATSONX DATA:DISCOVER:EXCEPTION", type: "error" })
end

#read(sync_config) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/outhad/integrations/source/watsonx_data/client.rb', line 33

def read(sync_config)
  connection_config = sync_config.source.connection_specification
  connection_config = connection_config.with_indifferent_access
  query = sync_config.model.query
  if connection_config[:engine] == "presto"
    query = batched_query_for_presto(query, sync_config.limit, sync_config.offset) unless sync_config.limit.nil? && sync_config.offset.nil?
  else
    query = batched_query(query, sync_config.limit, sync_config.offset) unless sync_config.limit.nil? && sync_config.offset.nil?
  end
  query(connection_config, query)
rescue StandardError => e
  handle_exception(e, { context: "WATSONX DATA:READ:EXCEPTION", type: "error" })
end