Sha256: 00675c8a5661be65c12aa6b03258b6da176d7b69a40a56e1cb7c312c2153b69f

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module Piglet
  module Relation
    class Group # :nodoc:
      include Relation
    
      def initialize(relation, grouping, options={})
        options ||= {}
        @sources, @grouping, @parallel = [relation], grouping, options[:parallel]
      end
      
      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
    
      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
piglet-0.2.4 lib/piglet/relation/group.rb
piglet-0.2.3 lib/piglet/relation/group.rb
piglet-0.2.2 lib/piglet/relation/group.rb
piglet-0.2.0 lib/piglet/relation/group.rb