本文介绍了在 OrientDB 中创建边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我的示例数据:

orientdb {db=audit}>从 V 中选择 *+----+------+-------+----------+---------+----+|# |@RID |@CLASS |名称 |域名 |本地名称 |+----+------+-------+----------+---------+----+|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 |测试版 |null |compute-1.example.com |null ||4 |#13:1 |测试版 |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 到 Beta:从 Alpha 中选择,加入 Name 作为 Beta.DomainName 的子字符串#12:0 和 #13:0 之间的边缘#12:1 和 #13:1 之间的边缘Alpha 到 Gamma:从 Alpha 中选择,加入 Name &带有 Gamma.LocalName 的.local"#12:0 和 #14:0 之间的边缘#12:2 和 #14:1 之间的边缘Beta 到 Gamma:从 Gamma 中选择 LocalName,去掉.local"后缀,作为 Beta.DomainName 的子串加入#13:0 和 #14:0 之间的边缘
解决方案

试试这个 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');//阿尔法到贝塔for(i=0;i

希望有帮助.

问候

I have an Orient database with vertices for servers from different management tools. As a server can be monitored by multiple management tools, I would like to create edges between the vertices for the same server. The connected components would then be the individual servers.

The problem I have, is that different systems will have different naming conventions - some use fully qualified domain names, some use internal domain names, and some only use the hostname.

My Sample Data:

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 |
+----+------+-------+----------+----------------------+----------------+

Expected Output:

I would expect 3 distinct commands (pseudocoded below), that would produce the below edges

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
解决方案

Try this JS function:

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+'');
    }
  }
}

This is the output:

Hope it helps.

Regards

这篇关于在 OrientDB 中创建边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 14:32