本文介绍了使用Java的Datastax DSE 5.0 Graph中是否真的不需要executeGraph()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两种方法似乎都存储了顶点,以后可以正确地对其进行检索。

It seems that in both approaches the vertex is stored and can be retrieved properly later.

常用配置:

DseCluster dseCluster = DseCluster.builder()
        .addContactPoint("192.168.1.43")
        .build();
DseSession dseSession = dseCluster.connect();
GraphTraversalSource g = DseGraph.traversal(
    dseSession, new GraphOptions().setGraphName("graph")
);

方法1:

Vertex v = g.addV("User").property("uuid","testuuid231").next();

方法2:

GraphStatement graphStatement =  DseGraph.statementFromTraversal(
    g.addV("User").property("uuid","testuuid231")
);
GraphResultSet grs = dseSession.executeGraph(graphStatement.setGraphName("graph"));
Vertex v = grs.one().asVertex() // as(Vertex.class) is not allowed after 1.1


推荐答案

您似乎正在使用,对吗?这是一个相对较新的API(仍处于beta版),使您可以使用DataStax Enterprise Java驱动程序在幕后使用Apache Tinkerpop进行Gremlin遍历。

It looks like you are using java-dse-graph, is that right? This is a relatively new API (still in beta) which allows you to make Gremlin Traversals w/ Apache Tinkerpop using the DataStax Enterprise Java driver under the covers.

方法1是您可以确定自己正在形成有效的遍历,尽管您也可以通过 statementFromTraversal 获得此遍历(也可以传递 String GraphStatement executeGraph 中,此时您不能确定自己正在执行有效遍历)。此外,由于您使用的是Tinkerpop API,而不是datastax驱动程序,因此您可以编写与供应商无关的代码。好吧,您仍然在使用它,但是一旦从 DseSession 获得了 GraphTraversalSource ,就不会直接使用它。

The benefits of approach 1 is that you can be sure that you are forming valid traversals for one, although you also get this via statementFromTraversal (you can also pass a String or GraphStatement into executeGraph at which point you can't be sure you are executing a valid traversal). Additionally, you can write code that is more vendor agnostic, since you are using the Tinkerpop API and not the datastax driver. Well, you are still using it, but not directly once you've got a GraphTraversalSource from a DseSession.

方法2有一些方法1中尚未提供的好处(至今):

Approach 2 has a few benefits that aren't available in approach 1 (yet):


  1. 如果您熟悉datastax驱动程序,则可以使用很多自己喜欢的相同API( ResultSet Statement 等)。

  2. TinkerPop的异步API()是最近才添加的,我不确定它是否可以与 java-dse-graph 一起使用(尚未尝试过)。使用 statementFromTraversal ,可以将生成的 GraphStatement 传递到 DseSession.executeAsync 执行异步操作。

  3. DSE Graph的架构API不属于Gremlin。因此,您不能仅凭TinkerPop进行架构更改。 将引入使用<$ c $进行此操作的模式API c> java-dse-graph 。在此之前,您将必须使用 executeGraph(String | GraphStatement)

  4. 您可以使用方法2执行完整的groovy / gremlin代码。这样一来,您就可以执行事务管理之类的功能,并在一个调用中执行多个遍历,而这在方法1中是当前无法做到的。

  1. If you are familiar with the datastax driver, you can use a lot of the same APIs that you are comfortable with (ResultSet, Statement, etc.).
  2. The async API for TinkerPop (TINKERPOP-1490) was very recently added and I'm not sure it would work with java-dse-graph (haven't tried it yet). Using statementFromTraversal, you can pass the generated GraphStatement into DseSession.executeAsync to do async.
  3. DSE Graph has a schema API that is not part of Gremlin. Therefore, you can't make schema changes with TinkerPop alone. JAVA-1061 will introduce a schema API for doing this using java-dse-graph. Until then you would have to use executeGraph(String|GraphStatement).
  4. You can execute full groovy/gremlin code with approach 2. This allows you to do things like transaction management and execute multiple traversals in one call, which you can't currently do with approach 1.

我希望 java-dse-graph (方法1)将来会成为与DSE Graph交互的更惯用的方式。 statementFromTraversal 提供了一个很好的方法来获得两全其美(Apache TinkerPop的优势以及DataStax Java驱动程序的接口)。

I expect that java-dse-graph (approach 1) will become the more idiomatic way to interact with DSE Graph in the future. statementFromTraversal offers a nice way to get the best of both worlds (the benefit of Apache TinkerPop + an interface to the DataStax java driver).

这篇关于使用Java的Datastax DSE 5.0 Graph中是否真的不需要executeGraph()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 07:30