Current Workshop Series examples uses CQL only. How to configure access to use both CQL and graph drivers at same app?
Here is an example accessing a DSE 6.8 core graph in three different ways, all using the same driver Datastax Java driver 4.8.0.
The three different ways are:
- via CQL, select rows from a vertex table
- via String API with a string graph traversal statement
- via Fluent API with a fluent graph traversal
import com.datastax.dse.driver.api.core.graph.FluentGraphStatement; import com.datastax.dse.driver.api.core.graph.GraphNode; import com.datastax.dse.driver.api.core.graph.GraphResultSet; import com.datastax.dse.driver.api.core.graph.ScriptGraphStatement; import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.cql.ResultSet; import com.datastax.oss.driver.api.core.cql.Row; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.structure.Vertex; import static com.datastax.dse.driver.api.core.graph.DseGraph.g; public class SimpleTraversal { public static void main(String[] args) { try (CqlSession session = CqlSession.builder().build()) { //CQL query String script1 = "select * from friends.person"; ResultSet result1 = session.execute(script1); for (Row row : result1) { System.out.println(row.getString("person_id")); } //String API String script2 = "g.V()"; ScriptGraphStatement statement = ScriptGraphStatement.builder(script2).build(); GraphResultSet result2 = session.execute(statement); for (GraphNode node : result2) { System.out.println(node); } //Fluent API GraphTraversal<Vertex,Vertex> traversal = g.V(); FluentGraphStatement statement2 = FluentGraphStatement.newInstance(traversal); GraphResultSet result3 = session.execute(statement2); for (GraphNode node : result3) { System.out.println(node); } } } }
You can pass configurations to the driver by using the application.conf
In there, I have defined the basic contact point and local datacenter, as well as the graphname and traversal source g.
See here for the driver docs:
https://docs.datastax.com/en/developer/java-driver/4.8/
I hope this helps, let me know if you have further questions.
Thanks @bettina.swynnerton, good news!
I noticed that the java driver is version 4.8 and python is still version 3.24. Is this the latest version? Does this Python driver also work for CQL and graph?
Yes, 3.24 is the latest Python driver version, and yes, you can use the same driver for CQL and graph queries. If needed, I can create you a similar example as for Java.
Have a look at the documentation, too:
https://docs.datastax.com/en/developer/python-driver/3.24/graph/
Exception has occurred: UnresolvableContactPoints {} File "e:_git\t1-astra\server\dao\session_manager.py", line 77, in connect cluster = Cluster(contact_points=connectionPoint, execution_profiles={'core': ep_graphson3}) File "e:_git\t1-astra\server\service\astra_service.py", line 32, in connect return self._session_manager.connect() File "e:_git\t1-astra\server\app.py", line 37, in hello astra_service.connect()
https://github.com/bampli/t1-astra/blob/master/server/dao/session_manager.py
https://github.com/bampli/t1-astra/blob/master/server/app.py
7 People are following this question.
DataStax Enterprise is powered by the best distribution of Apache Cassandra ™
© 2023 DataStax, Titan, and TitanDB are registered trademarks of DataStax, Inc. and its subsidiaries in the United States and/or other countries.
Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries.
Privacy Policy Terms of Use