Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring aggregates in order to support aggregate each [#72 state:…
…open]
- Loading branch information
andreas
committed
Sep 28, 2009
1 parent
31fdb51
commit 1c0ab81
Showing
8 changed files
with
139 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Neo4j::Aggregate | ||
class AggregateEachNode | ||
include Neo4j::NodeMixin | ||
include Neo4j::Aggregate::AggregateEachNodeMixin | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
lib/neo4j/extensions/aggregate/aggregate_each_node_mixin.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Neo4j::Aggregate | ||
|
||
module AggregateEachNodeMixin | ||
include Neo4j::NodeMixin | ||
include Enumerable | ||
|
||
has_list :groups | ||
|
||
def aggregate_size | ||
groups.size | ||
end | ||
|
||
def each | ||
groups.each {|node| yield node} | ||
end | ||
|
||
def aggregate_each(nodes) | ||
AggregatorEach.new(self, nodes) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Neo4j::Aggregate | ||
|
||
class AggregateNode | ||
include Neo4j::NodeMixin | ||
include Neo4j::Aggregate::AggregateNodeMixin | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Neo4j::Aggregate | ||
class AggregatorEach | ||
def initialize(root_node, nodes) | ||
@root_node = root_node | ||
@nodes = nodes | ||
end | ||
|
||
# Specifies which properties we should group on. | ||
# All thos properties can be combined to create a new group. | ||
# | ||
# :api: public | ||
def group_by(*keys) | ||
@group_by = keys | ||
self | ||
end | ||
|
||
|
||
def execute | ||
@nodes.each do |node| | ||
puts "agg #{node}" | ||
group_node = GroupEachNode.new | ||
group_node.group_by = @group_by.join(',') | ||
group_node.aggregate = node | ||
@root_node.groups << group_node | ||
puts "agg #{node} done" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Neo4j::Aggregate | ||
|
||
class GroupEachNode | ||
include Neo4j::NodeMixin | ||
include Enumerable | ||
|
||
has_one :aggregate | ||
property :aggregate_group, :aggregate_size, :group_by | ||
|
||
|
||
def each | ||
puts "each group #{group_by}" | ||
puts "Agg node #{aggregate.props.inspect}" | ||
group_by.split(',').each do |group| | ||
puts "VALUE key='#{group}' vakye=#{aggregate[group]}'" | ||
yield aggregate[group] | ||
end | ||
end | ||
|
||
|
||
# :api: private | ||
def get_property(key) | ||
value = super(key) | ||
return value unless value.nil? | ||
return nil unless aggregate | ||
aggregate[key] | ||
end | ||
|
||
end | ||
|
||
end |
Oops, something went wrong.