lib/piglet/relation/group.rb in piglet-0.1.2 vs lib/piglet/relation/group.rb in piglet-0.2.0
- old
+ new
@@ -5,9 +5,25 @@
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(', ')})"
\ No newline at end of file