标签: gremlin

通过java驱动在DSE-5.0.5中一次性添加多个顶点和多条边

请告诉一个简单的解决方案,因为我有数百万个节点,所以需要更少的时间:

  for(int i=1100000; i<=1200000;i++){
        GraphStatement q1 = new SimpleGraphStatement("g.addV(label, 'Asset','name','Asset"+i+"','type','"+1+"').as('a')").setGraphName("lookingglass");

    System.out.println("Added node----"+i);
    }

 for(int i=1100000;i<=1200000;i++){
        //int j=i+1;
    Vertex v1 = dseSession.executeGraph("g.V().has('name','Org"+1000+"')").one().asVertex();
    Vertex v2 = dseSession.executeGraph("g.V().has('name','Asset"+i+"')").one().asVertex();

    SimpleGraphStatement s = new SimpleGraphStatement(
            "def v1 = g.V(id1).next()\n" +
                    "def v2 = g.V(id2).next()\n" +
                    "v1.addEdge('HAS', v2)")
            .set("id1", v1)
            .set("id2", v2);

    dseSession.executeGraph(s);
    System.out.println("Added Edge "+i);
    }
    System.out.println("Done");
Run Code Online (Sandbox Code Playgroud)

由于我正在进行整个图搜索,这需要更长的时间。我们是否可以有一个简单的单个查询来添加一个 vartex 并将一条边从该查询添加到现有顶点,从而减少延迟?

注意我也尝试过以下方法,但以下方法似乎已被废弃,因此给出错误(Vertex 不支持用户提供的标识符:

 g.addV().property(id, "A").as("a").
      addV().property(id, "B").property("value", 100).as("b").
      addV().property(id, "C").property("value", 200).as("c").
      addV().property(id, "D").property("value", 500).as("d").
      addV().property(id, "E").property("value", 1000).as("e").
      addV().property(id, "Z").property("value", 900).as("z").
      addE("link").from("a").to("b").property("weight", 80).
      addE("link").from("a").to("c").property("weight", 20).
      addE("link").from("b").to("d").property("weight", 50). …
Run Code Online (Sandbox Code Playgroud)

cassandra gremlin datastax-enterprise tinkerpop3 datastax-enterprise-graph

0
推荐指数
1
解决办法
245
查看次数

gremlin-python 在一笔事务中删除多个顶点和边

我的背景:

  • gremlin-python
  • AWS 海王星

我的问题是:

1) 如果我拥有要删除的顶点和边的所有特定 id,我可以在一笔事务中递归地删除顶点和边吗?目的是编写 python 函数来评估每个边,并确定是否需要删除它,并链接一个 gremlin 查询来删除它。

例如:

要删除的顶点 ID:

'vertex1', 'vertex2', 'vertex3'
Run Code Online (Sandbox Code Playgroud)

要删除的边 id:

'edge1', 'edge2', 'edge3'
Run Code Online (Sandbox Code Playgroud)

链接到 g 的 python 函数的示例如下:

def chain_drop(g, vertex_id):
    g = g.V(vertex_id).drop()
    return g
Run Code Online (Sandbox Code Playgroud)

我希望作为一个事务执行的链式查询理想情况下如下所示:

g.E('edge1').drop()
 .V('vertex1').drop()
 .E('edge3').drop()
 .V('vertex3').drop()
 .iterate() # execute all these queries as one transaction
Run Code Online (Sandbox Code Playgroud)

上面的方法不起作用...而且似乎我不能在我的 gremlin 查询中使用 .E('someid') 。

有点偏离主题,但我最好的尝试(非递归)如下所示:

g.E('edge1', 'edge2', 'edge3').as_('edges')
 .V('vertex1', 'vertex2', 'vertex3').as_('vertices')
 .union(__.select('edges'),
        __.select('vertices'))
 .drop()
 .iterate()
Run Code Online (Sandbox Code Playgroud)

非常感谢任何帮助!

python gremlin amazon-neptune

0
推荐指数
1
解决办法
2392
查看次数

Gremlin:如何在同一条边上向后遍历

我有一个带有两个顶点的简单图形,id 为“a”和“b”。

我已经分配了从 'a' 到 'b' 的边,标签为 'foo'

小鬼> gV()

==>v[b]

==>v[a]

小鬼> gE()

==>e[04b4b9fd-2f20-751d-5673-5aa9d7ce0285][a-foo->b]

我的问题:我如何沿着同一条边向后遍历?例如,如果查询遍历到出站顶点,那么该查询如何穿过同一条边返回到入站顶点?

我的查询如下所示:

gE('04b4b9fd-2f20-751d-5673-5aa9d7ce0285').outV().as('outV')...[想要获得相同边的inV,这里]

