Class: Chicago::ETL::SchemaTableSinkFactory
- Inherits:
-
Object
- Object
- Chicago::ETL::SchemaTableSinkFactory
- Defined in:
- lib/chicago/etl/schema_table_sink_factory.rb
Overview
Builds Sinks for Dimension & Fact tables.
Instance Method Summary collapse
-
#error_sink(options = {}) ⇒ Object
Returns a sink to load errors generated in the ETL process.
-
#initialize(db, schema_table) ⇒ SchemaTableSinkFactory
constructor
Creates a new factory.
-
#key_sink(options = {}) ⇒ Object
Returns a sink to load data into the MySQL table backing the key table for a Dimension.
-
#sink(options = {}) ⇒ Object
Returns a sink to load data into the MySQL table backing the schema table.
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(={}) sink = MysqlFileSink. new(@db, :etl_error_log, [:column, :row_id, :error, :severity, :error_detail], ()). 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.
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(={}) table = .delete(:table) || @schema_table.key_table_name sink = MysqlFileSink.new(@db, table, [:original_id, :dimension_id], ()) 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(={}) MysqlFileSink.new(@db, @schema_table.table_name, load_columns([:exclude]), ()) end |