Skip to content

Commit

Permalink
Merge branch 'feature/loop' into develop
Browse files Browse the repository at this point in the history
* feature/loop: (44 commits)
  The test suite is back to 100%.
  Fix the creation of SideEffectCapPipe directly after the sources.
  Don't need to check the type of each yielded object in BlockFilterPipe or MapPipe any longer.
  don't try add_extensions on plain objects.
  Figured out how to raise the correct exception to keep Java Pipes happy.
  Use a common method to throw pipe exception. Hopefully I'll find a technique that Java will actually be able to catch.
  Update method names in rebuild_automatic_index for interface changes in Blueprints.
  Add Utils::Trie as a little experiment with looping pipes.
  Allow to_route with specified :element_type
  Improve exceptions in route creation.
  Use the LabelPipe
  Labels now returns a route.
  AutoIndexKeysInUse is actually not necessary.
  Revert changes to block filter pipe.
  I can actually do #count with the counted pipe.
  Better inspect strings.
  Optional args when adding to expandable pipe.
  GroupPipe -- not sure about this yet but I think it will be useful if I can get it right.
  another missed require..
  Changed to #collect everywhere because #map row uses the MapPipe.
  ...

Conflicts:
	lib/pacer/pipe/stream_sort_pipe.rb
	lib/pacer/pipes.rb
	lib/pacer/route/branched_route.rb
	spec/pacer/route/branched_route_spec.rb
  • Loading branch information
Darrick Wiebe committed Jan 17, 2011
2 parents 3ae6bce + 3ddade0 commit 84938a8
Show file tree
Hide file tree
Showing 50 changed files with 880 additions and 167 deletions.
2 changes: 2 additions & 0 deletions lib/pacer.rb
Expand Up @@ -32,6 +32,8 @@ module Pacer
require 'pacer/support'
require 'pacer/utils'
require 'pacer/filter'
require 'pacer/transform'
require 'pacer/side_effect'

class << self
attr_accessor :debug_info
Expand Down
1 change: 1 addition & 0 deletions lib/pacer/core.rb
Expand Up @@ -5,3 +5,4 @@ module Core

require 'pacer/core/route'
require 'pacer/core/graph'
require 'pacer/core/side_effect'
2 changes: 1 addition & 1 deletion lib/pacer/core/graph/edges_route.rb
Expand Up @@ -45,7 +45,7 @@ def filter(*args, &block)

# Return an iterator of or yield all labels
def labels
map { |e| e.get_label }
chain_route(:pipe_class => com.tinkerpop.pipes.pgm.LabelPipe, :route_name => 'labels')
end

# Stores the result of the current route in a new route so it will not need
Expand Down
2 changes: 1 addition & 1 deletion lib/pacer/core/graph/graph_route.rb
Expand Up @@ -78,7 +78,7 @@ def use_index?(index, element_type, index_name, index_value)
if index.index_class == element_type.java_class
key, value, index_specified = index_key_value(index_name, index_value)
if index.index_type == Pacer.automatic_index
keys = index.auto_index_keys_in_use
keys = index.getAutoIndexKeys
return false if keys and not keys.include? key
end
index.index_name == index_name or (not index_specified and index.index_type == Pacer.automatic_index)
Expand Down
4 changes: 2 additions & 2 deletions lib/pacer/core/graph/mixed_route.rb
Expand Up @@ -72,7 +72,7 @@ def element_type

# Calculate and save result.
def result(name = nil)
ids = map do |element|
ids = collect do |element|
if element.is_a? Pacer::VertexMixin
[:vertex, element.id]
else
Expand All @@ -84,7 +84,7 @@ def result(name = nil)
graph.send method, id
else
loader = proc do
ids.map { |method, id| graph.send(method, id) }
ids.collect { |method, id| graph.send(method, id) }
end
chain_route :back => loader, :graph => graph, :element_type => :mixed, :info => "#{ name }:#{ids.count}", :extensions => extensions
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pacer/core/graph/vertices_route.rb
Expand Up @@ -96,7 +96,7 @@ def add_edges_to(label, to_vertices, props = {})
graph.managed_transactions do
graph.managed_transaction do
each do |from_v|
to_vertices.to_route.each do |to_v|
to_vertices.each do |to_v|
counter += 1
graph.managed_checkpoint if counter % graph.bulk_job_size == 0
begin
Expand Down
23 changes: 13 additions & 10 deletions lib/pacer/core/route.rb
Expand Up @@ -113,8 +113,11 @@ def each_element
else
if block_given?
while item = iter.next
item.graph ||= g if g and item.respond_to? :graph=
yield item.add_extensions(extensions)
if item.respond_to? :graph=
item.graph ||= g if g and item.respond_to? :graph=
item = item.add_extensions(extensions)
end
yield item
end
else
iter.extend IteratorExtensionsMixin
Expand All @@ -123,7 +126,7 @@ def each_element
iter
end
end
rescue NoSuchElementException
rescue java.util.NoSuchElementException
self
end

Expand All @@ -134,7 +137,7 @@ def each_path
if block_given?
g = graph
while item = iter.next
path = iter.path.map do |e|
path = iter.path.collect do |e|
e.graph ||= g rescue nil
e
end
Expand All @@ -145,7 +148,7 @@ def each_path
iter.graph = graph
iter
end
rescue NoSuchElementException
rescue java.util.NoSuchElementException
self
end

Expand All @@ -165,7 +168,7 @@ def each_context
iter.context = self
iter
end
rescue NoSuchElementException
rescue java.util.NoSuchElementException
self
end

Expand All @@ -178,7 +181,7 @@ def each_object
else
iter
end
rescue NoSuchElementException
rescue java.util.NoSuchElementException
self
end

Expand All @@ -193,13 +196,13 @@ def inspect(limit = nil)
else
count = 0
limit ||= Pacer.inspect_limit
results = map do |v|
results = collect do |v|
count += 1
return route.inspect if count > limit
v.inspect
end
if count > 0
lens = results.map { |r| r.length }
lens = results.collect { |r| r.length }
max = lens.max
cols = (Pacer.columns / (max + 1).to_f).floor
cols = 1 if cols < 1
Expand Down Expand Up @@ -417,7 +420,7 @@ def inspect_string
ps = @pipe_class.name
if ps =~ /FilterPipe$/
ps = ps.split('::').last.sub(/FilterPipe/, '')
pipeargs = @pipe_args.map do |arg|
pipeargs = @pipe_args.collect do |arg|
if arg.is_a? Enumerable and arg.count > 10
"[...#{ arg.count } items...]"
else
Expand Down
9 changes: 9 additions & 0 deletions lib/pacer/core/side_effect.rb
@@ -0,0 +1,9 @@
module Pacer
module Core
module SideEffect
def side_effect
@pipe.getSideEffect
end
end
end
end
1 change: 1 addition & 0 deletions lib/pacer/filter.rb
Expand Up @@ -10,3 +10,4 @@ module Filter
require 'pacer/filter/range_filter'
require 'pacer/filter/uniq_filter'
require 'pacer/filter/index_filter'
require 'pacer/filter/loop_filter'
10 changes: 4 additions & 6 deletions lib/pacer/filter/future_filter.rb
Expand Up @@ -2,11 +2,11 @@ module Pacer
module Routes
module RouteOperations
def lookahead(&block)
chain_route :lookahead => block
chain_route :lookahead => block, :has_element => true
end

def neg_lookahead(&block)
chain_route :lookahead => block
chain_route :lookahead => block, :has_element => false
end
end
end
Expand All @@ -17,14 +17,12 @@ def self.triggers
[:lookahead]
end

def lookahead=(block)
@lookahead = block
end
attr_accessor :lookahead, :has_element

protected

def attach_pipe(end_pipe)
pipe = Pacer::Pipes::FutureFilterPipe.new(lookahead_pipe)
pipe = Pacer::Pipes::FutureFilterPipe.new(lookahead_pipe, has_element)
pipe.set_starts(end_pipe)
pipe
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pacer/filter/index_filter.rb
Expand Up @@ -25,6 +25,10 @@ def source
src = index.get(key, value) || java.util.ArrayList.new
src.iterator
end

def inspect_string
"#{ inspect_class_name }(#{ key }: #{value.inspect})"
end
end
end
end
66 changes: 66 additions & 0 deletions lib/pacer/filter/loop_filter.rb
@@ -0,0 +1,66 @@
module Pacer
module Routes
module RouteOperations
public

def loop(&block)
chain_route :looping_route => block
end
end
end

module Filter
module LoopFilter
def self.triggers
[:looping_route]
end

attr_reader :looping_route

def looping_route=(route)
if route.is_a? Proc
empty = Pacer::Route.new :filter => :empty, :back => self
@looping_route = route.call(empty)
else
@looping_route = route
end
end

def while(yield_paths = false, &block)
@yield_paths = yield_paths
@control_block = block
self
end

protected

def iterator
iter = super
iter.enable_path if @yield_paths
iter
end

def attach_pipe(end_pipe)
unless @control_block
raise 'No loop control block specified. Use either #while or #until after #loop.'
end
pipe = Pacer::Pipes::LoopPipe.new(looping_pipe, @control_block)
pipe.setStarts(end_pipe)
pipe
end

def looping_pipe
s, e = looping_route.send(:build_pipeline)
if s.equal?(e)
s
else
Pacer::Pipes::Pipeline.new s, e
end
end

def inspect_string
"#{ inspect_class_name }(#{ @looping_route.inspect })"
end
end
end
end
15 changes: 10 additions & 5 deletions lib/pacer/filter/property_filter.rb
Expand Up @@ -33,8 +33,7 @@ def filter_pipe(pipe, filters, block, expand_extensions)
if labels.empty?
super
else
label_pipe = Pacer::Pipes::LabelsFilterPipe.new
label_pipe.set_labels labels
label_pipe = Pacer::Pipes::LabelCollectionFilterPipe.new labels.collect { |l| l.to_s }, Pacer::Pipes::NOT_EQUAL
label_pipe.set_starts pipe
super(label_pipe, filters - labels, block, false)
end
Expand Down Expand Up @@ -122,11 +121,17 @@ def expand_extension_conditions(pipe, args_array)
end

def inspect_string
fs = "#{filters.inspect}" if filters.any?
bs = '&block' if @block
fs = filters.map do |f|
if f.is_a? Hash
f.map { |k, v| "#{ k }==#{ v.inspect }" }
else
f.inspect
end
end
fs << '&block' if @block
s = inspect_class_name
if fs or bs
s = "#{s}(#{ [fs, bs].compact.join(', ') })"
s = "#{s}(#{ fs.join(', ') })"
end
s
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pacer/filter/range_filter.rb
Expand Up @@ -46,6 +46,10 @@ def attach_pipe(end_pipe)
pipe.set_starts end_pipe
pipe
end

def inspect_string
"#{ inspect_class_name }(#{ range.inspect })"
end
end
end
end
1 change: 0 additions & 1 deletion lib/pacer/graph.rb
@@ -1,6 +1,5 @@
module Pacer
import com.tinkerpop.blueprints.pgm.Graph
import com.tinkerpop.blueprints.pgm.util.IndexHelper
end

require 'pacer/graph/graph_mixin'
Expand Down
1 change: 0 additions & 1 deletion lib/pacer/graph/edge_mixin.rb
Expand Up @@ -42,7 +42,6 @@ def display_name
end
end


# Deletes the edge from its graph.
def delete!
graph.remove_edge element
Expand Down
2 changes: 1 addition & 1 deletion lib/pacer/graph/element_mixin.rb
Expand Up @@ -67,7 +67,7 @@ def properties

def properties=(props)
props = graph.sanitize_properties(props) if graph
(property_keys - props.keys.map { |k| k.to_s }).each do |key|
(property_keys - props.keys.collect { |k| k.to_s }).each do |key|
remove_property key
end
props.each do |key, value|
Expand Down
20 changes: 14 additions & 6 deletions lib/pacer/graph/graph_mixin.rb
Expand Up @@ -115,19 +115,19 @@ def index_name(name, type = nil, opts = {})
end

def rebuild_automatic_index(old_index)
name = old_index.index_name
index_class = old_index.index_class
keys = old_index.auto_index_keys
name = old_index.getIndexName
index_class = old_index.getIndexClass
keys = old_index.getAutoIndexKeys
drop_index name
index = create_index name, index_class, Pacer.automatic_index
keys.each { |key| index.add_auto_index_key key } if keys
keys.each { |key| index.addAutoIndexKey key } if keys
if index_class == element_type(:vertex).java_class
v.bulk_job do |v|
Pacer::Utils::IndexHelper.autoIndexElement(index, v)
Pacer::Utils::AutomaticIndexHelper.indexElement(index, v)
end
else
e.bulk_job do |e|
Pacer::Utils::IndexHelper.autoIndexElement(index, e)
Pacer::Utils::AutomaticIndexHelper.indexElement(index, e)
end
end
index
Expand Down Expand Up @@ -165,6 +165,14 @@ def index_class(et)
element_type(et).java_class.to_java
end

def element_type?(et)
if [element_type(:vertex), element_type(:edge), element_type(:mixed)].include? element_type(et)
true
else
false
end
end

protected

def creating_elements
Expand Down

0 comments on commit 84938a8

Please sign in to comment.