gremlin

0
推荐指数
1
解决办法
418
查看次数

如何通过远程连接获取 JanusGraphManagement?

我有一个运行 gremlin-server 的 docker 容器。

它是通过以下方式启动的:

./bin/gremlin-server.sh conf/gremlin-server/gremlin-server.yaml
Run Code Online (Sandbox Code Playgroud)

从 docker 容器中,运行此图像:https : //hub.docker.com/r/janusgraph/janusgraph

服务器已启动并正在侦听端口 8182

$ docker ps
6019adda6081        janusgraph/janusgraph                                         "docker-entrypoint.s…"   2 days ago          Up 26 hours         0.0.0.0:8182->8182/tcp                             
Run Code Online (Sandbox Code Playgroud)

我对使用架构和索引感兴趣。

Janus 在这里提供:https : //docs.janusgraph.org/basics/schema/

以下是我用来尝试连接到 gremlin-server 的配置:

AbstractConfiguration config = new BaseConfiguration();

    config.setListDelimiter('/');
    // contents of conf/remote-graph.properties
    config.setProperty("gremlin.remote.driver.sourceName", "g");
    config.setProperty("gremlin.remote.remoteConnectionClass", "org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection");
    // contents of conf/remote-objects.yaml:
    config.setProperty("clusterConfiguration.hosts", databaseUrl);
    config.setProperty("clusterConfiguration.port", 8182);
    config.setProperty("clusterConfiguration.serializer.className", "org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0/");

    config.setProperty("storage.backend", "cql");
    config.setProperty("clusterConfiguration.serializer.config.ioRegistries", "org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry");
Run Code Online (Sandbox Code Playgroud)

当我打电话

GraphTraversalSource g = traversal().withRemote(config);
Run Code Online (Sandbox Code Playgroud)

我得到了一个遍历源,一切似乎都很好。但是,要使用 Janus 提供的管理工具,我似乎需要一个JanusGraphManagement对象。我无法获取Graph上面的通用对象并将其转换为JanusGraph. …

java gremlin gremlin-server janusgraph

0
推荐指数
1
解决办法
330
查看次数

需要帮助将 Gremlin 查询的结果提取到 Python 数据结构中

我正在尝试从 Python 代码内部对 AWS Neptune 数据库运行 Gremlin 查询,并希望将返回的数据存储到 Python 列表中。这对于简单的 Gremlin 查询工作正常,但一些更复杂的查询似乎有问题。

下面是代码,第一个 Gremlin 查询工作正常,但第二个不行。该节点不存在,因此可以在不导入任何数据的情况下进行尝试。

from __future__  import print_function  # Python 2/3 compatibility

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()

remoteConn = DriverRemoteConnection('wss://sdm-neptune-db-instance-1.cduuicw2rgrv.us-east-1.neptune.amazonaws.com:8182/gremlin','g')
g = graph.traversal().withRemote(remoteConn)

cust_List=g.V('AZ50K115E39AX').hasLabel('tp21tpcust').count().toList()
for p in cust_List:
    print('Data Fetched: ' + str(p))

cust_List=g.V('XXXXXXXX').hasLabel('tp21tpcust').local(__.repeat(__.out().simplePath()).until(__.not_(__.out())).path().by(id).limit(100)).local(__.unfold().union(__.limit(1),__.tail()).fold()).dedup().toList()
for p in cust_List:
    print('Data Fetched' + p)

remoteConn.close()
Run Code Online (Sandbox Code Playgroud)

这是错误,任何指导将不胜感激

Data Fetched: 1
Traceback (most recent call …
Run Code Online (Sandbox Code Playgroud)

gremlin amazon-neptune gremlinpython

0
推荐指数
1
解决办法
456
查看次数

Amazon Neptune 与 Tinkerpop 兼容吗?为什么以及如何?

我正在尝试学习一些关于图形语言和查询语言 Gremlin 的知识。这是来自文档:

Amazon Neptune 与 Apache TinkerPop3 和 Gremlin 3.4.1 兼容。这意味着您可以连接到 Neptune 数据库实例并使用 Gremlin 遍历语言来查询图形(请参阅 Apache TinkerPop3 文档中的图形)。

海王星和 tinkerpop 2 不是相互竞争的图形数据库吗?一个数据库与另一个数据库兼容意味着什么?

也很好奇……为什么 apache 会发布它的查询语言 Gremlin 以用于其他数据库?这背后的想法是什么?

编辑

哦,我明白了,tinkerpop 是某种与海王星兼容的图形框架......无论如何。

graph-databases gremlin tinkerpop tinkerpop3 amazon-neptune

-1
推荐指数
1
解决办法
162
查看次数