2016-02-29 73 views
0

使用社區版2.1.11從導入到RDBMS OrientDB:負載邊緣僅

我看到在互聯網上(例如一些類似的問題,import edges to OrientDB using etl或orient-database.narkive.com/d8c4b82y/orientdb- etl-edge-creation-help),但它們還沒有真正解決。

我正在實施航班連接搜索系統。我有RDBMS(SQL Server)和兩個相關表格 - 位置和航班。每個航班都有兩個位置標識 - locationFrom和locationTo。

當我將它導入到圖形中時,我想將位置看作頂點,並將其作爲邊連接到邊。正如我從手冊中瞭解的(從DBMS導入的,由於新手限制我不能發佈兩個以上的鏈接......),我應該爲此編寫兩個不同的JSON並由ETL運行它們。所以,我可以用這個代碼導入位置沒有任何問題:

{ 
    "config": { 
    log : "debug" 
    }, 
    "extractor" : { 
    "jdbc": { "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver", 
       "url": "jdbc:sqlserver://localhost:1434;databaseName=mydb;integratedSecurity=true;", 
       "userName": "root", 
       "userPassword": "root", 
       "query": "select * from locations" } 
    }, 

    "transformers" : [ 
    { "vertex": { "class": "Location"} } 
    ], 
    "loader" : { 
    "orientdb": { 
     "dbURL": "plocal:C:\orientdb-community-2.1.11\databases\Test", 
     dbUser: "admin", 
     dbPassword: "admin", 
     dbAutoDropIfExists: false, 
     dbAutoCreate: true, 
     tx: false, 
     wal: false, 
     batchCommit: 1000, 
     dbType: "graph", 
     indexes: [{class:"Location", fields:["id:string"], type:"UNIQUE_HASH_INDEX" }] 
    } 
    } 
} 

但是,當我嘗試導入航班,我得到了一個問題,我甚至不能與谷歌的幫助下解決:在ETL呢不想只導入邊緣。作爲第一個直觀的目的,我寫了這樣的事情:

{ 
    "config": { 
    log : "debug" 
    }, 
    "extractor" : { 
    "jdbc": { "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver", 
       "url": "jdbc:sqlserver://localhost:1434;databaseName=mydb;integratedSecurity=true;", 
       "userName": "root", 
       "userPassword": "root", 
       "query": "select * from flights" } 
    }, 

    "transformers" : [ 
    { "edge": { "class": "flight", "direction" : "out", 
      "joinFieldName": "flightFromLocation", 
      "lookup":"locationID", "unresolvedLinkAction":"CREATE"} 

      { "class": "flight", "direction" : "in", 
      "joinFieldName": "flightToLocation", 
      "lookup":"locationID", "unresolvedLinkAction":"CREATE"} 
    } 
    ], 
    "loader" : { 
    "orientdb": { 
     "dbURL": "plocal:C:\orientdb-community-2.1.11\databases\Test", 
     dbUser: "admin", 
     dbPassword: "admin", 
     dbAutoDropIfExists: false, 
     dbAutoCreate: true, 
     tx: false, 
     wal: false, 
     batchCommit: 1000, 
     dbType: "graph", 
     indexes: [{class:"flight", fields:["id:string"], type:"UNIQUE_HASH_INDEX" }] 
    } 
    } 
} 

