Class: Charrington::CreateRedshiftTable

Inherits:
Object
  • Object
show all
Includes:
LogStash::Util::Loggable, Service
Defined in:
lib/logstash/outputs/charrington/create_redshift_table.rb

Overview

This service will create a table dynamically based on the JSON structure. This is potentially called from Insert when an insert fails.

Constant Summary collapse

Error =
Class.new(StandardError)
CreateFailed =
Class.new(Error)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Service

included

Constructor Details

#initialize(connection, event, schema, table_name, columns, _opts = {}) ⇒ CreateRedshiftTable

rubocop:disable Metrics/ParameterLists



17
18
19
20
21
22
23
24
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 17

def initialize(connection, event, schema, table_name, columns, _opts = {}) # rubocop:disable Metrics/ParameterLists
  @connection = connection
  @event = event.to_hash
  @schema = schema
  @table_name = table_name
  @columns = columns
  @column_types = initial_columns
end

Instance Attribute Details

#column_typesObject

Returns the value of attribute column_types.



12
13
14
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 12

def column_types
  @column_types
end

#columnsObject (readonly)

Returns the value of attribute columns.



11
12
13
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 11

def columns
  @columns
end

#connectionObject (readonly)

Returns the value of attribute connection.



11
12
13
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 11

def connection
  @connection
end

#eventObject (readonly)

Returns the value of attribute event.



11
12
13
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 11

def event
  @event
end

#optsObject (readonly)

Returns the value of attribute opts.



11
12
13
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 11

def opts
  @opts
end

#schemaObject (readonly)

Returns the value of attribute schema.



11
12
13
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 11

def schema
  @schema
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



11
12
13
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 11

def table_name
  @table_name
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/logstash/outputs/charrington/create_redshift_table.rb', line 26

def call
  set_column_types
  logger.info "Finished running set_column_types and now have column_types for create table of: #{column_types}"
  create_table
  true
rescue StandardError => e
  raise CreateFailed, e.message
ensure
  @column_types.clear if @column_types.is_a? Array
end