在Tinkerpop 3中,如何进行分页?我想获取查询的前10个元素,然后接下来的10个元素而不必将它们全部加载到内存中.例如,下面的查询返回1000,000条记录.我想在不加载所有1000,000的情况下以10×10的速度获取它们.
g.V().has("key", value).limit(10)
Run Code Online (Sandbox Code Playgroud)
HttpChannelizer在Gremlin Server上运行的解决方案将是理想的选择.
我想删除两个顶点之间的边,所以我的代码在java tinkerpop3中如下
private void removeEdgeOfTwoVertices(Vertex fromV, Vertex toV,String edgeLabel,GraphTraversalSource g){
if(g.V(toV).inE(edgeLabel).bothV().hasId(fromV.id()).hasNext()){
List<Edge> edgeList = g.V(toV).inE(edgeLabel).toList();
for (Edge edge:edgeList){
if(edge.outVertex().id().equals(fromV.id())) {
TitanGraph().tx();
edge.remove();
TitanGraph().tx().commit();
return;//Remove edge ok, now return.
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否有更简单的方法通过直接查询到该边缘并删除它来删除两个顶点之间的边缘?谢谢您帮忙.
我试图理解条件插入的这种模式是如何工作的:
g.V()
.hasLabel('person').has('name', 'John')
.fold()
.coalesce(
__.unfold(),
g.addV('person').property('name', 'John')
).next();
Run Code Online (Sandbox Code Playgroud)
折叠/展开的目的是什么?为什么这些是必要的,为什么这不起作用:
g.V()
.coalesce(
__.hasLabel('person').has('name', 'John'),
g.addV('person').property('name', 'John')
).next();
Run Code Online (Sandbox Code Playgroud)
折叠然后展开的模式对我来说似乎是多余的,但上述情况并没有产生相同的结果.
我正在尝试使用Java中的Tinkerpop3作为客户端从已经运行的TitanDB服务器获取Graph对象(我不想创建服务器).
换句话说,我正在尝试实现这样的功能:public Graph obtainGraph(String serverIp,String graphName);
我试图像这样做: AWS Lambda + Tinkerpop/Gremlin + TitanDB on EC2 + AWS DynamoDB in cloud
但据我了解,TitanFactory.open()启动服务器,我不想这样做 - 我只想连接到现有的服务器.
文档以及Internet中的大多数材料使用内存中的图表作为示例,我找不到一个,它显示了如何:
创建新图并将其保存在远程服务器上
从远程服务器检索现有图
更新这样的远程Graph,所以在添加/删除边缘后提交更改
删除整个图表
我不想通过Gremlin语言(字符串)来做上述事情,而是通过Java API(TinkerpopBlueprins).这个人正在接近我需要的东西: 在Java中将顶点添加到TitanDB Graph 但是,他的方法已经将Graph作为参数.
我在Internet的很多地方都看到过,GraphFactory.open()获取了属性文件的路径,但是我还没有看到这种文件内容的例子,尤其是TitanDB的相关数据,所以我更喜欢使用Configuration对象.
图形图形= GraphFactory.open(new BaseConfiguration())
说,没有gremlin.graph属性.
配置配置= new BaseConfiguration(); configuration.setProperty("gremlin.graph","titan");
图形图形= GraphFactory.open(配置);
说GraphFactory无法找到[titan] - 确保jar在类路径中
是否有任何静态类型的构建器,其中包含枚举和常量,而不是Map,它将告诉我,我必须提供哪些属性以及它们的类型是什么?是否有任何开源项目,使用Tinkerpop3作为客户端连接到远程TitanDB服务器,我可以用作例子吗?
我希望看到完整的工作示例,而不是内存与外部配置.
我有一个足够简单的任务来完成:设置特定边缘属性的权重.以此场景为例:
我想做的是更新值weight.
其他要求
typeJoey和Pizza之间不能存在多个"吃" 的"吃"的边缘.我有以下信息:
我想我需要做类似以下的事情:
votes_for为type"吃"的所有外围边缘(应该最多1个)和标记为"吃饭"的具有name"披萨" 的外出顶点.weight边缘的值.这就是我在代码中乱搞的东西:
//vertex is Joey in this case
g.V(vertex.id())
.outE("votes_for")
.has("type", "eat")
//... how do I filter by .outV so that I can check for "pizza"?
.property(Cardinality.single, "weight", 0.99);
//... what do I …Run Code Online (Sandbox Code Playgroud) 我正在阅读TinkerPop3 文档
我很困惑的是我找不到任何解释next().
例如,w/next()或w/o next()返回相同的椎骨
gremlin> g.V().has('name', 'marko')
==>v[1]
gremlin> g.V().has('name', 'marko').next()
==>v[1]
Run Code Online (Sandbox Code Playgroud)
但是,班级名称彼此不同.
gremlin> g.V().has('name', 'marko').getClass()
==>class org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal
gremlin> g.V().has('name', 'marko').next().getClass()
==>class org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex
Run Code Online (Sandbox Code Playgroud)
没有'next()',指定的变量没有值.
gremlin> marko = g.V().has('name', 'marko')
==>v[1]
gremlin> marko
Run Code Online (Sandbox Code Playgroud)
甚至,与clockWithResult()输出完全不同.
gremlin> clockWithResult(1){g.V().both().barrier().both().barrier().both().barrier().count().next()}
==>1.079524
==>72
gremlin> clockWithResult(1){g.V().both().barrier().both().barrier().both().barrier().count()}
==>0.11863599999999999
==>[GraphStep([],vertex), VertexStep(BOTH,vertex), NoOpBarrierStep(2147483647), VertexStep(BOTH,vertex), NoOpBarrierStep(2147483647), VertexStep(BOTH,vertex), NoOpBarrierStep(2147483647), CountGlobalStep]
Run Code Online (Sandbox Code Playgroud)
或者这个例子:
gremlin> g.V(1).out('knows').values('name').fold()
==>[vadas, josh]
gremlin> g.V(1).out('knows').values('name').fold().next()
==>vadas
==>josh
Run Code Online (Sandbox Code Playgroud)
在手册中,还有许多其他例子让我感到困惑.
我希望马尔科和他的朋友能帮助我.
我知道这次被问了几次,但我没有找到关于Tinkerpop(3.1)的最新版本的任何参考,其中包含许多我们可以在遍历中使用的新的有用函数.
假设我必须找到节点3和节点4之间的最短路径.这种遍历是否有声音?
g.V(3).repeat(out()).until(id().is(4).and().simplePath()).path().limit(1)
Run Code Online (Sandbox Code Playgroud)
这里我假设当我循环执行BFS搜索时(因此,第一个结果是最短路径),因为这似乎就是loop()函数的情况.
另外,有没有办法在步骤中包含先前绑定的变量(通过使用as步骤)until?更确切地说,我试图在遍历期间选择两个节点,然后找到它们之间的最短路径,例如,
g.V().match(
__as('e0').out('Feedbacks').as('e1'),
__as('e0').repeat(out('Meets')).until(<I reach e1>).path().<get_length>.as('len')
).select('e0', 'e1', 'len')
Run Code Online (Sandbox Code Playgroud)
最后,从前面的遍历中可以看出,我不清楚如何获得最短路径的长度.使用类似的东西
g.V(3).repeat(out()).until(id().is(4).and().simplePath()).path().size()
Run Code Online (Sandbox Code Playgroud)
返回结果的大小(返回的行数),而
g.V(3).repeat(out()).until(id().is(4).and().simplePath()).path().by(__size())
Run Code Online (Sandbox Code Playgroud)
返回错误.
这是我正在试验的图表,如果有人想要玩一下.
graph = TinkerGraph.open()
e0 = graph.addVertex(T.id, 0, label, "User", "name", "e0")
e1 = graph.addVertex(T.id, 1, label, "User", "name", "e1")
e2 = graph.addVertex(T.id, 2, label, "User", "name", "e2")
e3 = graph.addVertex(T.id, 3, label, "User", "name", "e3")
e4 = graph.addVertex(T.id, 4, label, "User", "name", "e4")
e0.addEdge("Feedbacks", e2)
e0.addEdge("Meets", e1)
e2.addEdge("Feedbacks", e4)
e2.addEdge("Meets", e4) …Run Code Online (Sandbox Code Playgroud) 我使用gremlin-console(janusgraph)远程连接到gremlin服务器,但是当我创建一个变量并访问它时,它不起作用.我的最终目标是使用gremlin-console创建索引...
gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server -
[localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin> a = "b"
==>b
gremlin> a
No such property: a for class: Script3
Type ':help' or ':h' for help.
Run Code Online (Sandbox Code Playgroud) 我有一组用户名(例如['abc','def','ghi'])要添加到图表中的"用户"标签下.
现在我首先要检查用户名是否已经存在(g.V().hasLabel('user').has('username','def')),然后仅添加"用户"标签下用户名属性不匹配的用户名.
此外,这可以在单个gremlin查询或groovy脚本中完成吗?
我正在使用titan graph数据库,tinkerpop3和gremlin REST服务器.
在现代图中,我想为每个人获取他创建的软件的名称和名称列表。所以我尝试了以下查询
g.V().hasLabel('person').project('personName','softwareNames').
by(values('name')).
by(out('created').values('name').aggregate('a').select('a'))
Run Code Online (Sandbox Code Playgroud)
但我得到了错误
The provided traverser does not map to a value: v[2]->[VertexStep(OUT,[created],vertex), PropertiesStep([name],value), AggregateStep(a), SelectOneStep(last,a)]
Run Code Online (Sandbox Code Playgroud)
问题似乎在于顶点2没有“创建”的边。
如果仅在具有至少一个“已创建”边缘的顶点上运行查询,则该查询有效,例如对于顶点4(“ V(4)”而不是“ V()”),结果为
==>[personName:josh,softwareNames:[ripple,lop]]
Run Code Online (Sandbox Code Playgroud)
如何获得顶点2的软件名称的空列表,而不是错误的列表?