Class: Gitlab::Database::Aggregation::ClickHouse::Mean

Inherits:
Column show all
Defined in:
lib/gitlab/database/aggregation/click_house/mean.rb

Instance Attribute Summary

Attributes inherited from Column

#expression, #name, #secondary_expression, #type

Attributes inherited from PartDefinition

#description, #expression, #formatter, #name, #secondary_expression, #type

Instance Method Summary collapse

Methods inherited from Column

#secondary_arel, #to_inner_arel

Methods inherited from PartDefinition

#format_value, #instance_key, #parameterized?, #validate_part

Constructor Details

#initialize(name, type = :float, expression = nil, **kwargs) ⇒ Mean

Returns a new instance of Mean.



8
9
10
# File 'lib/gitlab/database/aggregation/click_house/mean.rb', line 8

def initialize(name, type = :float, expression = nil, **kwargs)
  super
end

Instance Method Details

#identifierObject



12
13
14
# File 'lib/gitlab/database/aggregation/click_house/mean.rb', line 12

def identifier
  :"mean_#{name}"
end

#to_outer_arel(context) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/gitlab/database/aggregation/click_house/mean.rb', line 16

def to_outer_arel(context)
  return super.average unless secondary_expression

  inner_column = Arel::Table.new(context[:inner_query_name])[context.fetch(:local_alias, name)]
  inner_condition_column = Arel::Table.new(context[:inner_query_name])[context.fetch(:local_secondary_alias,
    name)]
  Arel::Nodes::NamedFunction.new('avgIf', [inner_column, inner_condition_column.eq(1)])
end