Skip to content

vertex.getEdges(OUT/IN, ...) Returns the same edge for out edges #1454

@ironluca

Description

@ironluca

The API

Iterable<Edge> com.arcadedb.graph.Vertex.getEdges(DIRECTION direction, String... edgeTypes)
Return the same edge(s) irrespective of the direction given.

I understand that ArcadeDB edges are bi-directional, is the above intentional?

However, the API
long com.arcadedb.graph.Vertex.countEdges(DIRECTION direction, String edgeType)
gives the correct count of the edges.

The test class

public class VtxEdgeDirectionTest {

    public static void main(String[] args) throws Exception{
        
        RemoteDatabase db=new RemoteDatabase("wartales.optimas.ai", 
                                             2481, 
                                             "test_db", 
                                             "root", 
                                             "password");

        //Create FromVtx Type
        db.command("sql", "CREATE VERTEX TYPE FromVtx IF NOT EXISTS");

        //Create ToVtx Type
        db.command("sql", "CREATE VERTEX TYPE ToVtx IF NOT EXISTS");

        //Create ConEdge Type
        db.command("sql", "CREATE EDGE TYPE ConEdge IF NOT EXISTS");

        /*
         * Create the vertices and edges
         * (Fromvtx) ---[ConEdge]---> (ToVtx)
         */
        Vertex fromVtx=db.command("sql", "CREATE VERTEX FromVtx").next().getVertex().get();
        Vertex toVtx=db.command("sql", "CREATE VERTEX ToVtx").next().getVertex().get();
        Edge conEdg=fromVtx.newEdge("ConEdge", toVtx, true);

        String fromvtxRid=fromVtx.getIdentity().toString();
        String conEdgRid=conEdg.getIdentity().toString();
        String tovtxRid=toVtx.getIdentity().toString();

        System.out.println("( fromvtx ["+fromvtxRid+"] )---< conEdg ["+conEdgRid+"] >--->( toVtx ["+tovtxRid+"] )");

        //Out vertex of edge (fromVtx)
        System.out.println("edg.getOutVertex() = "+conEdg.getOutVertex());

        //In vertex of edge (fromVtx)
        System.out.println("conEdg.getInVertex() = "+conEdg.getInVertex());

        System.out.println("======== IN and OUT Edge fromVtx and edge count ========");
        System.out.println("fromVtx.countEdges(DIRECTION.OUT, \"ConEdge\") --> "+fromVtx.countEdges(DIRECTION.OUT, "ConEdge"));
        System.out.println("fromVtx.countEdges(DIRECTION.IN, \"ConEdge\") --> "+fromVtx.countEdges(DIRECTION.IN, "ConEdge"));
        System.out.println("fromVtx.getEdges(DIRECTION.OUT, \"ConEdge\") --> "+fromVtx.getEdges(DIRECTION.OUT, "ConEdge").iterator().next());
        System.out.println("fromVtx.getEdges(DIRECTION.IN, \"ConEdge\") --> "+fromVtx.getEdges(DIRECTION.IN, "ConEdge").iterator().next());

        System.out.println("======== IN and OUT Edge toVtx and edge count ========");
        System.out.println("toVtx.countEdges(DIRECTION.OUT, \"ConEdge\") --> "+toVtx.countEdges(DIRECTION.OUT, "ConEdge"));
        System.out.println("toVtx.countEdges(DIRECTION.IN, \"ConEdge\") --> "+toVtx.countEdges(DIRECTION.IN, "ConEdge"));
        System.out.println("toVtx.getEdges(DIRECTION.OUT, \"ConEdge\") --> "+toVtx.getEdges(DIRECTION.OUT, "ConEdge").iterator().next());
        System.out.println("toVtx.getEdges(DIRECTION.IN, \"ConEdge\") --> "+toVtx.getEdges(DIRECTION.IN, "ConEdge").iterator().next());


        System.out.println("======== Retrieval by getVertices ========");
        System.out.println("fromVtx.getVertices(DIRECTION.OUT, \"ConEdge\") --> "+fromVtx.getVertices(DIRECTION.OUT, "ConEdge").iterator().next());
        System.out.println("toVtx.getVertices(DIRECTION.IN, \"ConEdge\") --> "+toVtx.getVertices(DIRECTION.IN, "ConEdge").iterator().next());

        db.close();

    }//main closing

}//class closing

The console output

( fromvtx [#13:1] )---< conEdg [#52:1] >--->( toVtx [#37:1] )
edg.getOutVertex() = #13:1[?]
conEdg.getInVertex() = #37:1[?]
======== IN and OUT Edge fromVtx and edge count ========
fromVtx.countEdges(DIRECTION.OUT, "ConEdge") --> 1
fromVtx.countEdges(DIRECTION.IN, "ConEdge") --> 0
fromVtx.getEdges(DIRECTION.OUT, "ConEdge") --> #52:1[?]
fromVtx.getEdges(DIRECTION.IN, "ConEdge") --> #52:1[?]
======== IN and OUT Edge toVtx and edge count ========
toVtx.countEdges(DIRECTION.OUT, "ConEdge") --> 0
toVtx.countEdges(DIRECTION.IN, "ConEdge") --> 1
toVtx.getEdges(DIRECTION.OUT, "ConEdge") --> #52:1[?]
toVtx.getEdges(DIRECTION.IN, "ConEdge") --> #52:1[?]
======== Retrieval by getVertices ========
fromVtx.getVertices(DIRECTION.OUT, "ConEdge") --> #37:1[?]
toVtx.getVertices(DIRECTION.IN, "ConEdge") --> #13:1[?]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions