我有这个图:
我正在尝试使用OrientDB v3.0的“SQL语法”编写一个查询,该查询从客户端开始并遵循读取路径(X表示:并且没有与客户端的Have
关系)。
我可以获得细分,但我找不到如何走到联系人。 docs have many examples但只走一条路。
我试过这些查询没有成功:
SELECT FROM (TRAVERSE out("Access").out("Contain") FROM (SELECT @rid FROM Client where myId = 30543) MAXDEPTH 1)
SELECT FROM (
TRAVERSE out("Contain") FROM
(TRAVERSE out("Access") FROM (SELECT @rid FROM Client where myId = 30543) MAXDEPTH 1)
MAXDEPTH 1
)
SELECT out('Access').out("Contain") FROM Client WHERE myId = 30543
你有任何信息来完成这个遍历吗?
我正在使用Node.js API:
const pool = await orient.getPool();
const session = await pool.acquire();
logger.info('Running query...');
session.command(`SELECT out('Access').out("Contain") FROM Client WHERE myId = 30543`)
.on('data', (data) => {
if (data.out_Contain && data.out_Contain.delegate) {
logger.info('Segment %s contains %o Contact', data['@rid'].toString(), data.out_Contain.delegate.size);
} else if (data['@rid']) {
logger.info('Segment %s contains %o Contact', data['@rid'].toString(), data);
} else {
logger.info('Data %o', data);
}
})
.on('error', (err) => {
logger.error(err);
})
.on('end', () => {
console.timeEnd('query');
logger.info('End of the stream');
process.emit('SIGINT');
});
logger.debug('Registering SIGINT');
process.once('SIGINT', async () => {
await session.close();
await pool.close();
await orient.stop();
});
请尝试使用此代码:
"select out_{edgeclass}.in from (select expand(out_{edgeclass}.in) from {Vetex} where {condition})"
match
更适合这种任务。
使用SELECT
:
在第一个版本中,查询更具可读性,但它不使用索引,因此在执行时间方面不太理想。第二个和第三个使用索引(如果它们存在)(在子查询中的Person.name或City.name上),但它们更难阅读。他们使用哪个索引仅取决于您编写查询的方式。
但匹配:
查询执行程序为您优化查询,选择它们存在的索引。此外,查询变得更具可读性,尤其是在复杂情况下,例如多个嵌套的SELECT查询。
这里是正确的查询:
SELECT EXPAND(contatti)
FROM (
match { class: Client, as: user, where : ( myId = 30543)}
.out('Access')
.out('Contain'){ class:Contact, as:contatti, where: (gender= 'M')},
NOT {as:user} -Have-> {as:contatti}
RETURN DISTINCT contatti LIMIT 1000
)