Hi,

Thank you so much for your help. I wrote a java method to do this: 

Details are 
at 
http://stackoverflow.com/questions/30507054/orientdb-create-edge-using-kind-of-self-join/30571722?noredirect=1#comment49219620_30571722


OrientGraph graph = new OrientGraph("remote:localhost/testNode", "root", 
"root");

        for (Vertex v : graph.getVerticesOfClass("Node")) 
        {
            String id = v.getProperty("ID");    

            System.out.println("Checking children of: " + id);
            String sql = "select from node where PARENT_ID = '"+id+"'";

            for (Vertex child : (Iterable<Vertex>) graph.command(
                    new OCommandSQL(sql))
                    .execute()) 
            {
                v.addEdge("parent_of", child);
                System.out.println("\tAdded 'Parent Of' Edge from: " + id + " 
to " + child.getProperty("ID"));

            }               
            graph.commit();
        }


On Monday, 1 June 2015 12:40:08 UTC+5:30, alessand...@gmail.com wrote:
>
> Hi Kapil,
> try this function
>
> var g=orient.getGraph();
> var b=g.command('sql','select from Nodex')
> for(i=0;i<b.length;i++){
>   var id=b[i].getProperty("id"); 
>   var rid=b[i].getId().toString() + "";
>   var sql2="create edge hasParent from " + rid + " to ( select from Nodex 
> where parent_id = '" + id + "')";
>   g.command('sql',sql2);
> }
>
> Bye, Alessandro
>
>
> Il giorno venerdì 29 maggio 2015 09:12:37 UTC+2, Kapil Ranade ha scritto:
>>
>> I have imported hierarchical data into OrientDB from RDMBS using OETL. 
>>
>> In RDBMS we used to store parentId in the same row. e.g. the table 
>> structure is something like this:
>>
>> ID - Name - Parent_ID
>>
>> Corp - Corporate Office - Corp
>>
>> D1 - District Office 1 - Corp
>>
>> D2 - District Office 2 - Corp
>>
>> SO1 - Small Office 1 - D1
>>
>> SO2 - Small Office 2 - D2
>>
>> SO3 - Small Office 3 - D1
>>
>> Now each row is a node in orientdb. I want to create an edge (ParentOf) 
>> from say Corp to D1 and D1 to SO1 and so on.
>>
>> How can I write a query to achieve this? Something along the line of 
>> following?
>>
>> create edge parentOf from (select from node)a to (select from node where 
>> a.id = parent_id)
>>
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to orient-database+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to