/
GremlinScalaPipeline.scala
332 lines (248 loc) · 13.1 KB
/
GremlinScalaPipeline.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package com.tinkerpop.gremlin.scala
import com.tinkerpop.gremlin.pipes.GremlinPipeline
import com.tinkerpop.gremlin.pipes.filter.{PropertyFilterPipe, LabelFilterPipe, IdFilterPipe}
import com.tinkerpop.gremlin.Tokens
import com.tinkerpop.gremlin.pipes.transform._
import com.tinkerpop.pipes.branch._
import com.tinkerpop.pipes.filter._
import java.util.{ArrayList, List => JList}
import com.tinkerpop.pipes.transform._
import com.tinkerpop.pipes.sideeffect._
import com.tinkerpop.pipes.util._
import java.util.{Map => JMap, List => JList}
import com.tinkerpop.blueprints.pgm._
import com.tinkerpop.pipes.{PipeFunction, Pipe, FunctionPipe}
/**Adds convenience methods to [[com.tinkerpop.gremline.pipes.GremlinPipeline]]. */
class GremlinScalaPipeline[S, E](s: S) extends GremlinPipeline[S, E](s) /*with Iterator[E]*/ {
/*def hasNext: Boolean = pipeline.hasNext
def next(): E = pipeline.next()*/
def out: GremlinScalaPipeline[S, Vertex] =
super.out().asInstanceOf[GremlinScalaPipeline[S, Vertex]]
def in: GremlinScalaPipeline[S, Vertex] =
super.in().asInstanceOf[GremlinScalaPipeline[S, Vertex]]
def paths: GremlinScalaPipeline[S, JList[_]] =
super.path().asInstanceOf[GremlinScalaPipeline[S, JList[_]]]
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copied from GremlinPipeline
def idFilter[F <: Element](id: Any, filter: FilterPipe.Filter): GremlinScalaPipeline[S, F] =
super.idFilter(id, filter).asInstanceOf[GremlinScalaPipeline[S, F]]
override def labelFilter(label: String, filter: FilterPipe.Filter): GremlinScalaPipeline[S, Edge] =
super.labelFilter(label, filter).asInstanceOf[GremlinScalaPipeline[S, Edge]]
def propertyFilter[F <: Element, T](key: String, filter: FilterPipe.Filter, value: T): GremlinScalaPipeline[S, F] =
super.propertyFilter(key, filter, value).asInstanceOf[GremlinScalaPipeline[S, F]]
def propertyFilter[F <: Element, T](key: String, t: Tokens.T, value: T): GremlinScalaPipeline[S, F] =
super.propertyFilter(key, t, value).asInstanceOf[GremlinScalaPipeline[S, F]]
override def bothE(labels: String*): GremlinScalaPipeline[S, Edge] =
super.bothE(labels: _*).asInstanceOf[GremlinScalaPipeline[S, Edge]]
override def both(labels: String*): GremlinScalaPipeline[S, Vertex] =
super.both(labels: _*).asInstanceOf[GremlinScalaPipeline[S, Vertex]]
override def bothV: GremlinScalaPipeline[S, Vertex] =
super.bothV.asInstanceOf[GremlinScalaPipeline[S, Vertex]]
override def E: GremlinScalaPipeline[S, Edge] =
super.E.asInstanceOf[GremlinScalaPipeline[S, Edge]]
override def idEdge(graph: Graph): GremlinScalaPipeline[S, Edge] =
super.idEdge(graph).asInstanceOf[GremlinScalaPipeline[S, Edge]]
override def id: GremlinScalaPipeline[S, Object] =
super.id.asInstanceOf[GremlinScalaPipeline[S, Object]]
override def idVertex(graph: Graph): GremlinScalaPipeline[S, Vertex] =
super.idVertex(graph).asInstanceOf[GremlinScalaPipeline[S, Vertex]]
override def inE(labels: String*): GremlinScalaPipeline[S, Edge] =
super.inE(labels: _*).asInstanceOf[GremlinScalaPipeline[S, Edge]]
override def in(labels: String*): GremlinScalaPipeline[S, Vertex] =
super.in(labels: _*).asInstanceOf[GremlinScalaPipeline[S, Vertex]]
override def inV: GremlinScalaPipeline[S, Vertex] =
super.inV.asInstanceOf[GremlinScalaPipeline[S, Vertex]]
override def label: GremlinScalaPipeline[S, String] =
super.label.asInstanceOf[GremlinScalaPipeline[S, String]]
override def outE(labels: String*): GremlinScalaPipeline[S, Edge] =
super.outE(labels: _*).asInstanceOf[GremlinScalaPipeline[S, Edge]]
override def out(labels: String*): GremlinScalaPipeline[S, Vertex] =
super.out(labels: _*).asInstanceOf[GremlinScalaPipeline[S, Vertex]]
override def outV: GremlinScalaPipeline[S, Vertex] =
super.outV.asInstanceOf[GremlinScalaPipeline[S, Vertex]]
def map[F <: Element]: GremlinScalaPipeline[S, JMap[String, Object]] = //TODO use scala Map here?
super.map.asInstanceOf[GremlinScalaPipeline[S, JMap[String, Object]]]
def property[F <: Element](key: String): GremlinScalaPipeline[S, Object] =
super.property(key).asInstanceOf[GremlinScalaPipeline[S, Object]]
override def V: GremlinScalaPipeline[S, Vertex] =
super.V.asInstanceOf[GremlinScalaPipeline[S, Vertex]]
override def index[F <: Element](index: Index[F], key: String, value: Object): GremlinScalaPipeline[S, F] =
super.index(index, key, value).asInstanceOf[GremlinScalaPipeline[S, F]]
/********************************************/
/********************************************/
/**
* ****************************************
*/
def step[F](f: E => F): GremlinScalaPipeline[S, F] =
super.step(f).asInstanceOf[GremlinScalaPipeline[S, F]]
def step[F](pipe: Pipe[E, F]): GremlinScalaPipeline[S, F] =
super.step(pipe).asInstanceOf[GremlinScalaPipeline[S, F]]
////////////////////
/// BRANCH PIPES ///
////////////////////
override def copySplit(pipes: Pipe[_, _]*): GremlinScalaPipeline[S, E] =
super.copySplit(pipes: _*).asInstanceOf[GremlinScalaPipeline[S, E]]
override def exhaustMerge(pipes: Pipe[_, _]*): GremlinScalaPipeline[S, E] =
super.exhaustMerge(pipes: _*).asInstanceOf[GremlinScalaPipeline[S, E]]
override def exhaustMerge: GremlinScalaPipeline[S, E] =
super.exhaustMerge.asInstanceOf[GremlinScalaPipeline[S, E]]
override def fairMerge(pipes: Pipe[_, _]*): GremlinScalaPipeline[S, E] =
super.fairMerge(pipes: _*).asInstanceOf[GremlinScalaPipeline[S, E]]
override def fairMerge: GremlinScalaPipeline[S, E] =
super.fairMerge.asInstanceOf[GremlinScalaPipeline[S, E]]
def ifThenElse(ifFunction: S => Boolean, thenFunction: S => _, elseFunction: S => _): GremlinScalaPipeline[S, E] =
super.ifThenElse(ifFunction, thenFunction, elseFunction).asInstanceOf[GremlinScalaPipeline[S, E]]
def loop(numberedStep: Int, whileFunction: _ => Boolean): GremlinScalaPipeline[S, E] =
super.loop(numberedStep, whileFunction).asInstanceOf[GremlinScalaPipeline[S, E]]
def loop(namedStep: String, whileFunction: _ => Boolean): GremlinScalaPipeline[S, E] =
super.loop(namedStep, whileFunction).asInstanceOf[GremlinScalaPipeline[S, E]]
def loop(pipe: Pipe[E, E], whileFunction: _ => Boolean): GremlinScalaPipeline[S, E] =
super.loop(pipe, whileFunction).asInstanceOf[GremlinScalaPipeline[S, E]]
////////////////////
/// FILTER PIPES ///
////////////////////
/* def and(pipes: Pipe[_, Boolean]*): GremlinPipeline[S, E] = {
return this.add(new AndFilterPipe[_](pipes))
}
def back(numberedStep: Int): GremlinPipeline[S, _] = {
return this.add(new BackFilterPipe[_](new Pipeline[_, _](FluentUtility.removePreviousPipes(this, numberedStep))))
}
def back(namedStep: String): GremlinPipeline[S, _] = {
return this.add(new BackFilterPipe[_](new Pipeline[_, _](FluentUtility.removePreviousPipes(this, namedStep))))
}
def back(pipe: Pipe[_, _]): GremlinPipeline[S, _] = {
return this.add(new BackFilterPipe[_](pipe))
}
def dedup: GremlinPipeline[S, E] = {
return this.add(new DuplicateFilterPipe[_])
}
def except(collection: Collection[_]): GremlinPipeline[S, E] = {
return this.add(new ExceptFilterPipe[_](collection))
}
def filter(filterFunction: PipeFunction[_, Boolean]): GremlinPipeline[S, E] = {
return this.add(new FilterFunctionPipe[_](filterFunction))
}
def objectFilter(`object` : AnyRef, filter: FilterPipe.Filter): GremlinPipeline[S, E] = {
return this.add(new ObjectFilterPipe[_](`object`, filter))
}
def or(pipes: Pipe[S, Boolean]*): GremlinPipeline[S, E] = {
return this.add(new OrFilterPipe[_](pipes))
}
def random(bias: Double): GremlinPipeline[S, E] = {
return this.add(new RandomFilterPipe[_](bias))
}
def range(low: Int, high: Int): GremlinPipeline[S, E] = {
return this.add(new RangeFilterPipe[_](low, high))
}
def retain(collection: Collection[_]): GremlinPipeline[S, E] = {
return this.add(new RetainFilterPipe[_](collection))
}
def simplePath: GremlinPipeline[S, E] = {
return this.add(new CyclicPathFilterPipe[_])
}
/////////////////////////
/// SIDE-EFFECT PIPES ///
/////////////////////////
def aggregate(aggregate: Collection[_]): GremlinPipeline[S, E] = {
return this.add(new AggregatePipe[_](aggregate))
}
def aggregate(aggregate: Collection[_], aggregateFunction: PipeFunction[_, _]): GremlinPipeline[S, E] = {
return this.add(new AggregatePipe[_](aggregate, aggregateFunction))
}
def aggregate: GremlinPipeline[S, E] = {
return this.aggregate(new ArrayList[_])
}
def aggregate(aggregateFunction: PipeFunction[_, _]): GremlinPipeline[S, E] = {
return this.aggregate(new ArrayList[_], aggregateFunction)
}
def optional(numberedStep: Int): GremlinPipeline[S, _] = {
return this.add(new OptionalPipe[_](new Pipeline[_, _](FluentUtility.removePreviousPipes(this, numberedStep))))
}
def optional(namedStep: String): GremlinPipeline[S, _] = {
return this.add(new OptionalPipe[_](new Pipeline[_, _](FluentUtility.removePreviousPipes(this, namedStep))))
}
def optional(pipe: Pipe[_, _]): GremlinPipeline[S, _] = {
return this.add(new OptionalPipe[_](pipe))
}
def groupCount(map: Map[_, Number], keyFunction: PipeFunction[_, _], valueFunction: PipeFunction[Number, Number]): GremlinPipeline[S, E] = {
return this.add(new GroupCountFunctionPipe[_, _](map, keyFunction, valueFunction))
}
def groupCount(keyFunction: PipeFunction[_, _], valueFunction: PipeFunction[Number, Number]): GremlinPipeline[S, E] = {
return this.add(new GroupCountFunctionPipe[_, _](keyFunction, valueFunction))
}
def groupCount(map: Map[_, Number], keyFunction: PipeFunction[_, _]): GremlinPipeline[S, E] = {
return this.add(new GroupCountFunctionPipe[_, _](map, keyFunction, null))
}
def groupCount(keyFunction: PipeFunction[_, _]): GremlinPipeline[S, E] = {
return this.add(new GroupCountFunctionPipe[_, _](keyFunction, null))
}
def groupCount(map: Map[_, Number]): GremlinPipeline[S, E] = {
return this.add(new GroupCountPipe[_](map))
}
def groupCount: GremlinPipeline[S, E] = {
return this.add(new GroupCountPipe[_])
}
def sideEffect(sideEffectFunction: PipeFunction[_, _]): GremlinPipeline[S, E] = {
return this.add(new SideEffectFunctionPipe[_](sideEffectFunction))
}
def table(table: Table, stepNames: Collection[String], columnFunctions: PipeFunction[_, _]*): GremlinPipeline[S, E] = {
return this.add(new TablePipe[_](table, stepNames, FluentUtility.getAsPipes(this), columnFunctions))
}
def table(table: Table, columnFunctions: PipeFunction[_, _]*): GremlinPipeline[S, E] = {
return this.add(new TablePipe[_](table, null, FluentUtility.getAsPipes(this), columnFunctions))
}
def table(table: Table): GremlinPipeline[S, E] = {
return this.add(new TablePipe[_](table, null, FluentUtility.getAsPipes(this)))
}
def table: GremlinPipeline[S, E] = {
return this.add(new TablePipe[_](new Table, null, FluentUtility.getAsPipes(this)))
}
///////////////////////
/// TRANSFORM PIPES ///
///////////////////////
def gather: GremlinPipeline[S, List[_]] = {
return this.add(new GatherPipe[_])
}
def gather(function: PipeFunction[List[_], _]): GremlinPipeline[S, _] = {
this.addPipe(new GatherPipe[_])
return this.add(new TransformFunctionPipe[_, _](function))
}
def _: GremlinPipeline[S, E] =
{
return this.add(new IdentityPipe[_])
}
def memoize(namedStep: String): GremlinPipeline[S, E] = {
return this.add(new MemoizePipe[_, _](new Pipeline[_, _](FluentUtility.removePreviousPipes(this, namedStep))))
}
def memoize(numberedStep: Int): GremlinPipeline[S, E] = {
return this.add(new MemoizePipe[_, _](new Pipeline[_, _](FluentUtility.removePreviousPipes(this, numberedStep))))
}
def memoize(namedStep: String, map: Map[_, _]): GremlinPipeline[S, E] = {
return this.add(new MemoizePipe[_, _](new Pipeline[_, _](FluentUtility.removePreviousPipes(this, namedStep)), map))
}
def memoize(numberedStep: Int, map: Map[_, _]): GremlinPipeline[S, E] = {
return this.add(new MemoizePipe[_, _](new Pipeline[_, _](FluentUtility.removePreviousPipes(this, numberedStep)), map))
}*/
override def path(pathFunctions: PipeFunction[_, _]*): GremlinScalaPipeline[S, JList[_]] =
super.path(pathFunctions: _*).asInstanceOf[GremlinScalaPipeline[S, JList[_]]]
/*def scatter: GremlinPipeline[S, _] = {
return this.add(new ScatterPipe[_, _])
}
def cap: GremlinPipeline[S, _] = {
return this.add(new SideEffectCapPipe[_, _](FluentUtility.removePreviousPipes(this, 1).get(0).asInstanceOf[SideEffectPipe[_, _]]))
}*/
def transform[F](function: PipeFunction[E, F]): GremlinScalaPipeline[S, F] =
super.transform(function).asInstanceOf[GremlinScalaPipeline[S, F]]
//////////////////////
/// UTILITY PIPES ///
//////////////////////
/*def as(name: String): GremlinPipeline[S, E] = {
return this.add(new AsPipe[_, _](name, FluentUtility.removePreviousPipes(this, 1).get(0)))
}
def start(starts: AnyRef): GremlinPipeline[S, E] = {
this.add(new StartPipe[_](starts))
FluentUtility.setStarts(this, starts)
return this
}
*/
}