2015-11-12 20 views
5

Tôi có hai tập tin CSV:Làm thế nào để sử dụng OrientDB ETL để tạo ra cạnh chỉ

Đầu tiên chứa ~ hồ sơ 500M theo định dạng sau

id,name
10000023432,Tom User
13943423235,Blah Person

Second chứa ~ mối quan hệ bạn 1.5 tỷ trong các định dạng sau

fromId,toId
10000023432,13943423235

Tôi đã sử dụng công cụ ETL OrientDB để tạo các đỉnh từ tệp CSV đầu tiên. Bây giờ, tôi chỉ cần tạo ra các cạnh để thiết lập mối quan hệ hữu nghị giữa chúng.

Tôi đã thử nhiều cấu hình của file json ETL cho đến nay, mới nhất là cái này:

{ 
    "config": {"parallel": true}, 
    "source": { "file": { "path": "path_to_file" } }, 
    "extractor": { "csv": {} }, 
    "transformers": [ 
     { "vertex": {"class": "Person", "skipDuplicates": true} }, 
     { "edge": { "class": "FriendsWith", 
        "joinFieldName": "from", 
        "lookup": "Person.id", 
        "unresolvedLinkAction": "SKIP", 
        "targetVertexFields":{ 
         "id": "${input.to}" 
        }, 
        "direction": "out" 
        } 
     }, 
     { "code": { "language": "Javascript", 
        "code": "print('Current record: ' + record); record;"} 
     } 
    ], 
    "loader": { 
     "orientdb": { 
      "dbURL": "remote:<DB connection string>", 
      "dbType": "graph", 
      "classes": [ 
       {"name": "FriendsWith", "extends": "E"} 
      ], "indexes": [ 
       {"class":"Person", "fields":["id:long"], "type":"UNIQUE" } 
      ] 
     } 
    } 
} 

Nhưng thật không may, điều này cũng tạo ra các đỉnh với "từ" và "đến" bất động sản, ngoài để tạo cạnh.

Khi tôi cố gắng loại bỏ các biến đỉnh, quá trình ETL ném một lỗi:

Error in Pipeline execution: com.orientechnologies.orient.etl.transformer.OTransformException: edge: input type '[email protected]3 
6a8' is not supported 
Exception in thread "OrientDB ETL pipeline-0" com.orientechnologies.orient.etl.OETLProcessHaltedException: Halt 
     at com.orientechnologies.orient.etl.OETLPipeline.execute(OETLPipeline.java:149) 
     at com.orientechnologies.orient.etl.OETLProcessor$2.run(OETLProcessor.java:341) 
     at java.lang.Thread.run(Thread.java:745) 
Caused by: com.orientechnologies.orient.etl.transformer.OTransformException: edge: input type '[email protected]36a8' is not suppor 
ted 
     at com.orientechnologies.orient.etl.transformer.OEdgeTransformer.executeTransform(OEdgeTransformer.java:107) 
     at com.orientechnologies.orient.etl.transformer.OAbstractTransformer.transform(OAbstractTransformer.java:37) 
     at com.orientechnologies.orient.etl.OETLPipeline.execute(OETLPipeline.java:115) 
     ... 2 more 

tôi đang thiếu gì ở đây?

Trả lời

0

Với Java API bạn có thể đọc csv và sau đó tạo ra các cạnh

 String nomeYourDb = "nomeYourDb"; 
     OServerAdmin serverAdmin; 
     try { 
      serverAdmin = new OServerAdmin("remote:localhost/"+nomeYourDb).connect("root", "root"); 
      if (serverAdmin.existsDatabase()) { 
       OrientGraph g = new OrientGraph("remote:localhost/"+nomeYourDb); 
       String csvFile = "path_to_file"; 
       BufferedReader br = null; 
       String line = ""; 
       String cvsSplitBy = " "; // your separator 
       try { 
        br = new BufferedReader(new FileReader(csvFile)); 
        int index=0; 
        while ((line = br.readLine()) != null) { 
         if(index==0){ 
          index=1; 
         } 
         else{ 
          String[] ids = line.split(cvsSplitBy); 
          String personFrom="(select from Person where id='"+ids[0]+"')"; 
          String personTo="(select from Person where id='"+ids[1]+"')"; 
          String query="create edge FriendsWith from "+personFrom+" to "+personTo; 
          g.command(new OCommandSQL(query)).execute(); 
         } 
        } 
       } catch (FileNotFoundException e) { 
        e.printStackTrace(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       finally { 
       if (br != null) { 
         br.close(); 
       } 
      } 
      } 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
+0

Tôi có trình tải của riêng mình bằng cách sử dụng API Java. Tôi đã tự hỏi nếu nó có thể sử dụng công cụ ETL, bởi vì có các móc song song tự động trong công cụ. Cảm ơn vì câu trả lời. – lambdapilgrim

5

Bạn có thể nhập các cạnh với những biến ETL:

"transformers": [ 
    { "merge": { "joinFieldName": "fromId", "lookup": "Person.id" } }, 
    { "vertex": {"class": "Person", "skipDuplicates": true} }, 
    { "edge": { "class": "FriendsWith", 
       "joinFieldName": "toId", 
       "lookup": "Person.id", 
       "direction": "out" 
       } 
    }, 
    { "field": { "fieldNames": ["fromId", "toId"], "operation": "remove" } } 
] 

Các "hợp nhất" biến sẽ tham gia vào hiện tại dòng csv với bản ghi Person liên quan (điều này hơi lạ một chút nhưng vì một số lý do, điều này là cần thiết để liên kết fromId với người nguồn).

Biến áp "trường" sẽ xóa trường csv được phần bổ sung thêm vào. Bạn có thể thử nhập khẩu mà không cần biến "trường" để xem sự khác biệt.

Các vấn đề liên quan