TinkerPop中的遍历:图的遍历中谓词、栅栏、范围和Lambda的说明
来源:互联网 发布:hey软件 编辑:程序博客网 时间:2024/06/18 05:10
from:http://www.cnblogs.com/myitroad/p/7778500.html
关于谓词的注意事项
P
是Function<Object,Boolean>
形式的谓词。也就是说,给定一些对象,返回true或false。所提供的谓词在下表中概述,并用于各种步骤,例如has()
,where()
,is()
等。
Predicate| Description
--|--eq(object)
| Is the incoming object equal to the provided object?neq(object)
| Is the incoming object not equal to the provided object?lt(number)
| Is the incoming number less than the provided number?lte(number)
| Is the incoming number less than or equal to the provided number?gt(number)
| Is the incoming number greater than the provided number?gte(number)
| Is the incoming number greater than or equal to the provided number?inside(number,number)
| Is the incoming number greater than the first provided number and less than the second?outside(number,number)
| Is the incoming number less than the first provided number or greater than the second?between(number,number)
| Is the incoming number greater than or equal to the first provided number and less than the second?within(objects…)
| Is the incoming object in the array of provided objects?without(objects…)
| Is the incoming object not in the array of the provided objects?
除了表中的表达式外,还有比如not()
,test()
等,如下:
gremlin> not(neq(2)) //1\==>eq(2)gremlin> not(within('a','b','c')).test('d') //2\==>truegremlin> not(within('a','b','c')).test('a')==>false
Note
上述谓词表达式来自以下静态引入import static org.apache.tinkerpop.gremlin.process.traversal.P.*.
关于栅栏步骤的注意事项
Gremlin主要是一个懒惰的流处理语言。这意味着Gremlin在从遍历开始/头部获取更多数据之前,会尽其所能地完全处理当前在遍历管道中的任何遍历器。然而,在许多情况下,完全懒惰的计算是不可能的(或不切实际的)。当计算不是懒惰的时候,就存在一个“栅栏步骤”。有三种类型的障碍:
CollectingBarrierStep
如order()
,sample()
,aggregate()
,barrier()
等步骤。在步骤之前的所有遍历器被放入一个集合中,然后以某种方式(例如有序的)处理,然后将该集合一个一个地“流入(drained)”到下一个步骤。ReducingBarrierStep
如fold()
,count()
,sum()
,max()
,min()
等。在步骤之前的所有遍历器都被做“reduce”处理,并且一旦所有先前的遍历器被处理,一个单一的“reduced后的值(reduced value)”遍历器被发送到下一步。SupplyingBarrierStep
如cap()
。所有在这个步骤之前的遍历器被迭代(不处理),然后一些供应商(provided supplier)产生一个单一的遍历器来继续下一步。
在Gremlin OLAP中,在每个相邻顶点步骤的末尾可以引入一个栅栏。
关于范围的注意事项
范围枚举有两个常量:Scope.local和Scope.global。作用域决定作用域的特定步是与当前对象(本地)相关的,还是整个对象(全局)的整个对象流。
以下例子:
gremlin> g.V().has('name','marko').out('knows').count() //1\==>2gremlin> g.V().has('name','marko').out('knows').fold().count() //2\==>1gremlin> g.V().has('name','marko').out('knows').fold().count(local) //3\==>2gremlin> g.V().has('name','marko').out('knows').fold().count(global) //4\==>1
解释上述例子:
1、Marko知道两个人。
2、Marko的朋友列表被创建,因此,一个对象被计数(即单个列表)。
3、Marko的朋友列表被创建,并且本地计数产生该列表中的对象的数量。
4、count(global)
与count()
相同,因为大多数作用域步骤的默认行为是全局的。
- 支持范围的步骤
count()
dedup()
max()
mean()
min()
order()
range()
limit()
sample()
tail()
Lambdas的注意事项
Gremlin支持Lambda表达式,但是并不推荐使用。以下使用Lambda表达式与不用Lambda表达式进行相同查询的语法比较:
gremlin> g.V().filter{it.get().value('name') == 'marko'}. flatMap{it.get().vertices(OUT,'created')}. map {it.get().value('name')} // 使用Lambda==>lopgremlin> g.V().has('name','marko').out('created').values('name') //不使用Lambda==>lop
建议用户当且仅当所需功能只有lambda表达式时,才使用lambda表达式。原因是,lambda不能被Gremlin的编译策略优化,因为它们不能被程序检查(参见遍历策略)。
注意,目前(截止0.2.0版本)还不能在Gremlin-Server上执行远程发来的lambda,也没有支持远程执行的驱动程序。
- TinkerPop中的遍历:图的遍历中谓词、栅栏、范围和Lambda的说明
- TinkerPop中的遍历:图的遍历策略
- TinkerPop中的遍历:图的遍历策略
- TinkerPop中的遍历:图的遍历步骤(1/3)
- TinkerPop中的遍历:图的遍历步骤(2/3)
- TinkerPop中的遍历:图的遍历步骤(3/3)
- tinkerpop / gremlin图遍历简单示例
- uva11853 图 范围节点的处理和遍历
- 图的深度遍历和广度遍历
- 图的广度遍历和深度遍历
- 图的深度遍历和广度遍历
- 图的dfs遍历和bfs遍历
- 图的深度遍历和广度遍历
- 图的深度遍历和广度遍历
- 图的遍历(深度遍历和广度遍历)
- 图的遍历:深度优先遍历和广度优先遍历
- 树的遍历 有后序遍历和中序遍历建立二叉树,并输出层次遍历
- 二叉树的遍历:前序遍历、中序遍历和后序遍历
- SQL查询执行流程
- CMake Error: undefined reference to 'vtable for IDenoise'
- 代理模式
- Thingsboard
- MyEclipse配置Maven
- TinkerPop中的遍历:图的遍历中谓词、栅栏、范围和Lambda的说明
- 机器学习系列笔记(八)
- redis java 相关api
- POJ 2002.Squares
- Java 工具
- 在使用Recyclerview加载列表圆形图片时出现的滑动卡顿及图片混乱问题
- 计算机网络之文件传送协议FTP
- C# 获取文件的修改时间、访问时间、创建时间
- dijkstra algorithm 模板(showpath)