使用相交函数的 OrientDB 查询中的临时 collection

Temporary collection in an OrientDB query using the intersect function

我想构建一个概念上类似的查询:

SELECT INTERSECT(["12","34"],(SELECT custom_id FROM USER))

第一个 collection 理想情况下是即时制作的。否则可以做一个临时的collection吗?这个 collection 的限制是什么?它可以包含数千个元素吗?

我创建了一个数据库来测试你的案例,有不同的方法可以继续。 结构:

  • 类:用户;
  • 属性:custom_id 作为整数(在用户上创建);
  • 索引:User.custom_id UNIQUE(我建议创建一个索引以加快操作速度,以防您处理数千条记录)。

在你的例子中,参数是手动传递的,并与查询结果进行比较,你可以试试这个:

select intersect($a.left, $b.right)
let $a = (select [12, 34] as left), 
    $b = (select custom_id as right from User)

否则您只能使用查询来获取结果

select intersect($a.left, $b.right)
let $a = (select custom_id as left from User where custom_id = 12 or custom_id = 34), 
    $b = (select other_id as right from otherClass)

或者第三种方法是即时构建两个列表

select intersect($a.left, $b.right)
let $a = (select [12, 34] as left), 
    $b = (select [1, 5, 9, 12, 28, 34, 45] as right)

正在执行

select $a
let $a = (select [12, 34] as mylist)

Returns

[{"mylist":[12,34]}]

正在执行

select $a.mylist
let $a = (select [12, 34] as mylist)

Returns

[[12,34]]

正在执行

select $a.mylist[0]
let $a = (select [12, 34] as mylist)

Returns

[12,34]

正在执行

select intersect($a.left[0], $b.right[0])
let $a = (select [12, 34] as left), 
    $b = (select [1, 5, 9, 12, 28, 34, 45] as right)

Returns

[34, 12]

因此从之前的答案来看,[0] 后缀是获得 $a 正确引用的关键。需要 list() 函数将结果集行组合成 list/array.

解决方法是:

select intersect($a.left[0], $b.right[0])
let $a = (select [12, 34] as left), 
    $b = (select list(custom_id) as right from User)