简体   繁体   English

在RID和集合上使用orientdb中的expand

[英]using expand in orientdb on RIDs and collections

I am struggling to understand when expand will work in OrientDB. 我很难理解expand何时在OrientDB中工作。 My understanding of expand as applied to an RID is that it returns the document (and all its fields) http://orientdb.com/docs/2.1/SQL-Functions.html#expand 我对扩展应用于RID的理解是它返回文档(及其所有字段) http://orientdb.com/docs/2.1/SQL-Functions.html#expand

I am sometimes getting no results from applying expand to an RID. 我有时候没有将扩展应用于RID的结果。

I'll create some sample data here and provide an example of my problem. 我将在这里创建一些示例数据并提供我的问题示例。 The sample data is Person nodes connected up by "NEXT" edges. 样本数据是通过“NEXT”边连接的Person节点。

create database plocal:people
create class Person extends V
create property Person.name string
create property Person.age float
create property Person.ident integer


insert into Person(name,age,ident) VALUES ("Bob", 30.5, 1)
insert into Person(name,age,ident) VALUES ("Bob", 30.5, 2)
insert into Person(name,age,ident) VALUES   ("Carol", 20.3, 3)
insert into Person(name,age,ident) VALUES   ("Carol", 19, 4)
insert into Person(name,age,ident) VALUES   ("Laura", 75, 5)
insert into Person(name,age,ident) VALUES   ("Laura", 60.5, 6)
insert into Person(name,age,ident) VALUES   ("Laura", 46, 7)
insert into Person(name,age,ident) VALUES   ("Mike", 16.3, 8)
insert into Person(name,age,ident) VALUES   ("David", 86, 9)
insert into Person(name,age,ident) VALUES   ("Alice", 5, 10)
insert into Person(name,age,ident) VALUES   ("Nigel", 69, 11)
insert into Person(name,age,ident) VALUES   ("Carol", 60, 12)
insert into Person(name,age,ident) VALUES   ("Mike", 16.3, 13)
insert into Person(name,age,ident) VALUES   ("Alice", 5, 14)
insert into Person(name,age,ident) VALUES   ("Mike", 16.3, 15)

create class NEXT extends E

create edge NEXT from (select from Person where ident = 1) to (select from Person where ident = 3)
create edge NEXT from (select from Person where ident = 2) to (select from Person where ident = 4)
create edge NEXT from (select from Person where ident = 8) to (select from Person where ident = 12)
create edge NEXT from (select from Person where ident = 5) to (select from Person where ident = 15)
create edge NEXT from (select from Person where ident = 15) to (select from Person where ident = 14)
create edge NEXT from (select from Person where ident = 7) to (select from Person where ident = 13)
create edge NEXT from (select from Person where ident = 13) to (select from Person where ident = 10)
  1. This code snippet finds traversals out from node with ident 5 until it hits an Alice. 此代码段从具有ident 5的节点发现遍历,直到它命中Alice。 It returns one row with a collection of two RIDs: RID for Laura (ident 5) and RID for Mike (ident 15), because Mike is followed by an Alice. 它返回一行,其中包含两个RID的集合:Laura的RID(标识5)和Mike的标识(标识15),因为Mike后面跟着一个Alice。

     select $a let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice') 
  2. If I apply expand to $a , I get a results table with two rows, which contain details for these two records. 如果我将expand应用于$a ,我会得到一个包含两行的结果表,其中包含这两个记录的详细信息。 I don't know if this is due to expand on collections (soon to be deprecated in favour of unwind ?), or expand on RIDs or both. 我不知道这是否是由于expand集合(很快将被弃用以取消unwind ?),或expand RID或两者兼而有之。

     select expand($a) let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice') 
  3. If I unwind $a I get a results table with two rows which contain the RIDs for these two records. 如果我解开$a我会得到一个包含两行的结果表,其中包含这两条记录的RID。 (This makes sense to me) (这对我来说很有意义)

     select $a let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice') unwind $a 
  4. If I expand the unwind from 3, I get the same result as from 2, which does suggest that 2 unwound and expanded the People nodes 如果我expandunwind投3中,我得到了相同的结果,从2,这确实表明,2展开并扩大了人们的节点

     select expand($a) let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice') unwind $a 
  5. I can select the last RID in the collection of RIDs returned by 1. This gives me a table with 1 row, which contains the RID which is the last Person before Alice. 我可以选择由1返回的RID集合中的最后一个RID。这给了我一个包含1行的表,其中包含RID,它是Alice之前的最后一个Person。

     select last($a) let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice') 
  6. If I expand that result, I get 0 rows. 如果我扩展该结果,我得到0行。 This is really not what I expect - I would expect to get one row with the expanded record details for the record details returned in part 5 这真的不是我所期望的 - 我希望在第5部分中返回的记录详细信息的扩展记录详细信息中获得一行

     select expand(last($a)) let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice') 

