在一个查询中返回顶点和边属性

时间:2018-08-13 18:23:54

标签: orientdb

我正在使用OrientDb 3.0.1。

假定以下架构:

CREATE CLASS Product EXTENDS V;
CREATE PROPERTY Product.number STRING (MANDATORY, NOTNULL);

CREATE CLASS Object3D EXTENDS V;
CREATE PROPERTY Object3D.path STRING (NOTNULL);

CREATE CLASS has_Object3D EXTENDS E;
CREATE PROPERTY has_Object3D.in LINK Object3D (MANDATORY, NOTNULL);
CREATE PROPERTY has_Object3D.out LINK V (MANDATORY, NOTNULL);
CREATE PROPERTY has_Object3D.translation EMBEDDEDLIST INTEGER (MANDATORY, NOTNULL);

还有一些数据,例如:

INSERT INTO Product (number) VALUES
('1'), ('2'), ('3');

INSERT INTO Object3D (path) VALUES
("path1"), ("path2"), ("path3");

CREATE EDGE has_Object3D
FROM (SELECT FROM Product WHERE number = '1')
TO (SELECT FROM Object3D WHERE path = 'path1')
SET translation = [0, 0, 0];

问题:仅知道产品编号,如何在一个查询中从Object3D顶点和相应的has_Object3D获取属性?

类似这样的东西(不起作用):

SELECT
  expand(out('has_Object3D')),
  outE('has_Object3D').translation
FROM Product
WHERE number = '1';

谢谢。

2 个答案:

答案 0 :(得分:0)

尝试一下:

select out('has_Object3D').path as path, outE('has_Object3D').translation as translation from Product where number = "1"

这是输出:

+----+-------+-----------+
|#   |path   |translation|
+----+-------+-----------+
|0   |[path1]|[[0,0,0]]  |
+----+-------+-----------+



更新

select out('has_Object3D').path as path, outE('has_Object3D').translation as translation from Product where number = "1" unwind path, translation

这是输出:

+----+-----+-----------+
|#   |path |translation|
+----+-----+-----------+
|0   |path1|[0,0,0]    |
+----+-----+-----------+

希望有帮助

致谢

答案 1 :(得分:0)

但是@ michela-bonizzi发布的答案有效,但顶点之间的边缘不止一个时会出现问题。

以下查询更通用,也可以按预期运行。

MATCH {class: has_Object3D, as: e}.outV() {where: (number = '1')}
RETURN 
  e.inV().path AS `path`,
  e.translation AS `translation`