Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

ksadagopan_79052 avatar image
ksadagopan_79052 asked ·

Do you have examples for running Graph queries with Java driver 4.8.0?

Hi Team,

We have a DSE Graph DB 5.1.9. Currently using Java driver 1.7.0. Right now we trying to upgrade our applications to the latest driver and found that the OSS driver supports graph queries. I tried using OSS 4.8.0 version and getting

Do you have any examples using ?

com.datastax.oss.driver.api.core.servererrors.InvalidQueryException: No such property: g for class: Script518
    at com.datastax.oss.driver.api.core.servererrors.InvalidQueryException.copy(InvalidQueryException.java:48) ~[java-driver-core-4.8.0.jar:na]
    at com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:149) ~[java-driver-core-4.8.0.jar:na]
    at com.datastax.dse.driver.internal.core.graph.GraphRequestSyncProcessor.process(GraphRequestSyncProcessor.java:60) ~[java-driver-core-4.8.0.jar:na]
    at com.datastax.dse.driver.internal.core.graph.GraphRequestSyncProcessor.process(GraphRequestSyncProcessor.java:33) ~[java-driver-core-4.8.0.jar:na]

Here is my config

driver.contactPoints=hostname
driver.port=9042
driver.localdc=dc1
driver.username=test
driver.password=test
driver.keyspace=graphname

Driver config class

https://github.com/DataStax-Examples/cassandra-reactive-demo-java/blob/master/0_common/src/main/java/com/datastax/demo/common/conf/DriverConfiguration.java

Query class

    public String getMacc() {
        
         CqlSession session =dseConfiguration.getSession();
         
         ScriptGraphStatement statement =
                    ScriptGraphStatement.builder("g.V('{macAddressCKEY=00:00:00:38:d8:cd:8cd, ~label=MAC, PKEY=8cd}')").build();
         
         GraphResultSet result = session.execute(statement);
         for (GraphNode node : result) {
           System.out.println(node.asVertex());
         }
        
         return  null;
    }
dsegraph
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

For correctness, there is no longer a "DSE driver" or "OSS driver" since we unified the drivers in January 2020. Since then, there is only the "Java driver" from version 4.4.0 onwards. For details, see the blog post Better Drivers for Cassandra.

Here's an example code that passes a Gremlin script directly:

CqlSession session = CqlSession.builder().build();

String script = "g.V().has('name', name)";
ScriptGraphStatement statement =
    ScriptGraphStatement.builder(script)
        .withQueryParam("name", "marko")
        .build();

GraphResultSet result = session.execute(statement);
for (GraphNode node : result) {
  System.out.println(node.asVertex());
}

For details, see the Java driver doc on DSE Graph support.

I would also suggest that you have a look at the Java driver Upgrade Guide for important changes to the driver you need to be aware of. Cheers!

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thank you I'm using 4.8.0 driver and I'm facing this issue.

No such property: g for class: Script518

0 Likes 0 ·

Just wondering if you set the graph name (with .setGraphName()) anywhere in your code. Otherwise, you can set it globally in the configuration with:

datastax-java-driver {
  ...
  basic.graph.name = my_graph
  ...
}

You can get more info about execution profiles in the Graph options page of the Java driver. Cheers!

0 Likes 0 ·