在OrientDB的Google網上論壇的主題之一,我發現從OrientDB,那說,負載只有邊緣通過ETL可能一個post from Luca,但我仍然無法弄清楚,如何實現它:(我閱讀文檔和谷歌搜索兩天後的唯一想法是將它們作爲頂點導入,然後編寫一些控制檯JS函數,以創建具有相同屬性的正確邊緣。 。

或者,也許我失去了一些非常基本的?我完全陌生的東方......

回答

1

一簡單的方法來完成你所需要的是將你的表格導入兩個具有正常ETL過程的頂點類,然後使用js函數創建邊。

我做了這個數據集這兩個表的導入後重新創建您的情況:

locations flights_V

這裏是JS功能:

參數:flights_V_class,edge_class,location_class

var g=orient.getGraphNoTx(); 


var flightsV_table = g.command("sql","select from " + flights_V_class); 

for(i=0; i < flightsV_table.length; i++){ 

    var id_from = flightsV_table[i].getProperty("locationFrom"); 

    var id_to = flightsV_table[i].getProperty("locationTo"); 

    var select_from = "select from "+location_class+" where id = "+id_from; 
    var select_to = "select from "+location_class+" where id = "+id_to; 

    g.command("sql","create edge " + edge_class + " from (" + select_from + ") to (" + select_to + ")"); 
} 

這裏執行該功能後,我的數據: locations_EE flights_E

然後,畢竟,你可以刪除臨時flights_V類。

希望它有幫助。 再見。

伊萬

+0

Ivan和@Alessandro,非常感謝您的建議,我也考慮過JS,但仍然希望(基於Luka的帖子)通過ETL製作它。但是我意識到(發佈一個問題後)我確實需要一個同步工具,而不僅僅是導入;所以現在我寫一個基於Java API的。希望將來[鏈接](https://github.com/orientechnologies/orientdb-labs/blob/master/Teleporter-Index.md)將更具定製性:) – grreeenn

0

我曾嘗試與MySQL

我已經創建了位置和飛行

enter code here

Location.json

{ 
    "config": { 
    log : "debug" 
    }, 
    "extractor" : { 
    "jdbc": { "driver": "com.mysql.jdbc.Driver", 
       "url": "jdbc:mysql://localhost:3306/flights", 
       "userName": "user", 
       "userPassword": "password", 
       "query": "select * from Location" 
       } 
    }, 
    "transformers" : [ 
    { "vertex": { "class": "Location"} } 
    ], 
    "loader" : { 
    "orientdb": { 
     "dbURL": "yourPath", 
     "dbUser": "admin", 
     "dbPassword": "admin", 
     "dbAutoDropIfExists": false, 
     "dbAutoCreate": true, 
     "tx": false, 
     "wal": false, 
     "batchCommit": 1000, 
     "dbType": "graph", 
     "indexes": [{class:"Location", fields:["id:string"], type:"UNIQUE_HASH_INDEX" }] 
    } 
    } 
} 

Flight.json

{ 
    "config": { 
    log : "debug" 
    }, 
    "extractor" : { 
    "jdbc": { "driver": "com.mysql.jdbc.Driver", 
       "url": "jdbc:mysql://localhost:3306/flights", 
       "userName": "user", 
       "userPassword": "password", 
       "query": "select * from flight" 
       } 
    }, 
    "transformers" : [ 
    { "vertex": { "class": "Fligth"} } 
    ], 
    "loader" : { 
    "orientdb": { 
     "dbURL": "yourPath", 
     "dbUser": "admin", 
     "dbPassword": "admin", 
     "dbAutoDropIfExists": false, 
     "dbAutoCreate": true, 
     "tx": false, 
     "wal": false, 
     "batchCommit": 1000, 
     "dbType": "graph", 
     "indexes": [{class:"flight", fields:["id:string"], type:"UNIQUE_HASH_INDEX" }] 
    } 
    } 
} 

ETL過程先後引進了以下記錄

enter image description here

您可以使用此JavaScript函數

var g=orient.getGraphNoTx(); 
g.command("sql","CREATE CLASS Fligth2 EXTENDS E"); 
var fligth = g.command("sql","select from Fligth"); 
for(i=0;i<fligth.length;i++){ 
    var idFrom=fligth[i].getProperty("idFrom"); 
    var idTo=fligth[i].getProperty("idTo"); 
    var name=fligth[i].getProperty("name"); 
    print(name); 
    var from=g.command("sql","select from Location where id = " + idFrom); 
    var to=g.command("sql","select from Location where id = " + idTo); 
    g.command("sql","create edge Fligth2 from " + from[0].getId() + " to " + to[0].getId() + " set name = '" + name + "'"); 
} 
g.command("sql","drop class Fligth unsafe"); 
g.command("sql","UPDATE Location REMOVE id"); 

而且你應該有這樣的結構

enter image description here

enter image description here