ATLAS-3762: Improve edge creation using genuine iterator. Part 2
This commit is contained in:
parent
f467229294
commit
23aea76fff
|
|
@ -48,10 +48,19 @@ public interface AtlasGraph<V, E> {
|
|||
AtlasEdge<V, E> addEdge(AtlasVertex<V, E> outVertex, AtlasVertex<V, E> inVertex, String label);
|
||||
|
||||
/**
|
||||
* Adds a vertex to the graph.
|
||||
*
|
||||
* Fetch edges between two vertices using relationshipLabel
|
||||
* @param fromVertex
|
||||
* @param toVertex
|
||||
* @param relationshipLabel
|
||||
* @return
|
||||
*/
|
||||
AtlasEdge<V, E> getEdgeBetweenVertices(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipLabel);
|
||||
|
||||
/**
|
||||
* Adds a vertex to the graph.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
AtlasVertex<V, E> addVertex();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -171,6 +171,17 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
|
|||
return traversal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasEdge getEdgeBetweenVertices(AtlasVertex fromVertex, AtlasVertex toVertex, String edgeLabel) {
|
||||
GraphTraversal gt = V(fromVertex.getId()).outE(edgeLabel).where(__.otherV().hasId(toVertex.getId()));
|
||||
Object o = gt.hasNext() ? gt.next() : null;
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return GraphDbObjectFactory.createEdge(this, (Edge) o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasEdge<AtlasJanusVertex, AtlasJanusEdge> getEdge(String edgeId) {
|
||||
Iterator<Edge> it = getGraph().edges(edgeId);
|
||||
|
|
|
|||
|
|
@ -739,19 +739,21 @@ public final class GraphHelper {
|
|||
|
||||
public static List<AtlasVertex> getPropagationEnabledClassificationVertices(AtlasVertex entityVertex) {
|
||||
List<AtlasVertex> ret = new ArrayList<>();
|
||||
Iterable edges = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL).edges();
|
||||
if (entityVertex.hasEdges(AtlasEdgeDirection.OUT, CLASSIFICATION_LABEL)) {
|
||||
Iterable edges = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL).edges();
|
||||
|
||||
if (edges != null) {
|
||||
Iterator<AtlasEdge> iterator = edges.iterator();
|
||||
if (edges != null) {
|
||||
Iterator<AtlasEdge> iterator = edges.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
AtlasEdge edge = iterator.next();
|
||||
while (iterator.hasNext()) {
|
||||
AtlasEdge edge = iterator.next();
|
||||
|
||||
if (edge != null) {
|
||||
AtlasVertex classificationVertex = edge.getInVertex();
|
||||
if (edge != null) {
|
||||
AtlasVertex classificationVertex = edge.getInVertex();
|
||||
|
||||
if (isPropagationEnabled(classificationVertex)) {
|
||||
ret.add(classificationVertex);
|
||||
if (isPropagationEnabled(classificationVertex)) {
|
||||
ret.add(classificationVertex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -784,36 +784,13 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
|
|||
AtlasEdge ret = null;
|
||||
|
||||
if (toVertex.hasEdges(AtlasEdgeDirection.IN, relationshipLabel) && fromVertex.hasEdges(AtlasEdgeDirection.OUT, relationshipLabel)) {
|
||||
long fromVertexOutgoingEdgeCount = graphHelper.getOutGoingEdgesCountByLabel(fromVertex, relationshipLabel);
|
||||
long toVertexIncomingEdgeCount = graphHelper.getInComingEdgesCountByLabel(toVertex, relationshipLabel);
|
||||
if (toVertexIncomingEdgeCount < fromVertexOutgoingEdgeCount) {
|
||||
Iterator<AtlasEdge> edgesIteratorIn = graphHelper.getIncomingEdgesByLabel(toVertex, relationshipLabel);
|
||||
ret = getActiveEdgeFromList(edgesIteratorIn, fromVertex.getId(), e -> e.getOutVertex().getId());
|
||||
} else {
|
||||
Iterator<AtlasEdge> edgesIteratorOut = graphHelper.getOutGoingEdgesByLabel(fromVertex, relationshipLabel);
|
||||
ret = getActiveEdgeFromList(edgesIteratorOut, toVertex.getId(), e -> e.getInVertex().getId());
|
||||
}
|
||||
ret = graph.getEdgeBetweenVertices(fromVertex, toVertex, relationshipLabel);
|
||||
}
|
||||
|
||||
RequestContext.get().endMetricRecord(metric);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private AtlasEdge getActiveEdgeFromList(Iterator<AtlasEdge> edgesIterator, Object vertexIdToCompare, Function<AtlasEdge, Object> edgeIdFn) {
|
||||
while (edgesIterator != null && edgesIterator.hasNext()) {
|
||||
AtlasEdge edge = edgesIterator.next();
|
||||
if (edge != null) {
|
||||
Status status = graphHelper.getStatus(edge);
|
||||
|
||||
if ((status == null || status == ACTIVE) && edgeIdFn.apply(edge).equals(vertexIdToCompare)) {
|
||||
return edge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Long getRelationshipVersion(AtlasRelationship relationship) {
|
||||
Long ret = relationship != null ? relationship.getVersion() : null;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue