pacer 0.9.1.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +8 -0
- data/.document +5 -0
- data/.gitignore +26 -0
- data/.rspec +1 -0
- data/.rvmrc +0 -0
- data/CONTRIBUTORS +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +187 -0
- data/Rakefile +49 -0
- data/autotest/discover.rb +1 -0
- data/bin/autospec +16 -0
- data/bin/autotest +16 -0
- data/bin/rake +16 -0
- data/bin/rcov +16 -0
- data/bin/rspec +16 -0
- data/bin/yard +16 -0
- data/bin/yardoc +16 -0
- data/lib/pacer/blueprints/extensions.rb +77 -0
- data/lib/pacer/blueprints/multi_graph.rb +121 -0
- data/lib/pacer/blueprints/ruby_graph.rb +199 -0
- data/lib/pacer/blueprints/tg.rb +100 -0
- data/lib/pacer/blueprints.rb +4 -0
- data/lib/pacer/core/graph/edges_route.rb +92 -0
- data/lib/pacer/core/graph/element_route.rb +171 -0
- data/lib/pacer/core/graph/graph_index_route.rb +48 -0
- data/lib/pacer/core/graph/graph_route.rb +55 -0
- data/lib/pacer/core/graph/mixed_route.rb +96 -0
- data/lib/pacer/core/graph/vertices_route.rb +220 -0
- data/lib/pacer/core/graph.rb +13 -0
- data/lib/pacer/core/route.rb +502 -0
- data/lib/pacer/core/side_effect.rb +11 -0
- data/lib/pacer/core.rb +8 -0
- data/lib/pacer/exceptions.rb +11 -0
- data/lib/pacer/extensions/block_filter_element.rb +22 -0
- data/lib/pacer/extensions.rb +6 -0
- data/lib/pacer/filter/block_filter.rb +31 -0
- data/lib/pacer/filter/collection_filter.rb +109 -0
- data/lib/pacer/filter/empty_filter.rb +70 -0
- data/lib/pacer/filter/future_filter.rb +68 -0
- data/lib/pacer/filter/index_filter.rb +30 -0
- data/lib/pacer/filter/loop_filter.rb +95 -0
- data/lib/pacer/filter/object_filter.rb +55 -0
- data/lib/pacer/filter/property_filter/edge_filters.rb +93 -0
- data/lib/pacer/filter/property_filter/filters.rb +269 -0
- data/lib/pacer/filter/property_filter.rb +111 -0
- data/lib/pacer/filter/random_filter.rb +13 -0
- data/lib/pacer/filter/range_filter.rb +104 -0
- data/lib/pacer/filter/uniq_filter.rb +12 -0
- data/lib/pacer/filter/where_filter/node_visitor.rb +280 -0
- data/lib/pacer/filter/where_filter.rb +47 -0
- data/lib/pacer/filter.rb +17 -0
- data/lib/pacer/function_resolver.rb +43 -0
- data/lib/pacer/graph/edge_mixin.rb +127 -0
- data/lib/pacer/graph/element_mixin.rb +202 -0
- data/lib/pacer/graph/graph_indices_mixin.rb +93 -0
- data/lib/pacer/graph/graph_mixin.rb +361 -0
- data/lib/pacer/graph/graph_transactions_mixin.rb +207 -0
- data/lib/pacer/graph/index_mixin.rb +30 -0
- data/lib/pacer/graph/vertex_mixin.rb +119 -0
- data/lib/pacer/graph.rb +14 -0
- data/lib/pacer/pipe/blackbox_pipeline.rb +48 -0
- data/lib/pacer/pipe/block_filter_pipe.rb +38 -0
- data/lib/pacer/pipe/collection_filter_pipe.rb +10 -0
- data/lib/pacer/pipe/cross_product_transform_pipe.rb +48 -0
- data/lib/pacer/pipe/enumerable_pipe.rb +30 -0
- data/lib/pacer/pipe/expandable_pipe.rb +63 -0
- data/lib/pacer/pipe/id_collection_filter_pipe.rb +33 -0
- data/lib/pacer/pipe/is_empty_pipe.rb +30 -0
- data/lib/pacer/pipe/is_unique_pipe.rb +61 -0
- data/lib/pacer/pipe/label_collection_filter_pipe.rb +21 -0
- data/lib/pacer/pipe/label_prefix_pipe.rb +21 -0
- data/lib/pacer/pipe/loop_pipe.rb +86 -0
- data/lib/pacer/pipe/map_pipe.rb +36 -0
- data/lib/pacer/pipe/never_pipe.rb +9 -0
- data/lib/pacer/pipe/process_pipe.rb +37 -0
- data/lib/pacer/pipe/property_comparison_pipe.rb +40 -0
- data/lib/pacer/pipe/ruby_pipe.rb +25 -0
- data/lib/pacer/pipe/simple_visitor_pipe.rb +43 -0
- data/lib/pacer/pipe/stream_sort_pipe.rb +84 -0
- data/lib/pacer/pipe/stream_uniq_pipe.rb +33 -0
- data/lib/pacer/pipe/type_filter_pipe.rb +22 -0
- data/lib/pacer/pipe/unary_transform_pipe.rb +59 -0
- data/lib/pacer/pipe/variable_store_iterator_wrapper.rb +26 -0
- data/lib/pacer/pipe/visitor_pipe.rb +67 -0
- data/lib/pacer/pipes.rb +61 -0
- data/lib/pacer/route/mixin/bulk_operations.rb +52 -0
- data/lib/pacer/route/mixin/route_operations.rb +107 -0
- data/lib/pacer/route/mixin/variable_route_module.rb +26 -0
- data/lib/pacer/route/mixins.rb +3 -0
- data/lib/pacer/route.rb +228 -0
- data/lib/pacer/routes.rb +6 -0
- data/lib/pacer/side_effect/aggregate.rb +31 -0
- data/lib/pacer/side_effect/counted.rb +30 -0
- data/lib/pacer/side_effect/group_count.rb +44 -0
- data/lib/pacer/side_effect/is_unique.rb +32 -0
- data/lib/pacer/side_effect/section.rb +25 -0
- data/lib/pacer/side_effect/visitor.rb +37 -0
- data/lib/pacer/side_effect.rb +11 -0
- data/lib/pacer/support/array_list.rb +28 -0
- data/lib/pacer/support/enumerable.rb +100 -0
- data/lib/pacer/support/hash.rb +9 -0
- data/lib/pacer/support/iterator_mixins.rb +110 -0
- data/lib/pacer/support/native_exception.rb +22 -0
- data/lib/pacer/support/proc.rb +16 -0
- data/lib/pacer/support.rb +10 -0
- data/lib/pacer/transform/cap.rb +50 -0
- data/lib/pacer/transform/gather.rb +9 -0
- data/lib/pacer/transform/has_count_cap.rb +41 -0
- data/lib/pacer/transform/join.rb +181 -0
- data/lib/pacer/transform/map.rb +23 -0
- data/lib/pacer/transform/path.rb +50 -0
- data/lib/pacer/transform/process.rb +23 -0
- data/lib/pacer/transform/scatter.rb +23 -0
- data/lib/pacer/transform/sort_section.rb +103 -0
- data/lib/pacer/transform/stream_sort.rb +21 -0
- data/lib/pacer/transform/stream_uniq.rb +21 -0
- data/lib/pacer/transform.rb +16 -0
- data/lib/pacer/utils/graph_analysis.rb +112 -0
- data/lib/pacer/utils/trie.rb +93 -0
- data/lib/pacer/utils/tsort.rb +65 -0
- data/lib/pacer/utils/y_files.rb +127 -0
- data/lib/pacer/utils.rb +10 -0
- data/lib/pacer/version.rb +13 -0
- data/lib/pacer/wrappers/edge_wrapper.rb +51 -0
- data/lib/pacer/wrappers/element_wrapper.rb +78 -0
- data/lib/pacer/wrappers/new_element.rb +106 -0
- data/lib/pacer/wrappers/vertex_wrapper.rb +51 -0
- data/lib/pacer/wrappers.rb +19 -0
- data/lib/pacer-0.9.1.1-standalone.jar +0 -0
- data/lib/pacer.rb +290 -0
- data/pacer.gemspec +30 -0
- data/pom/standalone.xml +22 -0
- data/pom.xml +124 -0
- data/samples/grateful-dead.xml +26380 -0
- data/samples/grateful_dead.rb +63 -0
- data/samples/profile.rb +15 -0
- data/spec/data/grateful-dead.xml +26380 -0
- data/spec/data/pacer.graphml +319 -0
- data/spec/pacer/blueprints/dex_spec.rb +172 -0
- data/spec/pacer/blueprints/neo4j_spec.rb +177 -0
- data/spec/pacer/blueprints/tg_spec.rb +128 -0
- data/spec/pacer/core/graph/edges_route_spec.rb +52 -0
- data/spec/pacer/core/graph/element_route_spec.rb +46 -0
- data/spec/pacer/core/graph/graph_route_spec.rb +94 -0
- data/spec/pacer/core/graph/vertices_route_spec.rb +169 -0
- data/spec/pacer/core/route_spec.rb +197 -0
- data/spec/pacer/filter/collection_filter_spec.rb +19 -0
- data/spec/pacer/filter/empty_filter_spec.rb +29 -0
- data/spec/pacer/filter/future_filter_spec.rb +97 -0
- data/spec/pacer/filter/loop_filter_spec.rb +31 -0
- data/spec/pacer/filter/property_filter_spec.rb +111 -0
- data/spec/pacer/filter/random_filter_spec.rb +17 -0
- data/spec/pacer/filter/uniq_filter_spec.rb +18 -0
- data/spec/pacer/filter/where_filter_spec.rb +93 -0
- data/spec/pacer/graph/edge_mixin_spec.rb +116 -0
- data/spec/pacer/graph/element_mixin_spec.rb +297 -0
- data/spec/pacer/graph/graph_mixin_spec.rb +538 -0
- data/spec/pacer/graph/index_mixin_spec.rb +0 -0
- data/spec/pacer/graph/vertex_mixin_spec.rb +192 -0
- data/spec/pacer/pipe/block_filter_pipe_spec.rb +0 -0
- data/spec/pacer/pipe/labels_filter_pipe_spec.rb +0 -0
- data/spec/pacer/pipe/ruby_pipe_spec.rb +0 -0
- data/spec/pacer/pipe/type_filter_pipe_spec.rb +0 -0
- data/spec/pacer/route/mixin/base_spec.rb +419 -0
- data/spec/pacer/route/mixin/bulk_operations_spec.rb +30 -0
- data/spec/pacer/route/mixin/route_operations_spec.rb +127 -0
- data/spec/pacer/support/array_list_spec.rb +0 -0
- data/spec/pacer/support/enumerable_spec.rb +115 -0
- data/spec/pacer/transform/join_spec.rb +138 -0
- data/spec/pacer/transform/path_spec.rb +54 -0
- data/spec/pacer/utils/tsort_spec.rb +89 -0
- data/spec/pacer/wrapper/edge_wrapper_spec.rb +33 -0
- data/spec/pacer/wrapper/element_wrapper_spec.rb +169 -0
- data/spec/pacer/wrapper/vertex_wrapper_spec.rb +33 -0
- data/spec/pacer_spec.rb +0 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/support/contexts.rb +14 -0
- data/spec/support/graph_runner.rb +142 -0
- data/spec/support/matchers.rb +19 -0
- data/spec/support/use_transactions.rb +31 -0
- data/spec/tackle/simple_mixin.rb +21 -0
- data/spec/tackle/tinkerpop_graph_mixins.rb +60 -0
- metadata +364 -0
data/lib/pacer/graph.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Pacer
|
|
2
|
+
import com.tinkerpop.blueprints.pgm.Graph
|
|
3
|
+
import com.tinkerpop.blueprints.pgm.Element
|
|
4
|
+
import com.tinkerpop.blueprints.pgm.Vertex
|
|
5
|
+
import com.tinkerpop.blueprints.pgm.Edge
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
require 'pacer/graph/graph_mixin'
|
|
9
|
+
require 'pacer/graph/element_mixin'
|
|
10
|
+
require 'pacer/graph/vertex_mixin'
|
|
11
|
+
require 'pacer/graph/edge_mixin'
|
|
12
|
+
require 'pacer/graph/index_mixin'
|
|
13
|
+
require 'pacer/graph/graph_indices_mixin'
|
|
14
|
+
require 'pacer/graph/graph_transactions_mixin'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
# Same concept as the regular pipeline, but this one
|
|
3
|
+
# does not touch the intermediate pipes. They must be
|
|
4
|
+
# wired together before being passed in to this object.
|
|
5
|
+
# This allows me to build a pipeline in Pacer and then
|
|
6
|
+
# pass it on to a pipe like FutureFilterPipe that only
|
|
7
|
+
# knows how to act on a single pipe.
|
|
8
|
+
class BlackboxPipeline
|
|
9
|
+
include com.tinkerpop.pipes.Pipe
|
|
10
|
+
|
|
11
|
+
def initialize(start_pipe, end_pipe)
|
|
12
|
+
@start_pipe = start_pipe
|
|
13
|
+
@end_pipe = end_pipe
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def setStarts(pipe)
|
|
17
|
+
if pipe.respond_to? :iterator
|
|
18
|
+
@start_pipe.setStarts pipe.iterator
|
|
19
|
+
else
|
|
20
|
+
@start_pipe.setStarts pipe
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def next
|
|
25
|
+
@end_pipe.next
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def hasNext
|
|
29
|
+
@end_pipe.hasNext
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def reset
|
|
33
|
+
@end_pipe.reset
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def getPath
|
|
37
|
+
@end_pipe.getPath
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def iterator
|
|
41
|
+
@end_pipe.iterator
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_s
|
|
45
|
+
"[#{ @start_pipe }...#{ @end_pipe }]"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class BlockFilterPipe < AbstractPipe
|
|
3
|
+
field_reader :starts
|
|
4
|
+
|
|
5
|
+
def initialize(back, block, invert = false)
|
|
6
|
+
super()
|
|
7
|
+
@back = back
|
|
8
|
+
@block = block
|
|
9
|
+
@graph = back.graph
|
|
10
|
+
@invert = invert
|
|
11
|
+
|
|
12
|
+
@exts = @back.extensions + [Pacer::Extensions::BlockFilterElement]
|
|
13
|
+
@is_element = @graph.element_type?(back.element_type) if @graph
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def processNextStart()
|
|
17
|
+
while raw_element = starts.next
|
|
18
|
+
if @is_element
|
|
19
|
+
extended_element = raw_element.add_extensions(@exts)
|
|
20
|
+
extended_element.back = @back
|
|
21
|
+
extended_element.graph = @back.graph
|
|
22
|
+
ok = @block.call extended_element
|
|
23
|
+
else
|
|
24
|
+
ok = @block.call raw_element
|
|
25
|
+
end
|
|
26
|
+
ok = !ok if @invert
|
|
27
|
+
return raw_element if ok
|
|
28
|
+
end
|
|
29
|
+
raise Pacer::NoSuchElementException
|
|
30
|
+
rescue NativeException => e
|
|
31
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
32
|
+
raise e.cause
|
|
33
|
+
else
|
|
34
|
+
raise e
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class CrossProductTransformPipe < UnaryTransformPipe
|
|
3
|
+
attr_reader :branch_b
|
|
4
|
+
|
|
5
|
+
def initialize(method, branch_a, branch_b)
|
|
6
|
+
super(method, branch_a)
|
|
7
|
+
if branch_b.is_a? Pipe
|
|
8
|
+
@branch_b = branch_b
|
|
9
|
+
@b = nil
|
|
10
|
+
else
|
|
11
|
+
@b = branch_b
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def processNextStart
|
|
16
|
+
next_pair
|
|
17
|
+
a.send method, b rescue nil if a.respond_to? method
|
|
18
|
+
rescue NativeException => e
|
|
19
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
20
|
+
raise e.cause
|
|
21
|
+
else
|
|
22
|
+
raise e
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
protected
|
|
27
|
+
|
|
28
|
+
attr_accessor :b
|
|
29
|
+
|
|
30
|
+
def next_pair
|
|
31
|
+
if branch_b
|
|
32
|
+
begin
|
|
33
|
+
self.b = branch_b.next
|
|
34
|
+
rescue NativeException => e
|
|
35
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass or @first
|
|
36
|
+
next_a
|
|
37
|
+
branch_b.setStarts SingleIterator.new(element)
|
|
38
|
+
retry
|
|
39
|
+
else
|
|
40
|
+
raise e
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
else
|
|
44
|
+
next_a
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class EnumerablePipe < RubyPipe
|
|
3
|
+
def initialize(enumerable)
|
|
4
|
+
super()
|
|
5
|
+
case enumerable
|
|
6
|
+
when Enumerator
|
|
7
|
+
starts = enumerable
|
|
8
|
+
when Pacer::ElementMixin
|
|
9
|
+
starts = [enumerable].to_enum
|
|
10
|
+
when Enumerable
|
|
11
|
+
starts = enumerable.to_enum
|
|
12
|
+
else
|
|
13
|
+
starts = [enumerable].to_enum
|
|
14
|
+
end
|
|
15
|
+
set_starts starts
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def processNextStart()
|
|
19
|
+
@starts.next
|
|
20
|
+
rescue StopIteration
|
|
21
|
+
raise Pacer::NoSuchElementException
|
|
22
|
+
rescue NativeException => e
|
|
23
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
24
|
+
raise e.cause
|
|
25
|
+
else
|
|
26
|
+
raise e
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class ExpandablePipe < RubyPipe
|
|
3
|
+
def initialize
|
|
4
|
+
super()
|
|
5
|
+
@queue = java.util.LinkedList.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def add(element, metadata = nil, path = nil)
|
|
9
|
+
@queue.add [element, metadata, path]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def metadata
|
|
13
|
+
@metadata
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def next
|
|
17
|
+
super
|
|
18
|
+
rescue NativeException => e
|
|
19
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
20
|
+
raise e.cause
|
|
21
|
+
else
|
|
22
|
+
raise e
|
|
23
|
+
end
|
|
24
|
+
ensure
|
|
25
|
+
@path = @next_path
|
|
26
|
+
@metadata = @next_metadata
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
protected
|
|
30
|
+
|
|
31
|
+
def processNextStart
|
|
32
|
+
if @queue.isEmpty
|
|
33
|
+
@next_metadata = nil
|
|
34
|
+
r = @starts.next
|
|
35
|
+
if @starts.respond_to? :getPath
|
|
36
|
+
@next_path = @starts.getPath
|
|
37
|
+
else
|
|
38
|
+
@next_path = java.util.ArrayList.new
|
|
39
|
+
end
|
|
40
|
+
r
|
|
41
|
+
else
|
|
42
|
+
element, @next_metadata, @next_path = @queue.remove
|
|
43
|
+
element
|
|
44
|
+
end
|
|
45
|
+
rescue NativeException => e
|
|
46
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
47
|
+
raise e.cause
|
|
48
|
+
else
|
|
49
|
+
raise e
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def getPathToHere
|
|
54
|
+
path = java.util.ArrayList.new
|
|
55
|
+
if @path
|
|
56
|
+
@path.each do |e|
|
|
57
|
+
path.add e
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
path
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class IdCollectionFilterPipe < RubyPipe
|
|
3
|
+
def initialize(ids, comparison)
|
|
4
|
+
super()
|
|
5
|
+
@ids = Set[*ids]
|
|
6
|
+
@comparison = comparison
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def processNextStart
|
|
10
|
+
if @comparison == Pacer::Pipes::EQUAL
|
|
11
|
+
while true
|
|
12
|
+
element = @starts.next
|
|
13
|
+
if element and @ids.include? element.element_id
|
|
14
|
+
return element
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
else
|
|
18
|
+
while true
|
|
19
|
+
element = @starts.next
|
|
20
|
+
if element and not @ids.include? element.element_id
|
|
21
|
+
return element
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
rescue NativeException => e
|
|
26
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
27
|
+
raise e.cause
|
|
28
|
+
else
|
|
29
|
+
raise e
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class IsEmptyPipe < RubyPipe
|
|
3
|
+
def initialize
|
|
4
|
+
super
|
|
5
|
+
@raise = false
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def processNextStart
|
|
9
|
+
raise Pacer::NoSuchElementException if @raise
|
|
10
|
+
@starts.next
|
|
11
|
+
@raise = true
|
|
12
|
+
rescue NativeException => e
|
|
13
|
+
if e.cause.getClass == NoSuchElementException.getClass
|
|
14
|
+
# This is the only case where we return true.
|
|
15
|
+
# The only time we get here is if the first call to next
|
|
16
|
+
# has no results.
|
|
17
|
+
true
|
|
18
|
+
else
|
|
19
|
+
raise e
|
|
20
|
+
end
|
|
21
|
+
else
|
|
22
|
+
raise Pacer::NoSuchElementException
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def reset
|
|
26
|
+
@raise = false
|
|
27
|
+
super()
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class IsUniquePipe < RubyPipe
|
|
3
|
+
import java.util.ArrayList
|
|
4
|
+
import com.tinkerpop.pipes.sideeffect.SideEffectPipe
|
|
5
|
+
import com.tinkerpop.pipes.util.ExpandableIterator
|
|
6
|
+
import com.tinkerpop.pipes.filter.DuplicateFilterPipe
|
|
7
|
+
|
|
8
|
+
include SideEffectPipe
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
super()
|
|
12
|
+
prepare_state
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def processNextStart
|
|
16
|
+
value = starts.next
|
|
17
|
+
check_uniqueness value if @unique
|
|
18
|
+
value
|
|
19
|
+
rescue NativeException => e
|
|
20
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
21
|
+
raise e.cause
|
|
22
|
+
else
|
|
23
|
+
raise e
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def reset
|
|
28
|
+
super()
|
|
29
|
+
prepare_state
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def unique?
|
|
33
|
+
@unique
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def getSideEffect
|
|
37
|
+
@unique
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
protected
|
|
41
|
+
|
|
42
|
+
def check_uniqueness(value)
|
|
43
|
+
@expando.add value
|
|
44
|
+
@unique_pipe.next
|
|
45
|
+
rescue NativeException => e
|
|
46
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
47
|
+
@unique = false
|
|
48
|
+
else
|
|
49
|
+
raise e
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def prepare_state
|
|
54
|
+
@unique = true
|
|
55
|
+
@expando = ExpandableIterator.new ArrayList.new.iterator
|
|
56
|
+
@unique_pipe = DuplicateFilterPipe.new
|
|
57
|
+
@unique_pipe.setStarts @expando
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class LabelCollectionFilterPipe < RubyPipe
|
|
3
|
+
def initialize(labels)
|
|
4
|
+
super()
|
|
5
|
+
@labels = Set[*labels.map(&:to_s)]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def processNextStart
|
|
9
|
+
while true
|
|
10
|
+
edge = @starts.next
|
|
11
|
+
return edge if edge and @labels.include? edge.label
|
|
12
|
+
end
|
|
13
|
+
rescue NativeException => e
|
|
14
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
15
|
+
raise e.cause
|
|
16
|
+
else
|
|
17
|
+
raise e
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class LabelPrefixPipe < RubyPipe
|
|
3
|
+
def initialize(prefix)
|
|
4
|
+
super()
|
|
5
|
+
@prefix = /^#{prefix}/
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def processNextStart
|
|
9
|
+
while true
|
|
10
|
+
edge = @starts.next
|
|
11
|
+
return edge if edge.label =~ @prefix
|
|
12
|
+
end
|
|
13
|
+
rescue NativeException => e
|
|
14
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
15
|
+
raise e.cause
|
|
16
|
+
else
|
|
17
|
+
raise e
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class LoopPipe < RubyPipe
|
|
3
|
+
import java.util.ArrayList
|
|
4
|
+
|
|
5
|
+
def initialize(graph, looping_pipe, control_block)
|
|
6
|
+
super()
|
|
7
|
+
@control_block = control_block
|
|
8
|
+
|
|
9
|
+
@expando = ExpandablePipe.new
|
|
10
|
+
empty = ArrayList.new
|
|
11
|
+
@expando.setStarts empty.iterator
|
|
12
|
+
looping_pipe.setStarts(@expando)
|
|
13
|
+
@looping_pipe = looping_pipe
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def next
|
|
17
|
+
super
|
|
18
|
+
rescue NativeException => e
|
|
19
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
20
|
+
raise e.cause
|
|
21
|
+
else
|
|
22
|
+
raise e
|
|
23
|
+
end
|
|
24
|
+
ensure
|
|
25
|
+
@path = @next_path
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def setStarts(starts)
|
|
29
|
+
@starts_has_path = starts.respond_to? :getPath
|
|
30
|
+
super
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
|
|
35
|
+
def processNextStart
|
|
36
|
+
while true
|
|
37
|
+
# FIXME: hasNext shouldn't be raising an exception...
|
|
38
|
+
has_next = @looping_pipe.hasNext rescue nil
|
|
39
|
+
if has_next
|
|
40
|
+
element = @looping_pipe.next
|
|
41
|
+
depth = (@expando.metadata || 0) + 1
|
|
42
|
+
@next_path = @looping_pipe.getPath
|
|
43
|
+
else
|
|
44
|
+
element = @starts.next
|
|
45
|
+
if @starts_has_path
|
|
46
|
+
@next_path = @starts.getPath
|
|
47
|
+
else
|
|
48
|
+
@next_path = ArrayList.new
|
|
49
|
+
@next_path.add element
|
|
50
|
+
end
|
|
51
|
+
depth = 0
|
|
52
|
+
end
|
|
53
|
+
element.graph ||= @graph if element.respond_to? :graph=
|
|
54
|
+
case @control_block.call element, depth, @next_path
|
|
55
|
+
when :loop
|
|
56
|
+
@expando.add element, depth, @next_path
|
|
57
|
+
when :emit
|
|
58
|
+
return element
|
|
59
|
+
when :emit_and_loop, :loop_and_emit
|
|
60
|
+
@expando.add element, depth, @next_path
|
|
61
|
+
return element
|
|
62
|
+
when false, nil
|
|
63
|
+
else
|
|
64
|
+
@expando.add element, depth, @next_path
|
|
65
|
+
return element
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
rescue NativeException => e
|
|
69
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
70
|
+
raise e.cause
|
|
71
|
+
else
|
|
72
|
+
raise e
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def getPathToHere
|
|
77
|
+
path = ArrayList.new
|
|
78
|
+
if @path
|
|
79
|
+
@path.each do |e|
|
|
80
|
+
path.add e
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
path
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class MapPipe < AbstractPipe
|
|
3
|
+
field_reader :starts
|
|
4
|
+
|
|
5
|
+
def initialize(back, block)
|
|
6
|
+
super()
|
|
7
|
+
@block = block
|
|
8
|
+
@back = back
|
|
9
|
+
@graph = back.graph if back
|
|
10
|
+
@extensions = back.extensions + [Pacer::Extensions::BlockFilterElement]
|
|
11
|
+
@is_element = @graph.element_type?(back.element_type) if @graph
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def processNextStart
|
|
15
|
+
while true
|
|
16
|
+
obj = starts.next
|
|
17
|
+
begin
|
|
18
|
+
if @is_element
|
|
19
|
+
obj = obj.add_extensions(@extensions)
|
|
20
|
+
obj.back = @back
|
|
21
|
+
obj.graph = @back.graph
|
|
22
|
+
end
|
|
23
|
+
rescue
|
|
24
|
+
end
|
|
25
|
+
result = @block.call(obj)
|
|
26
|
+
return result
|
|
27
|
+
end
|
|
28
|
+
rescue NativeException => e
|
|
29
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
30
|
+
raise e.cause
|
|
31
|
+
else
|
|
32
|
+
raise e
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class ProcessPipe < AbstractPipe
|
|
3
|
+
field_reader :starts
|
|
4
|
+
attr_reader :is_element, :extensions, :back, :block, :graph
|
|
5
|
+
|
|
6
|
+
def initialize(back, block)
|
|
7
|
+
super()
|
|
8
|
+
@block = block
|
|
9
|
+
@back = back
|
|
10
|
+
@graph = back.graph if back
|
|
11
|
+
@extensions = back.extensions + [Pacer::Extensions::BlockFilterElement]
|
|
12
|
+
@is_element = graph.element_type?(back.element_type) if graph
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def processNextStart
|
|
16
|
+
while true
|
|
17
|
+
obj = starts.next
|
|
18
|
+
begin
|
|
19
|
+
if is_element
|
|
20
|
+
obj = obj.add_extensions(extensions)
|
|
21
|
+
obj.back = back
|
|
22
|
+
obj.graph = graph
|
|
23
|
+
end
|
|
24
|
+
rescue
|
|
25
|
+
end
|
|
26
|
+
result = block.call(obj)
|
|
27
|
+
return obj
|
|
28
|
+
end
|
|
29
|
+
rescue NativeException => e
|
|
30
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
31
|
+
raise e.cause
|
|
32
|
+
else
|
|
33
|
+
raise e
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class PropertyComparisonFilterPipe < RubyPipe
|
|
3
|
+
def initialize(left, right, filter)
|
|
4
|
+
super()
|
|
5
|
+
@filter = filter
|
|
6
|
+
@left = left.to_s
|
|
7
|
+
@right = right.to_s
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
protected
|
|
11
|
+
|
|
12
|
+
def processNextStart
|
|
13
|
+
while true
|
|
14
|
+
obj = @starts.next
|
|
15
|
+
l = obj.getProperty(@left)
|
|
16
|
+
r = obj.getProperty(@right)
|
|
17
|
+
case @filter
|
|
18
|
+
when FilterPipe::Filter::EQUAL
|
|
19
|
+
return obj if l == r
|
|
20
|
+
when FilterPipe::Filter::NOT_EQUAL
|
|
21
|
+
return obj if l != r
|
|
22
|
+
when FilterPipe::Filter::GREATER_THAN
|
|
23
|
+
return obj if l and r and l > r
|
|
24
|
+
when FilterPipe::Filter::LESS_THAN
|
|
25
|
+
return obj if l and r and l < r
|
|
26
|
+
when FilterPipe::Filter::GREATER_THAN_EQUAL
|
|
27
|
+
return obj if l and r and l >= r
|
|
28
|
+
when FilterPipe::Filter::LESS_THAN_EQUAL
|
|
29
|
+
return obj if l and r and l <= r
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
rescue NativeException => e
|
|
33
|
+
if e.cause.getClass == Pacer::NoSuchElementException.getClass
|
|
34
|
+
raise e.cause
|
|
35
|
+
else
|
|
36
|
+
raise e
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Pacer::Pipes
|
|
2
|
+
class RubyPipe < AbstractPipe
|
|
3
|
+
attr_reader :starts
|
|
4
|
+
|
|
5
|
+
def setStarts(starts)
|
|
6
|
+
@starts = starts
|
|
7
|
+
end
|
|
8
|
+
alias set_starts setStarts
|
|
9
|
+
|
|
10
|
+
def reset
|
|
11
|
+
super
|
|
12
|
+
@starts.reset if starts.respond_to? :reset
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
def getPathToHere
|
|
18
|
+
if starts.respond_to? :getPath
|
|
19
|
+
starts.getPath
|
|
20
|
+
else
|
|
21
|
+
java.util.ArrayList.new
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|