Re: how to load a CSV file into janusgraph


a.mar...@...
 

For adding vertex, this is using gremlin 

use something like this 

toInt = { Integer.parseInt(it)}
toShort
= { Short.parseShort(it) }
toByte
= { Byte.parseByte(it) }
toLong
= { Long.parseLong(it) }
toDate
= { Date.parse("yyyy-mm-dd",it) }
toBoolean
= { Boolean.parseBoolean(it) }
toFloat
= { Float.parseFloat(it) }


importFile
= { gr, file, adder ->
               
// Track Timing Stats
                start
= new Date();


               
// Make sure retries are built in
                attempt
= 0;


               
while (attempt < ATTEMPTS_MAX) {
                        attempt
++;
                       
try {
                                lines
= 0;
                               
// Load lines to DB
                                file
.eachLine { lines++; if (lines > 1) adder (gr, it) };
                                gr
.tx().commit();
                               
// Ensure consistency
                                attempt
= ATTEMPTS_MAX;
                               
// Print timing stats
                                stop
= new Date();
                                println
"Lines Processed: ["+ lines +"], Time Taken: ["+ TimeCategory.minus(stop, start) +"]";


                       
} catch (ex) {
                               
// Rollback and retry in the event of an error
                                println
"Error " + ex.toString();
                                println
"Retrying after 1 second...";
                                gr
.tx().commit();
                                sleep
(1000);
                       
}
               
}
       
};






addUser
= { gr, data ->
                ch
= data.split(",");
                gr
.addVertex(
                label
, 'User',
               
'property1', (ch[0]),
               
'property2', toShort(ch[1]),
               
'property3', toLong(ch[2]),
               
'property4', toDate(ch[3])
               
)
};


importFile
(g,file_name,addUser)




On Wednesday, June 14, 2017 at 9:44:16 AM UTC-7, Elizabeth wrote:
Hi all,

I am new to Janusgraph, I have dived into docs of Janusgraph for almost two weeks, nothing found.
I could only gather the scatted information and most of the time it will prompt some errors.
Could anyone supply a complete example of bulk loading or loading a CSV file into Janusgraph, please?
Any little help is appreated!

Best regards,

Elis.

Join janusgraph-users@lists.lfaidata.foundation to automatically receive all group messages.