在OrientDB中创建边

时间:2016-06-13 05:26:32

标签: orientdb

我有一个Orient数据库,其中包含来自不同管理工具的服务器的顶点。由于服务器可以由多个管理工具监控,我想在同一服务器的顶点之间创建边。然后,连接的组件将成为各个服务器。

我遇到的问题是,不同的系统会有不同的命名约定 - 有些使用完全限定的域名,有些使用内部域名,有些只使用主机名。

我的样本数据:

orientdb {db=audit}> select * from V

+----+------+-------+----------+----------------------+----------------+
|#   |@RID  |@CLASS |Name      |DomainName            |LocalName       |
+----+------+-------+----------+----------------------+----------------+
|0   |#12:0 |Alpha  |compute-1 |null                  |null            |
|1   |#12:1 |Alpha  |compute-2 |null                  |null            |
|2   |#12:2 |Alpha  |compute-3 |null                  |null            |
|3   |#13:0 |Beta   |null      |compute-1.example.com |null            |
|4   |#13:1 |Beta   |null      |compute-2.example.com |null            |
|5   |#14:0 |Gamma  |null      |null                  |compute-1.local |
|6   |#14:1 |Gamma  |null      |null                  |compute-3.local |
+----+------+-------+----------+----------------------+----------------+

预期输出:

我希望有3个不同的命令(下面是伪编码),这会产生下面的边缘

Alpha to Beta:
    Select from Alpha, join Name as a substring of Beta.DomainName

    edge between #12:0 and #13:0
    edge between #12:1 and #13:1

Alpha to Gamma:
    Select from Alpha, join Name & ".local" with Gamma.LocalName

    edge between #12:0 and #14:0
    edge between #12:2 and #14:1

Beta to Gamma:
    Select LocalName from Gamma, remove ".local" suffix, join as a substring of Beta.DomainName

    edge between #13:0 and #14:0

2 个答案:

答案 0 :(得分:2)

试试这个JS函数:

var db = orient.getGraph();
var a = db.command('sql','select from Alpha');
var b = db.command('sql','select from Beta');
var g = db.command('sql','select from Gamma');

//Alpha to Beta
for(i=0;i<b.length;i++)
{
  var name = a[i].getRecord().field('Name');
  var Arid = a[i].getRecord().field('@rid');
  for(j=0;j<b.length;j++)
  {
    var dn = b[j].getRecord().field('DomainName').substring(0,name.length);
    var Brid = b[j].getRecord().field('@rid');
    if(name==dn)
    {
      db.command('sql','create edge E from '+Arid+' to '+Brid+'');
    }
  }
}

//Alpha to Gamma
for(i=0;i<a.length;i++)
{
  var name = a[i].getRecord().field('Name');
  var Arid = a[i].getRecord().field('@rid');
  for(j=0;j<g.length;j++)
  {
    var ln = g[j].getRecord().field('LocalName').substring(0,name.length);
    var Grid = g[j].getRecord().field('@rid');
    if(name==ln)
    {
      db.command('sql','create edge E from '+Arid+' to '+Grid+'');
    }
  }
}

//Beta to Gamma
for(i=0;i<b.length;i++)
{
  var name = b[i].getRecord().field('DomainName').substring(0,9);
  var Brid = b[i].getRecord().field('@rid');
  for(j=0;j<g.length;j++)
  {
    var n = g[j].getRecord().field('LocalName').substring(0,name.length);
    var Grid = g[j].getRecord().field('@rid');
    if(name==n)
    {
      db.command('sql','create edge E from '+Brid+' to '+Grid+'');
    }
  }
}

这是输出:

enter image description here

希望它有所帮助。

此致

答案 1 :(得分:1)

您可以使用以下查询:

create edge from (select from Alpha where Name="compute-1") to (select from Beta where DomainName like "compute-1%")
create edge from (select from Alpha where Name="compute-2") to (select from Beta where DomainName like "compute-2%")

create edge from (select from Alpha where Name="compute-1") to (select from Gamma where LocalName like "compute-1%")
create edge from (select from Alpha where Name="compute-3") to (select from Gamma where LocalName like "compute-3%")

create edge from (select from Beta where DomainName like "compute-1%") to (select from Gamma where LocalName like "compute-1%")

希望有所帮助