Fix CREATE EDGE to avoid exceptions when the FROM does not exist
@@ -186,7 +186,10 @@ public class CreateEdgesStep extends AbstractExecutionStep {
}
if (toIterator.hasNext() || (toList.size() > 0 && fromIter.hasNext())) {
if (currentFrom == null) {
- throw new OCommandExecutionException("Invalid FROM vertex for edge");
+ if (!fromIter.hasNext()) {
+ finished = true;
+ return;
+ }
}
Object obj = toIterator.next();
@@ -236,15 +239,19 @@ public class CreateEdgesStep extends AbstractExecutionStep {
currentFrom = ((ORID) currentFrom).getRecord();
}
if (currentFrom instanceof OResult) {
- return ((OResult) currentFrom).getVertex().orElse(null);
+ Object from = currentFrom;
+ currentFrom = ((OResult) currentFrom).getVertex()
+ .orElseThrow(() -> new OCommandExecutionException("Invalid vertex for edge creation: " + from.toString()));
}
if (currentFrom instanceof OVertex) {
return (OVertex) currentFrom;
}
if (currentFrom instanceof OElement) {
- return ((OElement) currentFrom).asVertex().orElse(null);
+ Object from = currentFrom;
+ return ((OElement) currentFrom).asVertex()
+ .orElseThrow(() -> new OCommandExecutionException("Invalid vertex for edge creation: " + from.toString()));
}
- return null;
+ throw new OCommandExecutionException("Invalid vertex for edge creation: " + currentFrom.toString());
}
@Override
