executeGraph() is not really needed in Datastax DSE 5.0 Graph with Java?

人走茶凉 提交于 2019-12-12 20:01:58

问题


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

Common configuration:

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

Approach 1:

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

Approach 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

回答1:


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.

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.

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

  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.

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).



来源:https://stackoverflow.com/questions/41231912/executegraph-is-not-really-needed-in-datastax-dse-5-0-graph-with-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!