Class: Chicago::Schema::Fact
Overview
A fact table in the star schema.
Facts contain keys to dimension tables, ad-hoc fields used for filtering and grouping (termed degenerate dimensions), and measures, which are values to be summed, averaged etc.
You shouldn’t need to initialize a Fact yourself - they should be created via StarSchema#define_fact.
Instance Attribute Summary collapse
-
#degenerate_dimensions ⇒ Object
readonly
The degenerate dimensions associated with this fact.
-
#dimensions ⇒ Object
readonly
The Dimensions associated with this fact.
-
#measures ⇒ Object
readonly
The measures associated with this fact.
Attributes inherited from Table
#description, #natural_key, #table_name
Attributes included from NamedElement
Instance Method Summary collapse
-
#columns ⇒ Object
Returns an Array of all dimensions, degenerate_dimensions and measures for this fact table.
-
#factless? ⇒ Boolean
A Factless Fact table has no measures - it used only to express a relationship between a set of dimensions.
-
#initialize(name, opts = {}) ⇒ Fact
constructor
Creates a new fact.
-
#visit(visitor) ⇒ Object
Facts accept Visitors.
Methods inherited from Table
Constructor Details
#initialize(name, opts = {}) ⇒ Fact
Creates a new fact.
44 45 46 47 48 49 50 |
# File 'lib/chicago/schema/fact.rb', line 44 def initialize(name, opts={}) super @dimensions = opts[:dimensions] || [] @degenerate_dimensions = opts[:degenerate_dimensions] || [] @measures = opts[:measures] || [] @table_name = :"facts_#{@name}" end |
Instance Attribute Details
#degenerate_dimensions ⇒ Object (readonly)
The degenerate dimensions associated with this fact.
Degenerate dimensions are typically ids / numbers from a source system that have no associated information, for example: an order number. They are used for filtering and grouping facts.
27 28 29 |
# File 'lib/chicago/schema/fact.rb', line 27 def degenerate_dimensions @degenerate_dimensions end |
#dimensions ⇒ Object (readonly)
The Dimensions associated with this fact.
See Dimension.
19 20 21 |
# File 'lib/chicago/schema/fact.rb', line 19 def dimensions @dimensions end |
#measures ⇒ Object (readonly)
The measures associated with this fact.
Measures are usually numeric values that will be aggregated, for example the amount of a sale.
33 34 35 |
# File 'lib/chicago/schema/fact.rb', line 33 def measures @measures end |
Instance Method Details
#columns ⇒ Object
Returns an Array of all dimensions, degenerate_dimensions and measures for this fact table.
54 55 56 |
# File 'lib/chicago/schema/fact.rb', line 54 def columns @dimensions + @degenerate_dimensions + @measures end |
#factless? ⇒ Boolean
A Factless Fact table has no measures - it used only to express a relationship between a set of dimensions.
60 61 62 |
# File 'lib/chicago/schema/fact.rb', line 60 def factless? @measures.empty? end |
#visit(visitor) ⇒ Object
Facts accept Visitors
65 66 67 |
# File 'lib/chicago/schema/fact.rb', line 65 def visit(visitor) visitor.visit_fact(self) end |