0

使用社区版 2.1.11

我在网上看到了一些类似的问题(例如,使用 etl 或 orient-database.narkive.com/d8c4b82y/orientdb-etl-edge-creation-help 将边缘导入 OrientDB),但还没有真正解决。

我正在实施航班连接搜索系统。我有带有两个相关表的 RDBMS (SQL Server) - 位置和航班。每个航班都有两个 locationID - 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" }]
    }
  }
}

但是当我尝试导入航班时,我遇到了一个问题,即使在 Google 的帮助下我也无法解决: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 的 GoogleGroups 中的一个线程中,我找到了来自 OrientDB的 Luca的一篇文章,说只能通过 ETL 加载边缘,但我仍然不知道如何实现它:( 之后我唯一的想法两天的阅读文档和谷歌搜索是将它们作为顶点导入,然后编写一些控制台 JS 函数,该函数将创建具有相同属性的正确边缘......

或者也许我错过了一些非常基本的东西?我对东方完全陌生...

4

2 回答 2

1

一个简单的方法来做你需要做的就是将你的表导入两个具有正常 ETL 过程的顶点类,然后使用 js 函数创建边。

在导入两个表后,我制作了这个数据集来重新创建您的情况:

地点 航班_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 + ")");
}

执行函数后,这里是我的数据: 位置_EE 航班_E

然后,毕竟可以删除临时的 flight_V 类。

希望能帮助到你。再见。

伊万

于 2016-03-01T02:01:26.343 回答
0

我试过用 MySQL

我已经创建了位置和航班

在此处输入代码

位置.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" }]
    }
  }
}

飞行.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进程导入了以下记录

在此处输入图像描述

你可以使用这个 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");

你应该有这个结构

在此处输入图像描述

在此处输入图像描述

于 2016-03-01T14:39:22.200 回答