2016-02-02 3 views
1

Я пытаюсь выполнить следующий код:Vertex Этикетка с указанным именем не существует

public class Friendster { 

/** 
* @param args 
* @throws FileNotFoundException 
*/ 


public static void load(final TitanGraph graph,String filePath) throws FileNotFoundException { 
    Scanner sc = new Scanner(new File(filePath)); 
    System.out.println("Inside Load Function"); 


    for (int i =0 ; sc.hasNext();i++) 
    { 
     TitanTransaction tx = graph.newTransaction(); 
     String friendLine = sc.nextLine(); 

     String friendList[]= friendLine.split(":"); 
     if(friendList.length==1) 
     { 
      continue; 
     } 
     else if(friendList[1].equals("notfound")) 
     { 
      String human="human"; 
      tx.addVertex(T.label, human, "Name", "Not Found","No of Friends",0); 

      // tx.commit(); 
     } 
     else if(friendList[1].equals("private")) 
     { 
      String human="human"; 
      tx.addVertex(T.label, human, "Name", ""+friendList[0],"No of Freinds", "Private"); 
      System.out.println("Node Added : "+ friendList[0]); 

      // tx.commit(); 
     } 
     else 
     { 
      String human="human"; 
      int friends_count=friendList[1].split(",").length; 

      tx.addVertex(T.label, human, "Name", ""+friendList[0],"No of Friends",friends_count); 
      System.out.println("Node Added : "+ friendList[0]); 
      String totalList[]=friendList[1].split(","); 

      for(int j=0;j<totalList.length;j++) 
      { 
       Iterator<Vertex> itr2=graph.traversal().V().has("Name", ""+totalList[j]); 
        if(!itr2.hasNext()) 
        { 
         tx.addVertex(T.label, human, "Name", ""+totalList[j],"No of Friends",999); 
         System.out.println("Node Added : "+ totalList[j]); 

         //  tx.commit(); 
        } 
      } 
     } 
     tx.commit(); 

    } 




     } 

public static void main(String[] args) throws FileNotFoundException { 
    // TODO Auto-generated method stub 


    TitanGraph g = TitanFactory.open("titan-cassandra.properties"); 


     //LOADING FROM FILE 
    load(g,"/media/laxmikant/New Volume/friends.txt"); 


     g.close(); 

} 

}

Этот код дает ошибку, как:

Exception in thread "main" java.lang.IllegalArgumentException: Vertex Label with given name does not exist: human 
at com.thinkaurelius.titan.graphdb.types.typemaker.DisableDefaultSchemaMaker.makeVertexLabel(DisableDefaultSchemaMaker.java:37) 
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.getOrCreateVertexLabel(StandardTitanTx.java:988) 
at com.thinkaurelius.titan.graphdb.tinkerpop.TitanBlueprintsTransaction.addVertex(TitanBlueprintsTransaction.java:101) 
at Friendster.load(Friendster.java:79) 
at Friendster.main(Friendster.java:133) 

Это было правильно выполняться до , вдруг он начал бросать ошибку.

Если мы запускаем отдельные запросы в оболочке gremlin, он не дает ошибок, но в java-коде он вызывает ошибку, почему?

В чем проблема с этим кодом здесь?

ответ

2

Проблема в том, что вы установили schema.default=none в свой файл titan-cassandra.properties, поэтому автоматическое создание схемы отключено. Когда автоматическое создание схемы отключено, вам необходимо определить схему (включая все метки, свойства и индексы на вершинах и краях), прежде чем вы сможете их использовать.

Подробную информацию о том, как определить схему, см. В документе Chapter 5: Schema and Data Modeling в документации Titan.

+0

Спасибо за решение. Это сработало. Не могли бы вы немного помочь в этом вопросе, http://stackoverflow.com/questions/35187601/how-to-load-millions-of-vertices-from-csv-into-titan-1-0- 0-using-bulkloaderverte. – Amnesiac

0

Если вы поместили storage.batch-load как true, то также автоматически отключится создание схемы, и вы должны явно установить схему.

lazy val graph = TitanFactory.build() 
    .set("storage.backend", storage_backend) 
    .set("storage.hostname", "127.0.0.1") 
    .set("storage.cassandra.keyspace", "titan_graph_test") 
    .set("storage.batch-loading", "true") //this removes the consitency lock ,which don't work well with NSQL backends 
    .open() 
mgmt.makePropertyKey(TIME).dataType(classOf[String]).cardinality(Cardinality.SET).make() 
mgmt.makeEdgeLabel("interference").make() 

Обратите внимание, что в настоящее время с TitanGraph, с этими настройками, как представляется, ошибка, которая препятствует Vertex быть создано с меткой - https://groups.google.com/d/msg/aureliusgraphs/lFW1buC1Hms/tBV_hUUoAAAJ

Но вы можете создать вершины без метки и добавить указанные выше свойства

Смежные вопросы