lib/active_warehouse/aggregate/pipelined_rolap_aggregate.rb
# build and populate a table which group by's all dimension columns.
# this should include all the columns from the hierarchies in the dimension
# should it have the column id levels? only if in the hierarchy
# if there is no hierarchy specified, see if the hierachy name is a column, use that
# if not, just use the dim's id
# so a product dimension with no hierarchy specified should by just product_id
build and populate a table which group by's all dimension columns.
this should include all the columns from the hierarchies in the dimension
should it have the column id levels. only if in the hierarchy
if there is no hierarchy specified, see if the hierachy name is a column, use that
if not, just use the dim's id
so a product dimension with no hierarchy specified should by just product_id
build and populate a table which group by ' s all dimension columns . this should include all the columns from the hierarchies in the dimension should it have the column id levels . only if in the hierarchy if there is no hierarchy specified see if the hierachy name is a column use that if not just use the dim ' s id so a product dimension with no hierarchy specified should by just product_id
def create_aggregate_table(base_name, dimension_fields, current_levels, options)
        table_name = aggregate_rollup_name(base_name, current_levels)
        table_options = options[:aggregate_table_options] || {}
        if (options[:truncate] && connection.tables.include?(table_name))
          connection.drop_table(table_name)
        end
        unique_index_columns = []
        index_columns = []
        if !connection.tables.include?(table_name)
          aggregate_table_options = (options[:aggregate_table_options] || {}).merge({:id => false})
          connection.create_table(table_name, aggregate_table_options) do |t|
            dimension_fields.each_with_index do |pair, i|
              dim = pair.first
              levels = pair.last
              max_level = current_levels[i]
              levels.each_with_index do |field, j|
                break if (j >= max_level)
                column_options = {:null=>false}
                if [:string, :text].include?(field.column_type)
                  column_options[:limit] = field.limit
                  column_options[:default] = ''
                elsif [:primary_key, :integer, :float, :decimal, :boolean].include?(field.column_type)
                  column_options[:default] = 0
                end
                unique_index_columns << field.label
                index_columns << field.label
                t.column(field.label, field.column_type, column_options)
              end
            end
            aggregate_fields.each do |field|
              af_opts = {}
              aggregate_type = :integer
              af_opts[:limit] = 8
              if [:float, :decimal].include?(field.type) && field.strategy_name != :count
                af_opts[:limit] = field.type == :integer ? 8 : field.limit
                af_opts[:scale] = field.scale if field.scale
                af_opts[:precision] = field.precision if field.precision
                aggregate_type = field.column_type
              end
              t.column(field.label_for_table, aggregate_type, af_opts)
            end
          end
          index_columns.each{ |dimension_column|
            connection.add_index(table_name, dimension_column, :name => "by_#{dimension_column}")
          }
          unless unique_index_columns.empty?
            connection.add_index(table_name, unique_index_columns, :unique => true, :name => "by_unique_dims") 
          end
          table_name
        end
      end
def create_aggregate_table ( base_name , dimension_fields , current_levels , options ) table_name = aggregate_rollup_name ( base_name , current_levels ) table_options = options [ :aggregate_table_options ] || { } if ( options [ :truncate ] && connection . tables . include? ( table_name ) ) connection . drop_table ( table_name ) end unique_index_columns = [ ] index_columns = [ ] if ! connection . tables . include? ( table_name ) aggregate_table_options = ( options [ :aggregate_table_options ] || { } ) . merge ( { :id => false } ) connection . create_table ( table_name , aggregate_table_options ) do | t | dimension_fields . each_with_index do | pair , i | dim = pair . first levels = pair . last max_level = current_levels [ i ] levels . each_with_index do | field , j | break if ( j >= max_level ) column_options = { :null => false } if [ :string , :text ] . include? ( field . column_type ) column_options [ :limit ] = field . limit column_options [ :default ] = '' elsif [ :primary_key , :integer , :float , :decimal , :boolean ] . include? ( field . column_type ) column_options [ :default ] = 0 end unique_index_columns << field . label index_columns << field . label t . column ( field . label , field . column_type , column_options ) end end aggregate_fields . each do | field | af_opts = { } aggregate_type = :integer af_opts [ :limit ] = 8 if [ :float , :decimal ] . include? ( field . type ) && field . strategy_name != :count af_opts [ :limit ] = field . type == :integer ? 8 : field . limit af_opts [ :scale ] = field . scale if field . scale af_opts [ :precision ] = field . precision if field . precision aggregate_type = field . column_type end t . column ( field . label_for_table , aggregate_type , af_opts ) end end index_columns . each { | dimension_column | connection . add_index ( table_name , dimension_column , :name => "by_#{dimension_column}" ) } unless unique_index_columns . empty? connection . add_index ( table_name , unique_index_columns , :unique => true , :name => "by_unique_dims" ) end table_name end end
build and populate a table which group by's all dimension columns.
build and populate a table which group by ' s all dimension columns .
# puts "create_aggregate_table start: #{current_levels.inspect}" # # truncate if configured to, otherwise, just pile it on. # puts "create_table: #{table_name}" # puts "dim.name = #{dim.name}, max = #{max_level}, i = #{i}" # unique_index_columns << field.label if (j == (max_level-1)) # if it is a string or text column, then include the limit with the options # By default the aggregate field column type will be a count # But, if type is a decimal, and you do a sum or avg (not a count) then keep it a decimal # add index per dimension here (not for aggregate fields) # puts "making index for: #{table_name} on: #{dimension_column}" # Add a unique index for the  # puts "making unique index for: #{table_name} on: #{unique_index_columns.inspect}" # puts "create_aggregate_table end"
base_name
<not_specific>
dimension_fields
<not_specific>
current_levels
<not_specific>
options
<not_specific>