Class: Chicago::ETL::FactKeyBuilder

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

Overview

Returns ids for Fact tables.

Fact table surrogate ids are transient - there is no expectation that the same fact row will have the same id between invocations. This is ok, because all facts should have a natural key defined - the id generated by this is purely for convenience and linking to error rows.

As a result fact keys aren’t stored in a key table - they are never referenced by any other tables in the system.

In addition, the same row passed twice will get a different id.

Instance Method Summary collapse

Constructor Details

#initialize(db_table) ⇒ FactKeyBuilder

Returns a new instance of FactKeyBuilder.



195
196
197
198
# File 'lib/chicago/etl/key_builder.rb', line 195

def initialize(db_table)
  @db_table = db_table
  @counter = Counter.new { @db_table.max(:id) }
end

Instance Method Details

#key(row) ⇒ Object

Returns an id given a row - the row actually has no bearing on the id returned.



202
203
204
# File 'lib/chicago/etl/key_builder.rb', line 202

def key(row)
  [@counter.next, nil]
end