Class: ConceptQL::Operators::Count

Inherits:
PassThru show all
Defined in:
lib/conceptql/operators/count.rb

Constant Summary

Constants inherited from Operator

Operator::COLUMNS

Instance Attribute Summary

Attributes inherited from Operator

#arguments, #options, #upstreams, #values

Instance Method Summary collapse

Methods inherited from PassThru

#types

Methods inherited from Operator

#columns, #evaluate, #initialize, #label, #select_it, #set_values, #sql, #stream, #types

Methods included from Metadatable

#allows_many_upstreams, #allows_one_upstream, #argument, #category, #desc, #humanized_class_name, #inherited, #just_class_name, #option, #predominant_types, #preferred_name, #reset_categories, #to_metadata, #types

Constructor Details

This class inherits a constructor from ConceptQL::Operators::Operator

Instance Method Details

#query(db) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/conceptql/operators/count.rb', line 9

def query(db)
  db.from(unioned(db))
    .group(*COLUMNS)
    .select(*(COLUMNS - [:value_as_number]))
    .select_append{count(1).as(:value_as_number)}
    .from_self
end

#unioned(db) ⇒ Object



17
18
19
20
21
# File 'lib/conceptql/operators/count.rb', line 17

def unioned(db)
  upstreams.map { |c| c.evaluate(db) }.inject do |uni, q|
    uni.union(q)
  end
end