问题描述
我在创建边缘时遇到了两个问题.
I have 2 problems with edge creation.
首先,我正在使用批处理命令创建一堆顶点和边.有时,在尚未创建的顶点之间创建边(这取决于输入顺序,目前无法控制).当然,东方服务器会抛出异常而不是静默失败.我找不到告诉它跳过它或避免创建边缘的方法.在 Neo4j 中,您可以:
First, I'm creating a bunch of vertices and edges with a batch command. Sometimes and edge is created between vertices that havent been created yet (it depends on the input order, and for now that cannot be controlled). Of course Orient server throws an exception instead of failing silently. I couldnt find a way of telling it to skip it or avoid creating the edge. In Neo4j you can do:
MATCH (a {id:'zz'}),(b {id:'yy'})
CRAETE UNIQUE (a)-[r:REL {'id': 'xx'}]->(b)
因此,如果 a 或 b 不存在,则不会创建任何边.
So if a or b don't exist, no edge is created.
有没有办法做这样的事情?之前做一个选择来检查 a 和 b 的存在是不好的,因为顶点可以在上一个批处理命令中创建,因此不存在于数据库中,所以它必须是 osql 命令的一部分.
Is there a way to do something like that? Doing a select before to check for existence of both a and b is no good because the vertex could be created in the previous batch command, thus not present in the db, so it has to be part of the osql command.
第二,与这个问题相关,我想我可以构建一个脚本,这样我就可以分配查找a和b的选择strong> 到一个变量.
Second, related to this issue, I was thinking i could build a script so I could assign the select that looks for both a and b to a variable.
BEGIN
LET source = SELECT FROM V WHERE id = 'zz'
LET target = SELECT FROM V WHERE id = 'yy'
<< some sort of condition based on source != null and target != null? >>
LET edge = CREATE EDGE REL FROM $source TO $target
COMMIT
是否可以根据源和目标的条件发出创建命令?.如果是这样,那将解决这两个问题.
Is it possible to issue the creation command base on a condition on both source and target?. If so, that would solve both issues.
推荐答案
自 v. 2.1.7 开始提供
it will be available since v. 2.1.7
https://github.com/orienttechnologies/orientdb-docs/blob/master/SQL-batch.md#conditional-execution
这篇关于OrientDB 在批处理/脚本中创建边缘问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!