orientdb let子查询中的值在哪里

时间:2018-08-06 13:16:25

标签: orientdb

使用:通过 OrientDB Studio 附带的 OrientDB 3.0.4 ,带有官方 OrientDB docker镜像

如何在子查询let中使用where变量?

给出一个具有2个值的测试类:

insert into test content {a: 1};
insert into test content {a: 2};

测试:

select a from test;

返回:

a
1
2

使用let变量的另一项测试按预期工作:

select a, $b from test let $b = a;

返回:

a  $b
1  1
2  2

现在测试在let中使用子查询选择

select a, $b, $c from test let $b = a, $c = (select a from test);

也可以按预期工作并返回:

a  $b  $c
1  1   [{"a":1},{"a":2}]
2  2   [{"a":1},{"a":2}]

现在有问题的部分: 如何在$b的子选择中使用变量$c

所有这些嵌套选择均不返回任何内容:

select a, $b, $c from test let $b = a, $c = (select a from test where a = $parrent.a);
select a, $b, $c from test let $b = a, $c = (select a from test where a = $parrent.$b);
select a, $b, $c from test let $b = a, $c = (select a from test where a = $parrent.b);
select a, $b, $c from test let $b = a, $c = (select a from test where a = $parent.$current.$b);
select a, $b, $c from test let $b = a, $c = (select a from test where a = $parent.$current.b);
select a, $b, $c from test let $b = a, $c = (select a from test where a = $parent.current.$b);
select a, $b, $c from test let $b = a, $c = (select a from test where a = $parent.current.b);
select a, $b, $c from test let $b = a, $c = (select a from test where a = $current.$b);
select a, $b, $c from test let $b = a, $c = (select a from test where a = $current.b);
select a, $b, $c from test let $b = a, $c = (select a from test where a = b);

结果:

a  $b  $c
1  1   []
2  2   []

我在所有站点/论坛/官方文档的子查询中发现了用于访问let变量的所有这些变体,但实际上没有任何作用。甚至来自https://orientdb.com/docs/3.0.x/sql/SQL-Query.html#let-block的官方示例也不起作用,并且失败了,com.orientechnologies.orient.core.exception.OCommandExecutionException: Class $parent not found DB name="test"

SELECT FROM Document LET $temp = ( SELECT @rid, $depth FROM (TRAVERSE 
      V.OUT, E.IN FROM $parent.current ) WHERE @class = 'Concept' AND 
      ( id = 'first concept' OR id = 'second concept' )) WHERE $temp.SIZE() > 0;

起初,我认为该变量不会传播到嵌套选择,但这不是事实。使用此选择:

select a, $b, $c from test let $b = a, $c = (select a from test where a = $parrent.current.a);

嵌套选择返回非空列表

a  $b  $c
1  1   [{"a":1},{"a":2}]
2  2   [{"a":1},{"a":2}]

问题在于嵌套选择中的条件始终为true。看起来条件中的a的值被$parent.a的值覆盖,但a语句中的select的值却被覆盖(不返回相同的值a和嵌套a

要覆盖select语句的值,只需在嵌套查询之外声明$a

select $b let $a = 1, $b = (select a, $parent.$a from test where a = $parent.$a);

返回:

[{"a":1,"$parent.$a":1},{"a":1,"$parent.$a":1}]

不使用相同的变量名将返回更好的结果:

select $b let $c = 4, $b = (select a, $parent.$c, c from test where c = $parent.$c);

a仍具有原始值,但嵌套对象中不存在的c保留$parent.$c的值

[{"a":1,"$parent.$c":4,"c":4},{"a":2,"$parent.$c":4,"c":4}]

我做错什么了吗?还是我缺少let变量概念中的某些内容,或者不了解可见性范围?还是查询引擎坏了?

0 个答案:

没有答案