Class: Piglet::Relation::Group
- Inherits:
-
Object
- Object
- Piglet::Relation::Group
- Includes:
- Relation
- Defined in:
- lib/piglet/relation/group.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes included from Relation
Instance Method Summary collapse
-
#initialize(relation, grouping, options = {}) ⇒ Group
constructor
A new instance of Group.
- #schema ⇒ Object
- #to_s ⇒ Object
Methods included from Relation
#[], #alias, #cogroup, #cross, #distinct, #eql?, #field, #filter, #foreach, #group, #hash, #join, #limit, #method_missing, #order, #sample, #split, #stream, #union
Constructor Details
#initialize(relation, grouping, options = {}) ⇒ Group
Returns a new instance of Group.
8 9 10 11 |
# File 'lib/piglet/relation/group.rb', line 8 def initialize(relation, grouping, ={}) ||= {} @sources, @grouping, @parallel = [relation], grouping, [:parallel] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Piglet::Relation::Relation
Instance Method Details
#schema ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/piglet/relation/group.rb', line 13 def schema parent = @sources.first parent_schema = parent.schema if @grouping.size == 1 group_type = parent.schema.field_type(@grouping.first) else group_type = Piglet::Schema::Tuple.parse( @grouping.map { |field| [field, parent_schema.field_type(field)] } ) end Piglet::Schema::Tuple.parse([ [:group, group_type], [parent.alias.to_sym, Piglet::Schema::Bag.new(parent_schema)] ]) end |
#to_s ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/piglet/relation/group.rb', line 29 def to_s str = "GROUP #{@sources.first.alias} BY " if @grouping.size > 1 str << "(#{@grouping.join(', ')})" else str << @grouping.first.to_s end str << " PARALLEL #{@parallel}" if @parallel str end |