Class: Chicago::ETL::SchemaTableSinkFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/chicago/etl/schema_table_sink_factory.rb

Overview

Builds Sinks for Dimension & Fact tables.

Instance Method Summary collapse

Constructor Details

#initialize(db, schema_table) ⇒ SchemaTableSinkFactory

Creates a new factory.



6
7
8
# File 'lib/chicago/etl/schema_table_sink_factory.rb', line 6

def initialize(db, schema_table)
  @db, @schema_table = db, schema_table
end

Instance Method Details

#error_sink(options = {}) ⇒ Object

Returns a sink to load errors generated in the ETL process.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chicago/etl/schema_table_sink_factory.rb', line 41

def error_sink(options={})
  sink = MysqlFileSink.
    new(@db, :etl_error_log, 
        [:column, :row_id, :error, :severity, :error_detail], mysql_options(options)).
    set_constant_values(:table => @schema_table.table_name.to_s,
                        :process_name => "StandardTransformations",
                        :process_version => 3,
                        :logged_at => Time.now)

  sink.truncation_strategy = lambda do
    @db[:etl_error_log].
      where(:table => @schema_table.table_name.to_s).delete
  end
  sink
end

#key_sink(options = {}) ⇒ Object

Returns a sink to load data into the MySQL table backing the key table for a Dimension.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :table (Symbol)
    • a custom key table name. The

    schema table’s key table name will be used otherwise.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chicago/etl/schema_table_sink_factory.rb', line 27

def key_sink(options={})
  table = options.delete(:table) || @schema_table.key_table_name
  sink = MysqlFileSink.new(@db,
                           table,
                           [:original_id, :dimension_id],
                           mysql_options(options))
  sink.truncation_strategy = lambda do
    # No Op - we want to maintain keys to avoid having to sort
    # out fact tables.
  end
  sink
end

#sink(options = {}) ⇒ Object

Returns a sink to load data into the MySQL table backing the schema table.

Pass an :exclude option if you don’t want all columns of the schema table to be loaded via this sink.



15
16
17
18
19
20
# File 'lib/chicago/etl/schema_table_sink_factory.rb', line 15

def sink(options={})
  MysqlFileSink.new(@db,
                    @schema_table.table_name,
                    load_columns(options[:exclude]),
                    mysql_options(options))
end