josemotta_190638 avatar image
josemotta_190638 asked bettina.swynnerton commented

Configure access to use both CQL and graph in the same app/api

Current Workshop Series examples uses CQL only. How to configure access to use both CQL and graph drivers at same app?

1 comment
10 |1000

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

Erick Ramirez avatar image Erick Ramirez ♦♦ commented ·

Could you please clarify if you're looking for driver usage examples for DSE Graph?

0 Likes 0 ·

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered bettina.swynnerton commented

Hi @josemotta_190638,

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


            //String API

            String script2 = "g.V()";

            ScriptGraphStatement statement =

            GraphResultSet result2 = session.execute(statement);
            for (GraphNode node : result2) {


            //Fluent API

            GraphTraversal<Vertex,Vertex> traversal = g.V();

            FluentGraphStatement statement2 = FluentGraphStatement.newInstance(traversal);

            GraphResultSet result3 = session.execute(statement2);
            for (GraphNode node : result3) {



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:

I hope this helps, let me know if you have further questions.

4 comments Share
10 |1000

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

josemotta_190638 avatar image josemotta_190638 commented ·

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?

0 Likes 0 ·
bettina.swynnerton avatar image bettina.swynnerton ♦♦ josemotta_190638 commented ·

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:

0 Likes 0 ·
josemotta_190638 avatar image josemotta_190638 bettina.swynnerton ♦♦ commented ·

Hi @bettina.swynnerton! Would you please help with this error? I did some changes to connect to a local Cassandra cluster built with Kind and Tilt.

Exception has occurred: UnresolvableContactPoints {} File "e:_git\t1-astra\server\dao\", line 77, in connect cluster = Cluster(contact_points=connectionPoint, execution_profiles={'core': ep_graphson3}) File "e:_git\t1-astra\server\service\", line 32, in connect return self._session_manager.connect() File "e:_git\t1-astra\server\", line 37, in hello astra_service.connect()

Follows the dao/ link:

I also changed server/

0 Likes 0 ·
Show more comments