TinkerPop中的遍历:图的遍历中谓词、栅栏、范围和Lambda的说明
关于谓词的注意事项
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\
==>true
gremlin> 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\
==>2
gremlin> g.V().has('name','marko').out('knows').fold().count() //2\
==>1
gremlin> g.V().has('name','marko').out('knows').fold().count(local) //3\
==>2
gremlin> 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
==>lop
gremlin> g.V().has('name','marko').out('created').values('name') //不使用Lambda
==>lop
建议用户当且仅当所需功能只有lambda表达式时,才使用lambda表达式。原因是,lambda不能被Gremlin的编译策略优化,因为它们不能被程序检查(参见遍历策略)。
注意,目前(截止0.2.0版本)还不能在Gremlin-Server上执行远程发来的lambda,也没有支持远程执行的驱动程序。
TinkerPop中的遍历:图的遍历中谓词、栅栏、范围和Lambda的说明的更多相关文章
- iReport 中使用 Chart 图
iReport 中使用 Chart 图 SSH2项目中需要引入如下两个jar包: jfreechart-1.0.12.jar jcommon-1.0.15.jar 从 iReport 的安装目录下搜索 ...
- TinkerPop中的遍历:图的遍历策略
遍历策略 一个TraversalStrategy分析一个遍历,如果遍历符合它的标准,可以相应地改变它.遍历策略在编译时被执行,并构成Gremlin遍历机的编译器的基础.有五类策略分列如下: decor ...
- TinkerPop中的遍历:图的遍历步骤(3/3)
48 Project Step project() 步骤(map)将当前对象投射到由提供的标签键入的Map<String,Object>中. gremlin> g.V().out(' ...
- TinkerPop中的遍历:图的遍历步骤(1/3)
图遍历步骤(Graph Traversal Steps) 在最一般的层次上,Traversal<S,E>实现了Iterator,S代表起点,E代表结束.遍历由四个主要组成部分组成: Ste ...
- Java中关于HashMap的元素遍历的顺序问题
Java中关于HashMap的元素遍历的顺序问题 今天在使用如下的方式遍历HashMap里面的元素时 1 for (Entry<String, String> entry : hashMa ...
- 二叉树 Java 实现 前序遍历 中序遍历 后序遍历 层级遍历 获取叶节点 宽度 ,高度,队列实现二叉树遍历 求二叉树的最大距离
数据结构中一直对二叉树不是很了解,今天趁着这个时间整理一下 许多实际问题抽象出来的数据结构往往是二叉树的形式,即使是一般的树也能简单地转换为二叉树,而且二叉树的存储结构及其算法都较为简单,因此二叉树显 ...
- [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...
- Jquery中each的三种遍历方法
Jquery中each的三种遍历方法 $.post("urladdr", { "data" : "data" }, function(dat ...
- 关于js中的for(var in)遍历属性报错问题
之前遇到过这个问题,但是没找到问题的所在,将for(var i in array){} 改成了for(var i ;i<array.length;i++)循环,但是今天又遇到了,mark一下错 ...
- OC中几种集合的遍历方法(数组遍历,字典遍历,集合遍历)
// 先分别初始化数组.字典和集合,然后分别用for循环.NSEnumerator枚举器和forin循环这三个方法来实现遍历 NSArray *array = @[@"yinhao" ...
随机推荐
- Shiro-从数据表中初始化资源和权限
我们在 applicationContext中配置受保护的资源和权限的关系 <property name="filterChainDefinitions"> <v ...
- Operating System-进程间互斥的问题-生产者&&消费者引入
之前介绍的几种解决进程间互斥的方案,不管是Peterson方案还是TSL指令的方式,都有一个特点:当一个进程被Block到临界区外面时,被Block的进程会一直处于忙等待的状态,这个不但浪费了CPU资 ...
- poj 2115 C Looooops——exgcd模板
题目:http://poj.org/problem?id=2115 exgcd裸题.注意最后各种%b.注意打出正确的exgcd板子.就是别忘了/=g. #include<iostream> ...
- 通过扫码自定义链接安装iOS app,版本更新总结。
1.打包ipa,plist工具:xcode6证书:企业级开发证书 1.1)xcode6开始企业级打包时不在生成plist,需要自己编写:模版见下: <?xml version="1.0 ...
- Jlink flash 烧录HEX 程序
一般Jlink版本 和 Jag(硬件)最好匹配 安装Jlink 时,IAR的工具包也可以顺带安装. 有源码: IAR 可以自动选择CPU型号,代码直接Download and debug https: ...
- DataGridView上下方向键定位
/// <summary> /// DataGridView上下方向键定位 /// </summary> /// <param name="dgv"& ...
- [Chapter 3 Process]Practice 3.1 相关知识:进程创建、fork函数
3.1 Using the program shown in the Figure3.30, explain what the output will be at LINE A 答案:LINE A 处 ...
- 第八章 Java中的并发工具类
等待多线程完成的CountDownLatch countDownLatch允许一个或多个线程等待其他线程完成操作. public class CountDownLatchTest { static C ...
- 用命令查看端口占用情况 netstat -ano
查看所有端口 netstat -ano 可以看到进程ID 参考某个具体端口,第五列就是PID进程ID了. netstat -aon|findstr "80"
- NSThread 基本使用
一.简介 (1)使用NSThread对象建立一个线程非常方便 (2)但是!要使用NSThread管理多个线程非常困难,不推荐使用 (3)技巧!使用[NSThreadcurrentThread]跟踪任务 ...