Can anyone shed any light on why the expand in part 6 does not expand the RID returned by last($a) ? 任何人都可以解释为什么第6部分中的扩展不会扩展last($a)返回的RID last($a)

Also if anyone knows for sure what's going on in part 2 - whether both definitions of expand are being applied at once - that would help. 此外,如果有人确切知道第2部分中发生了什么 - 扩展的两个定义是否同时应用 - 这将有所帮助。

EDIT 编辑

Bizarrely, this code snippet seems to do what I want point 6 to do, but I don't know why. 奇怪的是,这个代码片段似乎做了我想要的第6点,但我不知道为什么。 Thought it might trigger someone's memory about what's going on (the point of my question is to understand why some things work and some don't, rather than to get any query that works in this particular case, so unfortunately having found this working snippet does not close this question.) 认为它可能触发某人对正在发生的事情的记忆(我的问题是要理解为什么有些东西有效,有些则不然,而不是得到任何在这种特殊情况下有效的查询,所以很遗憾找到这个工作片段的确如此不要关闭这个问题。)

select expand(last($a)) 
        from (select from Person where ident = 5)
          let $a = (traverse out('NEXT') from $current while name <> 'Alice')

1) Traverse returns all the records that it visits and that comply with the whilst clause. 1)Traverse返回它访问的所有记录并符合while子句。 In this case, that is only 2 records. 在这种情况下,这只是2条记录。

2) Expand takes all the rids in a 'collection' and returns those records, in effect disposing of the query that contained the collection. 2)展开“收集”中的所有rid并返回这些记录,实际上处理包含该集合的查询。 Actually I've only just found out that they are deprecating expand for unwind, and I'm not sure why as they seem to serve 2 different purposes. 实际上我只是发现他们正在弃用扩展以放松,我不知道为什么因为它们似乎服务于两个不同的目的。 Unwind is more like a JOIN in an RDBMS. 展开更像是RDBMS中的JOIN。

3) You've unwound the results against nothing, so it looks like you only get the $a 'cell' per row, but in fact you are getting nothing and $a. 3)你已经解开了结果,所以看起来你每行只能得到$ a'单元',但实际上你什么都没得到$ a。 Perhaps this will make more the purpose of unwind clearer, select *, $a from (select from Person limit 1) let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice') unwind $a 也许这将使更多的目的放松更清楚, select *, $a from (select from Person limit 1) let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice') unwind $a

4) When you expand, you replace the original query, so all you end up with is the records in the expanded field. 4)展开时,替换原始查询,因此您最终得到的是扩展字段中的记录。

5) Yes. 5)是的。

6) I think you have found a bug. 6)我认为你发现了一个bug。 first() and last() must be returning text or something, not a pointer. first()last()必须返回文本或其他东西,而不是指针。 The following replicates expand(first($a)) and works, hence my presumption of a bug; 以下重复expand(first($a))并起作用,因此我推测出一个错误; select expand($a[0]) let $a = (traverse out('NEXT') from (select from Person where ident = 5) while name <> 'Alice')

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

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