Class: Wukong::Processor::GroupConcat

Inherits:
Group show all
Defined in:
lib/wukong/widget/reducers/group_concat.rb

Overview

Concatenates the elements of a group, yielding the group key, the count, and its members.

GroupConcat takes all the same options as Group.

Examples:

Concatenating elements of a group on the command-line.


$ cat input
{"id": 1, "parent_id": 4}
{"id": 2, "parent_id": 3}
{"id": 3, "parent_id": 3}
...
$ cat input | wu-local group_concat --by=parent_id --to=tsv
4	1	{"id": 1, "parent_id": 4}
3	2	{"id": 2, "parent_id": 3}	{"id": 3, "parent_id": 3}
...

See Also:

Constant Summary

Constants inherited from Wukong::Processor

SerializerError

Instance Attribute Summary collapse

Attributes inherited from Count

#size

Attributes inherited from Accumulator

#group, #key

Attributes included from Hanuman::StageInstanceMethods

#graph

Instance Method Summary collapse

Methods inherited from Group

#get_key

Methods included from DynamicGet

#get, #get_nested, included

Methods inherited from Count

#get_key

Methods inherited from Accumulator

#get_key, #process

Methods inherited from Wukong::Processor

configure, description, #perform_action, #process, #receive_action, #stop

Methods included from Logging

included

Methods inherited from Hanuman::Stage

#clone

Methods included from Hanuman::StageClassMethods

#builder, #label, #register, #set_builder

Methods included from Hanuman::StageInstanceMethods

#add_link, #linkable_name, #root

Instance Attribute Details

#membersObject

The members of the current group.



55
56
57
# File 'lib/wukong/widget/reducers/group_concat.rb', line 55

def members
  @members
end

Instance Method Details

#accumulate(record) ⇒ Object

Accumulate each record, adding it to the current members.

Parameters:

  • record (Object)


74
75
76
77
# File 'lib/wukong/widget/reducers/group_concat.rb', line 74

def accumulate record
  super(record)
  self.members << record
end

#finalize {|key, size, *members| ... } ⇒ Object

Yields the group, including its key, its size, and each member.

Yields:

Yield Parameters:

  • key (Object)

    the key defining the group

  • size (Integer)

    the number of members in the group

  • the (Array<Object>)

    members of the group



86
87
88
89
90
# File 'lib/wukong/widget/reducers/group_concat.rb', line 86

def finalize
  group = [key, size]
  group.concat(members)
  yield group
end

#setupObject

Initializes the empty members array.



58
59
60
61
# File 'lib/wukong/widget/reducers/group_concat.rb', line 58

def setup
  super()
  @members = []
end

#start(record) ⇒ Object

Initializes the empty members array.

Parameters:

  • record (Object)


66
67
68
69
# File 'lib/wukong/widget/reducers/group_concat.rb', line 66

def start record
  super(record)
  self.members = []
end