Class: Fluent::RedshiftOutput::RedshiftConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/out_redshift.rb

Constant Summary collapse

REDSHIFT_CONNECT_TIMEOUT =

10sec

10.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_conf) ⇒ RedshiftConnection

Returns a new instance of RedshiftConnection.



282
283
284
285
# File 'lib/fluent/plugin/out_redshift.rb', line 282

def initialize(db_conf)
  @db_conf = db_conf
  @connection = nil
end

Instance Attribute Details

#db_confObject (readonly)

Returns the value of attribute db_conf.



287
288
289
# File 'lib/fluent/plugin/out_redshift.rb', line 287

def db_conf
  @db_conf
end

Instance Method Details

#closeObject



315
316
317
318
# File 'lib/fluent/plugin/out_redshift.rb', line 315

def close
  @connection.close rescue nil if @connection
  @connection = nil
end

#connect_startObject



311
312
313
# File 'lib/fluent/plugin/out_redshift.rb', line 311

def connect_start
  @connection = create_redshift_connection
end

#exec(sql, &block) ⇒ Object



297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/fluent/plugin/out_redshift.rb', line 297

def exec(sql, &block)
  conn = @connection
  conn = create_redshift_connection if conn.nil?
  if block
    conn.exec(sql) {|result| block.call(result)}
  else
    conn.exec(sql)
  end
rescue PG::Error => e
  raise RedshiftError.new(e)
ensure
  conn.close if conn && @connection.nil?
end

#fetch_table_columns(table_name, schema_name) ⇒ Object



289
290
291
292
293
294
295
# File 'lib/fluent/plugin/out_redshift.rb', line 289

def fetch_table_columns(table_name, schema_name)
  columns = nil
  exec(fetch_columns_sql(table_name, schema_name)) do |result|
    columns = result.collect{|row| row['column_name']}
  end
  columns
end