pacer 0.9.1.1-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +4 -1
- data/.gitignore +4 -0
- data/.rspec +1 -1
- data/Gemfile-dev +33 -0
- data/Gemfile-release +4 -0
- data/README.md +27 -9
- data/Rakefile +26 -8
- data/bin/autotest +1 -1
- data/lib/pacer/blueprints/multi_graph.rb +7 -19
- data/lib/pacer/blueprints/ruby_graph.rb +77 -52
- data/lib/pacer/blueprints/tg.rb +6 -93
- data/lib/pacer/blueprints.rb +0 -1
- data/lib/pacer/core/graph/edges_route.rb +10 -12
- data/lib/pacer/core/graph/element_route.rb +14 -21
- data/lib/pacer/core/graph/graph_index_route.rb +12 -8
- data/lib/pacer/core/graph/graph_route.rb +2 -5
- data/lib/pacer/core/graph/mixed_route.rb +3 -5
- data/lib/pacer/core/graph/vertices_route.rb +26 -27
- data/lib/pacer/core/route.rb +35 -66
- data/lib/pacer/exceptions.rb +13 -6
- data/lib/pacer/extensions/block_filter_element.rb +0 -5
- data/lib/pacer/filter/collection_filter.rb +9 -2
- data/lib/pacer/filter/empty_filter.rb +12 -3
- data/lib/pacer/filter/future_filter.rb +5 -5
- data/lib/pacer/filter/loop_filter.rb +7 -13
- data/lib/pacer/filter/object_filter.rb +10 -16
- data/lib/pacer/filter/property_filter/filters.rb +134 -93
- data/lib/pacer/filter/property_filter.rb +22 -19
- data/lib/pacer/filter/where_filter/node_visitor.rb +47 -26
- data/lib/pacer/filter/where_filter.rb +24 -3
- data/lib/pacer/function_resolver.rb +7 -2
- data/lib/pacer/graph/graph_ml.rb +39 -0
- data/lib/pacer/graph/graph_transactions_mixin.rb +107 -175
- data/lib/pacer/graph/pacer_graph.rb +438 -0
- data/lib/pacer/graph/simple_encoder.rb +20 -0
- data/lib/pacer/graph/yaml_encoder.rb +81 -0
- data/lib/pacer/graph.rb +8 -10
- data/lib/pacer/pipe/blackbox_pipeline.rb +11 -4
- data/lib/pacer/pipe/block_filter_pipe.rb +5 -22
- data/lib/pacer/pipe/cross_product_transform_pipe.rb +5 -7
- data/lib/pacer/pipe/edges_pipe.rb +22 -0
- data/lib/pacer/pipe/enumerable_pipe.rb +3 -9
- data/lib/pacer/pipe/expandable_pipe.rb +2 -14
- data/lib/pacer/pipe/id_collection_filter_pipe.rb +2 -8
- data/lib/pacer/pipe/is_empty_pipe.rb +5 -12
- data/lib/pacer/pipe/is_unique_pipe.rb +3 -13
- data/lib/pacer/pipe/label_collection_filter_pipe.rb +1 -7
- data/lib/pacer/pipe/label_prefix_pipe.rb +0 -6
- data/lib/pacer/pipe/loop_pipe.rb +27 -25
- data/lib/pacer/pipe/never_pipe.rb +1 -1
- data/lib/pacer/pipe/path_wrapping_pipe.rb +40 -0
- data/lib/pacer/pipe/process_pipe.rb +2 -20
- data/lib/pacer/pipe/property_comparison_pipe.rb +0 -6
- data/lib/pacer/pipe/ruby_pipe.rb +10 -3
- data/lib/pacer/pipe/simple_visitor_pipe.rb +12 -11
- data/lib/pacer/pipe/stream_sort_pipe.rb +1 -7
- data/lib/pacer/pipe/stream_uniq_pipe.rb +0 -6
- data/lib/pacer/pipe/type_filter_pipe.rb +1 -7
- data/lib/pacer/pipe/unary_transform_pipe.rb +6 -8
- data/lib/pacer/pipe/unwrapping_pipe.rb +13 -0
- data/lib/pacer/pipe/vertices_pipe.rb +22 -0
- data/lib/pacer/pipe/visitor_pipe.rb +3 -7
- data/lib/pacer/pipe/wrapping_pipe.rb +37 -0
- data/lib/pacer/pipes.rb +17 -12
- data/lib/pacer/route/mixin/bulk_operations.rb +8 -9
- data/lib/pacer/route/mixin/route_operations.rb +17 -11
- data/lib/pacer/route/mixins.rb +0 -1
- data/lib/pacer/route.rb +198 -121
- data/lib/pacer/side_effect/aggregate.rb +22 -2
- data/lib/pacer/side_effect/as.rb +73 -0
- data/lib/pacer/side_effect/group_count.rb +0 -3
- data/lib/pacer/side_effect/is_unique.rb +7 -6
- data/lib/pacer/side_effect.rb +1 -1
- data/lib/pacer/support/enumerable.rb +14 -12
- data/lib/pacer/support/nil_class.rb +5 -0
- data/lib/pacer/support/proc.rb +2 -2
- data/lib/pacer/support.rb +1 -1
- data/lib/pacer/transform/cap.rb +1 -1
- data/lib/pacer/transform/has_count_cap.rb +1 -1
- data/lib/pacer/transform/join.rb +20 -16
- data/lib/pacer/transform/map.rb +6 -2
- data/lib/pacer/transform/path.rb +44 -20
- data/lib/pacer/transform/sort_section.rb +58 -51
- data/lib/pacer/utils/tsort.rb +7 -2
- data/lib/pacer/utils.rb +0 -1
- data/lib/pacer/version.rb +4 -3
- data/lib/pacer/visitors/section.rb +42 -0
- data/lib/pacer/visitors/visits_section.rb +32 -0
- data/lib/pacer/visitors.rb +7 -0
- data/lib/pacer/wrappers/edge_wrapper.rb +164 -11
- data/lib/pacer/wrappers/element_wrapper.rb +133 -8
- data/lib/pacer/wrappers/index_wrapper.rb +47 -0
- data/lib/pacer/wrappers/vertex_wrapper.rb +175 -12
- data/lib/pacer/wrappers/wrapper_selector.rb +40 -0
- data/lib/pacer/wrappers/wrapping_pipe_function.rb +90 -0
- data/lib/pacer/wrappers.rb +3 -1
- data/lib/pacer-1.0.0-standalone.jar +0 -0
- data/lib/pacer.rb +13 -47
- data/pacer.gemspec +0 -8
- data/pom.xml +10 -3
- data/spec/pacer/blueprints/dex_spec.rb +12 -26
- data/spec/pacer/blueprints/neo4j_spec.rb +14 -28
- data/spec/pacer/blueprints/tg_spec.rb +6 -54
- data/spec/pacer/core/graph/edges_route_spec.rb +1 -1
- data/spec/pacer/core/graph/element_route_spec.rb +2 -2
- data/spec/pacer/core/graph/graph_route_spec.rb +2 -2
- data/spec/pacer/core/graph/vertices_route_spec.rb +10 -3
- data/spec/pacer/core/route_spec.rb +35 -58
- data/spec/pacer/filter/empty_filter_spec.rb +5 -6
- data/spec/pacer/filter/future_filter_spec.rb +8 -8
- data/spec/pacer/filter/loop_filter_spec.rb +120 -6
- data/spec/pacer/filter/object_filter_spec.rb +15 -0
- data/spec/pacer/filter/property_filter/filters_spec.rb +169 -0
- data/spec/pacer/filter/property_filter_spec.rb +15 -12
- data/spec/pacer/filter/uniq_filter_spec.rb +1 -1
- data/spec/pacer/filter/where_filter_spec.rb +55 -7
- data/spec/pacer/graph/{graph_mixin_spec.rb → pacer_graph_spec.rb} +114 -185
- data/spec/pacer/route/mixin/base_spec.rb +36 -35
- data/spec/pacer/route/mixin/route_operations_spec.rb +4 -46
- data/spec/pacer/side_effect/as_spec.rb +34 -0
- data/spec/pacer/support/enumerable_spec.rb +6 -6
- data/spec/pacer/transform/join_spec.rb +7 -5
- data/spec/pacer/transform/map_spec.rb +55 -0
- data/spec/pacer/transform/path_spec.rb +30 -15
- data/spec/pacer/transform/process_spec.rb +42 -0
- data/spec/pacer/transform/sort_section_spec.rb +82 -0
- data/spec/pacer/wrapper/edge_wrapper_spec.rb +122 -2
- data/spec/pacer/wrapper/element_wrapper_spec.rb +289 -3
- data/spec/pacer/wrapper/vertex_wrapper_spec.rb +289 -2
- data/spec/spec_helper.rb +16 -7
- data/spec/support/graph_runner.rb +80 -29
- data/tags +1165 -0
- metadata +46 -107
- data/.rvmrc +0 -0
- data/lib/pacer/blueprints/extensions.rb +0 -77
- data/lib/pacer/graph/edge_mixin.rb +0 -127
- data/lib/pacer/graph/element_mixin.rb +0 -202
- data/lib/pacer/graph/graph_indices_mixin.rb +0 -93
- data/lib/pacer/graph/graph_mixin.rb +0 -361
- data/lib/pacer/graph/index_mixin.rb +0 -30
- data/lib/pacer/graph/vertex_mixin.rb +0 -119
- data/lib/pacer/pipe/map_pipe.rb +0 -36
- data/lib/pacer/pipe/variable_store_iterator_wrapper.rb +0 -26
- data/lib/pacer/route/mixin/variable_route_module.rb +0 -26
- data/lib/pacer/side_effect/section.rb +0 -25
- data/lib/pacer/support/iterator_mixins.rb +0 -110
- data/lib/pacer/wrappers/new_element.rb +0 -106
- data/lib/pacer-0.9.1.1-standalone.jar +0 -0
- data/spec/pacer/graph/edge_mixin_spec.rb +0 -116
- data/spec/pacer/graph/element_mixin_spec.rb +0 -297
- data/spec/pacer/graph/index_mixin_spec.rb +0 -0
- data/spec/pacer/graph/vertex_mixin_spec.rb +0 -192
@@ -24,17 +24,16 @@ module Pacer::Routes
|
|
24
24
|
target_graph.in_bulk_job = true
|
25
25
|
size ||= target_graph.bulk_job_size
|
26
26
|
counter = 0
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
yield element
|
34
|
-
end
|
27
|
+
target_graph.transaction do |commit, rollback|
|
28
|
+
each_slice(size) do |slice|
|
29
|
+
print counter if Pacer.verbose?
|
30
|
+
counter += size
|
31
|
+
slice.each do |element|
|
32
|
+
yield element
|
35
33
|
end
|
36
|
-
|
34
|
+
commit.call
|
37
35
|
end
|
36
|
+
print '.' if Pacer.verbose?
|
38
37
|
end
|
39
38
|
ensure
|
40
39
|
puts '!' if Pacer.verbose?
|
@@ -60,13 +60,6 @@ module Pacer::Routes
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
# Store the current intermediate element in the route's vars hash by the
|
64
|
-
# given name so that it is accessible subsequently in the processing of the
|
65
|
-
# route.
|
66
|
-
def as(name)
|
67
|
-
chain_route :modules => VariableRouteModule, :variable_name => name
|
68
|
-
end
|
69
|
-
|
70
63
|
# Returns true if this route could contain both vertices and edges.
|
71
64
|
def mixed_route?
|
72
65
|
self.is_a? Pacer::Core::Graph::MixedRoute
|
@@ -98,10 +91,23 @@ module Pacer::Routes
|
|
98
91
|
results
|
99
92
|
end
|
100
93
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
94
|
+
# Creates a terse, human-friendly name for the class based on its
|
95
|
+
# element type, function and info.
|
96
|
+
# @return [String]
|
97
|
+
def inspect_class_name
|
98
|
+
s = case element_type
|
99
|
+
when :vertex
|
100
|
+
'V'
|
101
|
+
when :edge
|
102
|
+
'E'
|
103
|
+
when :object
|
104
|
+
'Obj'
|
105
|
+
when :mixed
|
106
|
+
'Elem'
|
107
|
+
end
|
108
|
+
s = "#{s}-#{function.name.split('::').last.sub(/Filter|Route$/, '')}" if function
|
109
|
+
s = "#{s} #{ @info }" if @info
|
110
|
+
s
|
105
111
|
end
|
106
112
|
end
|
107
113
|
end
|
data/lib/pacer/route/mixins.rb
CHANGED
data/lib/pacer/route.rb
CHANGED
@@ -1,12 +1,155 @@
|
|
1
|
-
[Pacer::Core::Route, Pacer::
|
1
|
+
[Pacer::Core::Route, Pacer::Wrappers::ElementWrapper, Pacer::Wrappers::EdgeWrapper, Pacer::Wrappers::VertexWrapper].each do |klass|
|
2
2
|
klass.class_eval %{
|
3
3
|
def chain_route(args_hash)
|
4
|
-
Pacer::
|
4
|
+
Pacer::RouteBuilder.current.chain self, args_hash
|
5
5
|
end
|
6
6
|
}
|
7
7
|
end
|
8
8
|
|
9
9
|
module Pacer
|
10
|
+
|
11
|
+
class RouteBuilder
|
12
|
+
class << self
|
13
|
+
attr_writer :current
|
14
|
+
|
15
|
+
def current
|
16
|
+
@current ||= RouteBuilder.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :types
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@types = Hash.new do |h, type_def|
|
24
|
+
h[type_def] = Class.new(Route) do
|
25
|
+
type_def.each do |mods|
|
26
|
+
mods.each do |mod|
|
27
|
+
include mod
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def chain(source, args)
|
35
|
+
types[type_def(source, args)].new source, configuration(source, args), arguments(source, args)
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def source_value(source, name)
|
41
|
+
source.send name if source.respond_to? name
|
42
|
+
end
|
43
|
+
|
44
|
+
def type_def(source, args)
|
45
|
+
[
|
46
|
+
type_modules(source, args),
|
47
|
+
function_modules(source, args),
|
48
|
+
other_modules(source, args),
|
49
|
+
extension_modules(source, args)
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
def configuration(source, args)
|
54
|
+
{
|
55
|
+
element_type: element_type(source, args),
|
56
|
+
graph: graph(source, args),
|
57
|
+
extensions: extensions(source, args),
|
58
|
+
wrapper: wrapper(source, args),
|
59
|
+
function: function_modules(source, args).first
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def arguments(source, args)
|
64
|
+
args.reject do |key, val|
|
65
|
+
Set[:element_type, :wrapper, :extensions, :modules, :graph, :back, :filter, :side_effect, :transform, :visitor].include? key
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def graph(source, args)
|
70
|
+
args[:graph] || source_value(source, :graph)
|
71
|
+
end
|
72
|
+
|
73
|
+
def element_type(source, args)
|
74
|
+
et = args[:element_type] || source_value(source, :element_type)
|
75
|
+
if not et
|
76
|
+
fail ClientError, "No element_type specified or inferred"
|
77
|
+
end
|
78
|
+
if not graph(source, args) and (et == :vertex or et == :edge or et == :mixed)
|
79
|
+
fail ClientError, "Element type #{ et.inspect } specified, but no graph specified."
|
80
|
+
end
|
81
|
+
et
|
82
|
+
end
|
83
|
+
|
84
|
+
def type_modules(source, args)
|
85
|
+
case element_type source, args
|
86
|
+
when :vertex
|
87
|
+
[Pacer::Core::Graph::ElementRoute, Pacer::Core::Graph::VerticesRoute]
|
88
|
+
when :edge
|
89
|
+
[Pacer::Core::Graph::ElementRoute, Pacer::Core::Graph::EdgesRoute]
|
90
|
+
when :mixed
|
91
|
+
[Pacer::Core::Graph::ElementRoute, Pacer::Core::Graph::MixedRoute]
|
92
|
+
else
|
93
|
+
[]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def other_modules(source, args)
|
98
|
+
[*args[:modules]]
|
99
|
+
end
|
100
|
+
|
101
|
+
def type_from_source?(source, args)
|
102
|
+
element_type(source, args) == source_value(source, :element_type)
|
103
|
+
end
|
104
|
+
|
105
|
+
def wrapper(source, args)
|
106
|
+
args.fetch(:wrapper) do
|
107
|
+
source_value(source, :wrapper) if type_from_source? source, args
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def extensions(source, args)
|
112
|
+
exts = args.fetch(:extensions) do
|
113
|
+
source_value(source, :extensions) if type_from_source? source, args
|
114
|
+
end
|
115
|
+
if exts.is_a? Set
|
116
|
+
exts.to_a
|
117
|
+
elsif exts.is_a? Module
|
118
|
+
[exts]
|
119
|
+
elsif exts.is_a? Array
|
120
|
+
exts.uniq
|
121
|
+
else
|
122
|
+
[]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def all_extensions(source, args)
|
127
|
+
w = wrapper source, args
|
128
|
+
exts = extensions source, args
|
129
|
+
if w and exts
|
130
|
+
(w.extensions + exts).uniq
|
131
|
+
elsif w
|
132
|
+
w.extensions
|
133
|
+
elsif exts
|
134
|
+
exts
|
135
|
+
else
|
136
|
+
[]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def extension_modules(source, args)
|
141
|
+
all_extensions(source, args).uniq.select do |mod|
|
142
|
+
mod.respond_to?(:const_defined?) and mod.const_defined? :Route
|
143
|
+
end.map { |mod| mod::Route }
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def function_modules(source, args)
|
148
|
+
FunctionResolver.function(args).compact
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
10
153
|
# The base class for almost everything in Pacer. Every route is an
|
11
154
|
# instance of this class with a variety of modules mixed into the
|
12
155
|
# instance at runtime.
|
@@ -37,11 +180,33 @@ module Pacer
|
|
37
180
|
include Pacer::Core::Route
|
38
181
|
include Pacer::Routes::RouteOperations
|
39
182
|
|
40
|
-
|
41
|
-
|
183
|
+
attr_reader :config
|
184
|
+
|
185
|
+
def wrapper
|
186
|
+
config[:wrapper]
|
187
|
+
end
|
188
|
+
|
189
|
+
def extensions
|
190
|
+
config[:extensions]
|
191
|
+
end
|
192
|
+
|
193
|
+
def all_extensions
|
194
|
+
if wrapper
|
195
|
+
(wrapper.extensions + extensions).uniq
|
196
|
+
else
|
197
|
+
extensions
|
198
|
+
end
|
199
|
+
end
|
42
200
|
|
43
201
|
# The type of object that this route emits.
|
44
|
-
|
202
|
+
def element_type
|
203
|
+
config[:element_type]
|
204
|
+
end
|
205
|
+
|
206
|
+
# The function mixed into this instance
|
207
|
+
def function
|
208
|
+
config[:function]
|
209
|
+
end
|
45
210
|
|
46
211
|
# Additional info to include after the class name when generating a
|
47
212
|
# name for this route.
|
@@ -57,18 +222,18 @@ module Pacer
|
|
57
222
|
# Create a new route. It should be very rare that you would need to
|
58
223
|
# directly create a Route object.
|
59
224
|
#
|
60
|
-
# See {Core::Graph::GraphRoute} and {
|
225
|
+
# See {Core::Graph::GraphRoute} and {PacerGraph} for methods
|
61
226
|
# to build routes based on a graph.
|
62
227
|
#
|
63
|
-
# See {
|
64
|
-
# {
|
228
|
+
# See {ElementWrapper}, {VertexWrapper} and
|
229
|
+
# {EdgeWrapper} for methods to build routes based on an
|
65
230
|
# individual graph element.
|
66
231
|
#
|
67
232
|
# @see Core::Graph::GraphRoute
|
68
|
-
# @see
|
69
|
-
# @see
|
70
|
-
# @see
|
71
|
-
# @see
|
233
|
+
# @see PacerGraph
|
234
|
+
# @see ElementWrapper
|
235
|
+
# @see VertexWrapper
|
236
|
+
# @see EdgeWrapper
|
72
237
|
#
|
73
238
|
# See Pacer's {Enumerable#to_route} method to create a route based
|
74
239
|
# on an Array, a Set or any other Enumerable type.
|
@@ -104,125 +269,37 @@ module Pacer
|
|
104
269
|
# When the route object is fully initialized, the
|
105
270
|
# {#after_initialize} method is called to allow mixins to do any
|
106
271
|
# additional setup.
|
107
|
-
def initialize(
|
108
|
-
|
109
|
-
|
110
|
-
@extensions = Set[]
|
111
|
-
self.graph = args[:graph]
|
112
|
-
self.back = args[:back]
|
113
|
-
include_function args
|
114
|
-
set_element_type args
|
115
|
-
include_other_modules args
|
116
|
-
keys = args.keys - [:element_type, :modules, :graph, :back, :filter, :side_effect, :transform]
|
117
|
-
keys.each do |key|
|
118
|
-
send("#{key}=", args[key])
|
119
|
-
end
|
120
|
-
include_extensions args
|
121
|
-
after_initialize
|
122
|
-
rescue Exception => e
|
123
|
-
puts "Exception creating Route with #{ args.inspect }" if Pacer.verbose?
|
124
|
-
raise
|
125
|
-
end
|
126
|
-
|
127
|
-
protected
|
128
|
-
|
129
|
-
# Set the element type of this route and include the apropriate
|
130
|
-
# mixin to support the element type.
|
131
|
-
#
|
132
|
-
# @param [:vertex, :edge, :mixed, element type, Object] et the
|
133
|
-
# element type to use
|
134
|
-
def element_type=(et)
|
135
|
-
if graph
|
136
|
-
@element_type = graph.element_type(et)
|
137
|
-
if @element_type == graph.element_type(:vertex)
|
138
|
-
extend Pacer::Core::Graph::VerticesRoute
|
139
|
-
elsif @element_type == graph.element_type(:edge)
|
140
|
-
extend Pacer::Core::Graph::EdgesRoute
|
141
|
-
elsif @element_type == graph.element_type(:mixed)
|
142
|
-
extend Pacer::Core::Graph::MixedRoute
|
143
|
-
end
|
144
|
-
elsif et == :object or et == Object
|
145
|
-
@element_type = Object
|
272
|
+
def initialize(source, config, args)
|
273
|
+
if source.is_a? Route
|
274
|
+
@back = source
|
146
275
|
else
|
147
|
-
|
276
|
+
@source = source
|
148
277
|
end
|
149
|
-
|
150
|
-
|
151
|
-
# This callback may be overridden. Be sure to call super() though.
|
152
|
-
# @return ignored
|
153
|
-
def after_initialize
|
154
|
-
end
|
155
|
-
|
156
|
-
# Find the module for the function to include based on the :filter,
|
157
|
-
# :side_effect or :transform argument given to {#initialize} and
|
158
|
-
# extend this instance with it.
|
159
|
-
def include_function(args)
|
160
|
-
@function, extension = FunctionResolver.function(args)
|
161
|
-
self.extend extension if extension
|
162
|
-
self.extend function if function
|
163
|
-
end
|
164
|
-
|
165
|
-
# @return [Route, nil] the previous route in the chain
|
166
|
-
def back_object(args)
|
167
|
-
back || args[:back]
|
168
|
-
end
|
169
|
-
|
170
|
-
# Get element type from the previous route in the chain.
|
171
|
-
# @return [element type, nil]
|
172
|
-
def back_element_type(args)
|
173
|
-
b = back_object(args)
|
174
|
-
if b.respond_to? :element_type
|
175
|
-
b.element_type
|
176
|
-
end
|
177
|
-
end
|
278
|
+
@config = config
|
279
|
+
@args = args
|
178
280
|
|
179
|
-
|
180
|
-
|
181
|
-
# @raise [StandardError] if no element type can be found
|
182
|
-
def set_element_type(args)
|
183
|
-
if args[:element_type]
|
184
|
-
self.element_type = args[:element_type]
|
185
|
-
else
|
186
|
-
if bet = back_element_type(args)
|
187
|
-
self.element_type = bet
|
188
|
-
else
|
189
|
-
raise "No element_type specified or inferred"
|
190
|
-
end
|
281
|
+
args.each do |key, value|
|
282
|
+
send("#{key}=", value)
|
191
283
|
end
|
192
|
-
end
|
193
284
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
285
|
+
after_initialize
|
286
|
+
rescue Exception => e
|
287
|
+
begin
|
288
|
+
if Pacer.verbose?
|
289
|
+
puts "Exception #{ e.class } #{ e.message } ..."
|
290
|
+
puts "... creating #{ config.inspect } route"
|
291
|
+
puts "... with #{ args.inspect }"
|
201
292
|
end
|
293
|
+
rescue Exception
|
202
294
|
end
|
295
|
+
raise e
|
203
296
|
end
|
204
297
|
|
205
|
-
|
206
|
-
# previous route's element type is the same as the current route's
|
207
|
-
# element type and no extensions were explicitly set on this route.
|
208
|
-
def include_extensions(args)
|
209
|
-
if back_element_type(args) == self.element_type and not args.key? :extensions and not args.key? :wrapper
|
210
|
-
back_obj = back_object(args)
|
211
|
-
if not wrapper and extensions.none?
|
212
|
-
self.wrapper = back_obj.wrapper if back_obj.respond_to? :wrapper
|
213
|
-
self.extensions = back_obj.extensions if back_obj.respond_to? :extensions
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
298
|
+
protected
|
217
299
|
|
218
|
-
#
|
219
|
-
#
|
220
|
-
|
221
|
-
def inspect_class_name
|
222
|
-
s = "#{element_type.to_s.scan(/Elem|Obj|V|E/).last}"
|
223
|
-
s = "#{s}-#{function.name.split('::').last.sub(/Filter|Route$/, '')}" if function
|
224
|
-
s = "#{s} #{ @info }" if @info
|
225
|
-
s
|
300
|
+
# This callback may be overridden. Be sure to call super() though.
|
301
|
+
# @return ignored
|
302
|
+
def after_initialize
|
226
303
|
end
|
227
304
|
end
|
228
305
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Pacer
|
2
2
|
module Routes::RouteOperations
|
3
3
|
def aggregate(into = nil)
|
4
|
-
|
4
|
+
aggregate = ::Pacer::SideEffect::Aggregate
|
5
|
+
r = self
|
6
|
+
r = section(into, aggregate::ElementSet) if into.is_a? Symbol
|
7
|
+
r.chain_route :side_effect => aggregate, :into => into
|
5
8
|
end
|
6
9
|
end
|
7
10
|
|
@@ -10,7 +13,14 @@ module Pacer
|
|
10
13
|
import com.tinkerpop.pipes.sideeffect.AggregatePipe
|
11
14
|
import java.util.HashSet
|
12
15
|
|
13
|
-
|
16
|
+
include Pacer::Visitors::VisitsSection
|
17
|
+
|
18
|
+
attr_reader :into
|
19
|
+
|
20
|
+
def into=(name)
|
21
|
+
@into = name
|
22
|
+
self.section = name if name.is_a? Symbol
|
23
|
+
end
|
14
24
|
|
15
25
|
protected
|
16
26
|
|
@@ -26,6 +36,16 @@ module Pacer
|
|
26
36
|
pipe.setStarts end_pipe if end_pipe
|
27
37
|
pipe
|
28
38
|
end
|
39
|
+
|
40
|
+
class ElementSet < HashSet
|
41
|
+
def on_element(element)
|
42
|
+
add element
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset
|
46
|
+
clear
|
47
|
+
end
|
48
|
+
end
|
29
49
|
end
|
30
50
|
end
|
31
51
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Pacer
|
2
|
+
module Routes::RouteOperations
|
3
|
+
# Store the current intermediate element in the route's vars hash by the
|
4
|
+
# given name so that it is accessible subsequently in the processing of the
|
5
|
+
# route.
|
6
|
+
def as(name)
|
7
|
+
as = ::Pacer::SideEffect::As
|
8
|
+
section(name, as::SingleElementSet).chain_route :side_effect => as, :variable_name => name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module SideEffect
|
13
|
+
module As
|
14
|
+
class AsPipe < Pacer::Pipes::AbstractPipe
|
15
|
+
|
16
|
+
field_reader :starts
|
17
|
+
attr_accessor :vars
|
18
|
+
|
19
|
+
def initialize(pipe, vars, variable_name)
|
20
|
+
super()
|
21
|
+
setStarts pipe if pipe
|
22
|
+
@vars = vars
|
23
|
+
@variable_name = variable_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def getCurrentPath
|
27
|
+
starts.getCurrentPath
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def processNextStart
|
33
|
+
@vars[@variable_name] = starts.next
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
import java.util.HashSet
|
39
|
+
|
40
|
+
attr_accessor :variable_name
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def attach_pipe(pipe)
|
45
|
+
if element_type == :vertex or element_type == :edge or element_type == :mixed
|
46
|
+
wrapped = Pacer::Pipes::WrappingPipe.new graph, element_type, extensions
|
47
|
+
wrapped.setStarts pipe
|
48
|
+
as_pipe = AsPipe.new(wrapped, vars, variable_name)
|
49
|
+
unwrapped = Pacer::Pipes::UnwrappingPipe.new
|
50
|
+
unwrapped.setStarts as_pipe
|
51
|
+
unwrapped
|
52
|
+
else
|
53
|
+
AsPipe.new(pipe, vars, variable_name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def inspect_class_name
|
58
|
+
@variable_name.inspect
|
59
|
+
end
|
60
|
+
|
61
|
+
class SingleElementSet < HashSet
|
62
|
+
def on_element(element)
|
63
|
+
clear
|
64
|
+
add element
|
65
|
+
end
|
66
|
+
|
67
|
+
def reset
|
68
|
+
clear
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -15,17 +15,18 @@ module Pacer
|
|
15
15
|
module SideEffect
|
16
16
|
module IsUnique
|
17
17
|
def unique?
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
checked = Pacer::Pipes::IsUniquePipe.new
|
19
|
+
checked.setStarts pipe
|
20
|
+
checked.next while checked.unique?
|
21
|
+
false
|
22
|
+
rescue Pacer::EmptyPipe, java.util.NoSuchElementException
|
23
|
+
true
|
21
24
|
end
|
22
25
|
|
23
26
|
protected
|
24
27
|
|
25
28
|
def attach_pipe(end_pipe)
|
26
|
-
|
27
|
-
@pipe.setStarts(end_pipe) if end_pipe
|
28
|
-
@pipe
|
29
|
+
end_pipe
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
data/lib/pacer/side_effect.rb
CHANGED
@@ -4,8 +4,8 @@ module Pacer
|
|
4
4
|
end
|
5
5
|
|
6
6
|
require 'pacer/side_effect/aggregate'
|
7
|
+
require 'pacer/side_effect/as'
|
7
8
|
require 'pacer/side_effect/group_count'
|
8
9
|
require 'pacer/side_effect/is_unique'
|
9
10
|
require 'pacer/side_effect/counted'
|
10
|
-
require 'pacer/side_effect/section'
|
11
11
|
require 'pacer/side_effect/visitor'
|
@@ -35,20 +35,22 @@ module Enumerable
|
|
35
35
|
e = iter.next
|
36
36
|
end
|
37
37
|
end
|
38
|
-
rescue StopIteration
|
38
|
+
rescue StopIteration, Pacer::EmptyPipe, java.util.NoSuchElementException
|
39
39
|
hs
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_list
|
43
|
+
java.util.Arrays.asList *self
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_iterable
|
47
|
+
Pacer::Pipes::EnumerablePipe.new self
|
46
48
|
end
|
47
49
|
|
48
50
|
# NOTE: if this is a collection of wrapped vertices or edges, Java pipes
|
49
51
|
# may crash with something like:
|
50
52
|
#
|
51
|
-
# NativeException: java.lang.ClassCastException: org.jruby.RubyObject cannot be cast to com.tinkerpop.blueprints.
|
53
|
+
# NativeException: java.lang.ClassCastException: org.jruby.RubyObject cannot be cast to com.tinkerpop.blueprints.Element
|
52
54
|
#
|
53
55
|
# You can work around that by passing the option :unwrap => true or
|
54
56
|
# setting the :based_on parameter to a route that has extensions.
|
@@ -58,15 +60,15 @@ module Enumerable
|
|
58
60
|
else
|
59
61
|
based_on = opts[:based_on]
|
60
62
|
if opts[:unwrap] or based_on and (based_on.wrapper or based_on.extensions.any?) and based_on.is_a? Pacer::Core::Graph::ElementRoute
|
61
|
-
source = Pacer::
|
63
|
+
source = Pacer::RouteBuilder.current.chain(self, :element_type => :object).map { |e| e.element }
|
62
64
|
else
|
63
65
|
source = self
|
64
66
|
end
|
65
67
|
if based_on
|
66
|
-
Pacer::
|
68
|
+
Pacer::RouteBuilder.current.chain(source, :element_type => opts.fetch(:element_type, based_on.element_type), :graph => based_on.graph, :wrapper => based_on.wrapper, :extensions => based_on.extensions, :info => based_on.info, :route_name => opts[:route_name])
|
67
69
|
else
|
68
70
|
graph = opts[:graph] if opts[:graph]
|
69
|
-
Pacer::
|
71
|
+
Pacer::RouteBuilder.current.chain(source, :element_type => opts.fetch(:element_type, :object), :graph => graph, :wrapper => opts[:wrapper], :extensions => opts[:extensions], :info => opts[:info], :route_name => opts[:route_name])
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
@@ -80,7 +82,7 @@ module Enumerable
|
|
80
82
|
r.chain_route(:graph => based_on.graph,
|
81
83
|
:element_type => based_on.element_type,
|
82
84
|
:pipe_class => based_on.send(:id_pipe_class),
|
83
|
-
:pipe_args => [based_on.graph],
|
85
|
+
:pipe_args => [based_on.graph.blueprints_graph],
|
84
86
|
:route_name => 'lookup',
|
85
87
|
:extensions => based_on.extensions,
|
86
88
|
:wrapper => based_on.wrapper,
|
data/lib/pacer/support/proc.rb
CHANGED
@@ -7,10 +7,10 @@ class Proc
|
|
7
7
|
source = self
|
8
8
|
end
|
9
9
|
if based_on
|
10
|
-
Pacer::
|
10
|
+
Pacer::RouteBuilder.current.chain(source, :element_type => :mixed, :graph => based_on.graph, :extensions => based_on.extensions, :info => based_on.info)
|
11
11
|
else
|
12
12
|
graph = opts[:graph] if opts[:graph]
|
13
|
-
Pacer::
|
13
|
+
Pacer::RouteBuilder.current.chain(source, :element_type => (opts[:element_type] || :object), :graph => graph, :extensions => opts[:extensions], :info => opts[:info])
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|