0

My previous question was about the syntax of the TitanFactory class. Now i wonder how to use it?

For example i can construct RexsterGraph object like the following and it works like a charm.

Graph graph = new RexsterGraph(http://190.188.20.11:8183/graphs/graph");

Now i want to import csv file into the titan. So i need TitanGraph object. I found the following post to do that.

How to import a CSV file into Titan graph database?

And i worte the following code and it gives me error.

Could not find implementation class: com.thinkaurelius.titan.diskstorage.cassandra.thrift.CassandraThriftStoreManager

    TitanGraph titanGraph = null;
    try {
        titanGraph = TitanFactory
                .open("D:\\TEMP\\titan-cassandra.properties");
    } catch (Exception e) {
        System.err.println(e.getMessage());

        System.out.println("\n");

        System.err.println(e.getStackTrace());
    }

The only thing i need is that i want some code like RexsterGraph example for getting instance of TitanGraph object. What should i do? by the way i run the code on my local but graph is working remote linux machine

Community
  • 1
  • 1
brtb
  • 2,201
  • 6
  • 34
  • 53
  • Would you edit your question and describe your Titan setup a bit more? It looks like you want to use a remote Cassandra cluster as the storage backend for Titan? If your application has access to the remote Cassandra cluster, you don't necessarily need Rexster involved to load graph data into Titan. What does the rexster config xml look like for the graph instance? – Jason Plurad Sep 11 '15 at 16:15

1 Answers1

1

sample test.csv lines

id:1,name:xxx,age:20,........

id:2,name:yyy,age:21,........

I don't know what is your csv file size but it is small, you can import like this

            String path = "c:\\test.csv";
            Charset encoding = Charset.forName("ISO-8859-1");
            try {
                List<String> lines = Files.readAllLines(Paths.get(path), encoding);
                Graph graph = new RexsterGraph("http://190.188.20.11:8183/graphs/graph");
                
                for (String line : lines) {
                    Vertex currentNode = graph.addVertex(null);
                    String[] values = line.split(",");
                    for (String value : values) {
                        String[] property = value.split(":");
                        currentNode.setProperty(property[0].toString(), property[1].toString());
                    }
                }
                
            }
Community
  • 1
  • 1
AgonyClanKios
  • 102
  • 1
  • 8