Skip to content

Commit

Permalink
Added simple logging. Added possibility for config options for batch …
Browse files Browse the repository at this point in the history
…inserter.
  • Loading branch information
dmontag committed Jun 29, 2011
1 parent 3045406 commit fe8c0ba
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main/java/org/neo4j/dataimport/CsvImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,30 @@ public void importTo( BatchInserter target )

public static void main( String[] args )
{
if (args.length != 3)
if ( args.length != 3 )
{
System.out.println( "Args: <target store dir> <nodes CSV> <relationships CSV>" );
System.exit( 1 );
}
BatchInserter batchInserter = new BatchInserterImpl( args[0] );
String storeDir = args[0];
BatchInserter batchInserter = new BatchInserterImpl( storeDir, getConfig( storeDir ) );
new CsvImporter( new File( args[1] ), new File( args[2] ) ).importTo( batchInserter );
batchInserter.shutdown();
}

private static Map<String, String> getConfig( String storeDir )
{
File configFile = new File( storeDir, "neo4j.properties" );
if ( configFile.exists() )
{
return BatchInserterImpl.loadProperties( configFile.getAbsolutePath() );
}
return new HashMap<String, String>();
}

private void importNodes( BatchInserter target ) throws FileNotFoundException
{
long counter = 0;
Scanner nodeScanner = new Scanner( nodes );
while ( nodeScanner.hasNextLine() )
{
Expand All @@ -80,12 +92,13 @@ private void importNodes( BatchInserter target ) throws FileNotFoundException
continue;
}
target.createNode( id, getProperties( properties, nodePropertyKeys ) );
System.out.println( "Creating node " + id );
if ( ++counter % 100000 == 0 ) System.out.println( "Created " + counter + " nodes." );
}
}

private void importRels( BatchInserter target ) throws FileNotFoundException
{
long counter = 0;
Scanner nodeScanner = new Scanner( rels );
while ( nodeScanner.hasNextLine() )
{
Expand Down Expand Up @@ -118,9 +131,8 @@ private void importRels( BatchInserter target ) throws FileNotFoundException
continue;
}
target.createRelationship( from, to, type, getProperties( properties, relPropertyKeys ) );
System.out.println( "Creating rel from " + from + " to " + to );
if ( ++counter % 100000 == 0 ) System.out.println( "Created " + counter + " relationships." );
}

}

private List<Pair<String, String>> parsePropertyKeys( List<String> properties )
Expand Down Expand Up @@ -158,7 +170,6 @@ private Map<String, Object> getProperties( List<String> nodeParts, List<Pair<Str
properties.put( key, getPropertyValue( value, pair.other() ) );
}
}
System.out.println( String.format( "Props: %s", properties ) );
return properties;
}

Expand Down

0 comments on commit fe8c0ba

Please sign in to comment.