简体   繁体   English

OrientDB SQL:包含连接顶点的rids

[英]OrientDB SQL: Include rids from connected vertices

I have one vertex "A" connected to vertices "B" and "C". 我有一个顶点“ A”连接到顶点“ B”和“ C”。

I want to query for A with an appended list of the record-ids of B and C. 我想用B和C的记录ID的附加列表查询A。

Example of how properties could look: 属性外观的示例:

A:
{
   "@rid": "#1:0",
   "property": "ValueForA"
}

B:
{
   "@rid": "#2:0",
   "property": "ValueForB"
}

C:
{
   "@rid": "#2:1",
   "property": "ValueForC"
}

I want a query for A that gives me: 我想要一个查询A,该查询给了我:

{
    "@rid": "#1:0",
    "property": "ValueForA",
    "connected": ["#2:0", "#2:1"]
}

I would prefer to be able to do this with only projections. 我希望仅凭投影就能做到这一点。 It works fine for any custom field in B and C, but for @rid I get a link (why this inconsistency?). 它适用于B和C中的任何自定义字段,但对于@rid,我可以获得一个链接(为什么会有这种不一致?)。

I've tried: 我试过了:

SELECT @rid, *, out().@rid as connected FROM #1:0

Which gives me exactly what I want but the rids in the list are links to the records, not only rids. 这确实给了我我想要的东西,但列表中的标记是指向记录的链接,而不仅仅是标记。

And

SELECT @rid, *, out().@rid.asString() as connected FROM #1:0

Which gives: 这使:

{
    "@rid": "#1:0",
    "property": "ValueForA",
    "connected": "[#2:0, #2:1]"
}

Where the connected property is just a string. 其中,connected属性只是一个字符串。

There's probably (hopefully?) a reason for this inconsistency of @rid and other properties. @rid和其他属性不一致的原因可能是(希望如此)。 As I wrote, if @rid instead was "id", the first example would work fine. 如我所写,如果@rid改为“ id”,则第一个示例可以正常工作。 Regardless, I would like to know an easy way to do this, because I feel it should be easy to do it. 无论如何,我想知道一种简单的方法,因为我觉得这样做应该很容易。

Update 更新

It was misleading to add id as property example in the examples above, since it could somehow hint that it was unique (though I never said that), so I removed it. 在上面的示例中将id添加为属性示例会产生误导,因为它可能以某种方式暗示它是唯一的(尽管我从未说过),因此我将其删除。 I only added them to keep the 3 records apart. 我只是添加它们以使3条记录分开。 However, record-id is what is being used as unique id to separate the vertices above, so using any properties of the record is not possible. 但是,record-id被用作唯一ID来分隔上面的顶点,因此无法使用记录的任何属性。 To clarify further, the record can have arbitrary properties. 为了进一步说明,记录可以具有任意属性。 Not only the example ones given above. 不仅是上面给出的示例。

Again, first question is if it is possible using projections? 再次,第一个问题是是否可以使用投影?

Further comments: I find it really strange that I could easily do it if I made a property "rid" holding the exact same record id as @rid for each record. 进一步的评论:如果我将每个记录的属性“ rid”保存为与@rid完全相同的记录ID,我会很容易做到这一点,这真的很奇怪。 Why would I have to do that (I will not do that) in order to make it easy to use though. 我为什么要这样做(我不会那样做)以便使其易于使用。

Update2 UPDATE2

I also would like to be able to target several vertices at once and append connections for each of them. 我还希望能够一次定位多个顶点并为每个顶点附加连接。 I do this already, using projections, for many properties (but not @rid). 我已经使用投影对许多属性(而不是@rid)进行了此操作。

The fact that the query return the @rid like a link is pretty normal, a possible way to do it. 查询像链接一样返回@rid的事实是很正常的,这是一种可行的方法。 it could be this one: 可能是这样的:

select id, property, $a from #21:0
let $a = (select out() from #21:0 where $parent.current.id = id)

this is the output: 这是输出:

在此处输入图片说明

Hope it helps. 希望能帮助到你。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM