Class: Chicago::Schema::QueryColumn Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/chicago/schema/query_column.rb

Overview

This class is abstract.

Decorates/adapts Columns so they can be used in SQL statements and in a User Interface.

Generate with the column method:

QueryColumn.column(owner, column, "some.alias")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column, table_label = nil) ⇒ QueryColumn

Returns a new instance of QueryColumn.



17
18
19
20
# File 'lib/chicago/schema/query_column.rb', line 17

def initialize(column, table_label=nil)
  @column = column
  @table_label = table_label
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



23
24
25
# File 'lib/chicago/schema/query_column.rb', line 23

def method_missing(*args, &block)
  @column.send(*args, &block)
end

Class Method Details

.column(owner, column, column_alias, table_label) ⇒ Object

Factory method that returns a query column.

Parameters:

  • owner

    the column owner, normally a fact or dimension

  • column

    the wrapped column

  • column_alias

    the reference to this column as used by the column parser.

  • table_label

    a table name to distinguish this column from and identically named one. May be nil.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chicago/schema/query_column.rb', line 44

def self.column(owner, column, column_alias, table_label)
  if column.kind_of?(Chicago::Schema::Dimension)
    DimensionAsColumn.new(owner, column, column_alias)
  elsif owner.kind_of?(Chicago::Schema::Dimension) && owner.identifiable? && owner.identifiers.include?(column.name)
    DimensionIdentifierColumn.new(owner, column, column_alias)
  elsif column.calculated?
    VirtualColumn.new(owner, column, column_alias, table_label)
  else
    QualifiedColumn.new(owner, column, column_alias, table_label)
  end
end

Instance Method Details

#filter_dataset(ds, filter) ⇒ Object



56
57
58
# File 'lib/chicago/schema/query_column.rb', line 56

def filter_dataset(ds, filter)
  ds.filter(filter)
end

#qualified_labelObject

Returns the label for this column.

The label is qualified by the table name if neccessary (i.e. if the column comes from a dimension which features multiple times in the same fact table).



32
33
34
# File 'lib/chicago/schema/query_column.rb', line 32

def qualified_label
  @table_label ? "#{label} (#{@table_label})" : label
end