Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit 926850d

Browse files
committed
added run scripts for easy execution
1 parent cbe52f6 commit 926850d

File tree

10 files changed

+52
-21
lines changed

10 files changed

+52
-21
lines changed

generate.sh

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
source ./settings.sh
22

3-
mvn clean test-compile exec:java -Dexec.mainClass=org.neo4j.batchimport.TestDataGenerator -Dexec.classpathScope=test -Dexec.args=sorted
3+
mvn clean test-compile exec:java -Dexec.mainClass=org.neo4j.batchimport.TestDataGenerator -Dexec.classpathScope=test \
4+
-Dexec.args="$1 $2 $3 $4" | grep -iv '\[\(INFO\|debug\)\]'

import.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DB=${1-target/graph.db}
2+
shift
3+
NODES=${1-nodes.csv}
4+
shift
5+
RELS=${1-rels.csv}
6+
shift
7+
mvn compile exec:java -Dexec.mainClass="org.neo4j.batchimport.Importer" \
8+
-Dexec.args="batch.properties $DB $NODES $RELS $@" | grep -iv '\[\(INFO\|debug\)\]'

import_csv.sh

100644100755
File mode changed.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<version>1.9-SNAPSHOT</version>
66
<name>Neo4j Batch Importer</name>
77
<properties>
8+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>Å
89
<neo4j.version>1.9</neo4j.version>
910
<license-text.header>GPL-3-header.txt</license-text.header>
1011
</properties>

run.sh

100644100755
File mode changed.

sample/import.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
echo "Run in main directory sh sample/import.sh"
2-
mvn test-compile exec:java -Dexec.mainClass="org.neo4j.batchimport.Importer" -Dexec.args="sample/batch.properties target/graph.db sample/nodes.csv,sample/nodes2.csv sample/rels.csv"
2+
mvn test-compile exec:java -Dexec.mainClass="org.neo4j.batchimport.Importer" \
3+
-Dexec.args="sample/batch.properties target/graph.db sample/nodes.csv,sample/nodes2.csv sample/rels.csv"

settings.sh

100644100755
File mode changed.

src/main/java/org/neo4j/batchimport/Importer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.*;
1818
import java.util.zip.GZIPInputStream;
1919

20+
import static org.neo4j.batchimport.Utils.join;
2021
import static org.neo4j.index.impl.lucene.LuceneIndexImplementation.EXACT_CONFIG;
2122
import static org.neo4j.index.impl.lucene.LuceneIndexImplementation.FULLTEXT_CONFIG;
2223

@@ -61,7 +62,9 @@ protected BatchInserter createBatchInserter(File graphDb, Config config) {
6162
// todo nodes and rels-files in config
6263
// todo graphdb in config
6364
public static void main(String[] args) throws IOException {
64-
System.err.println("Usage java -jar batchimport.jar data/dir nodes.csv relationships.csv [node_index node-index-name fulltext|exact nodes_index.csv rel_index rel-index-name fulltext|exact rels_index.csv ....]");
65+
System.err.println("Usage: Importer data/dir nodes.csv relationships.csv [node_index node-index-name fulltext|exact nodes_index.csv rel_index rel-index-name fulltext|exact rels_index.csv ....]");
66+
System.err.println("Using: Importer "+join(args," "));
67+
System.err.println();
6568

6669
final Config config = Config.convertArgumentsToConfig(args);
6770

src/main/java/org/neo4j/batchimport/Utils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ private static String formatNode(NodeRecord record) {
5858
return String.format("Node[%d] -> %d, .%d", record.getId(), record.getNextRel(), record.getNextProp());
5959
}
6060

61+
static String join(String[] types, String delim) {
62+
StringBuilder sb =new StringBuilder();
63+
for (String type : types) {
64+
sb.append(type).append(delim);
65+
}
66+
return sb.substring(0, sb.length() - delim.length());
67+
}
6168
}

src/test/java/org/neo4j/batchimport/TestDataGenerator.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,65 @@
1414
@Ignore
1515
public class TestDataGenerator {
1616

17-
private static int NODES = 1 * 1000 * 1000;
17+
private static final int NODES = 1 * 1000 * 1000;
1818
private static final int RELS_PER_NODE = 50;
1919
private static final String[] TYPES = {"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN"};
20-
public static final int NUM_TYPES = 10;
2120

2221
public static void main(String...args) throws IOException {
22+
System.out.println("Usage: TestDataGenerator NODES RELS_PER_NODE TYPE1,TYPE2,TYPE3 sorted");
2323
long relCount=0, time = System.currentTimeMillis();
24+
25+
int nodes = args.length > 0 ? Integer.parseInt(args[0]) : NODES;
26+
int relsPerNode = args.length > 1 ? Integer.parseInt(args[1]) : RELS_PER_NODE;
27+
String[] types = args.length > 2 ? args[2].split(",") : TYPES;
28+
final boolean sorted = args.length > 0 && args[args.length-1].equalsIgnoreCase("sorted");
29+
System.out.println("Using: TestDataGenerator "+nodes+" "+relsPerNode+" "+ Utils.join(types, ",")+" "+(sorted?"sorted":""));
30+
2431
BufferedWriter nodeFile = new BufferedWriter(new FileWriter("nodes.csv"));
2532
nodeFile.write("Node\tRels\tProperty\tCounter:int\n");
2633
BufferedWriter relFile = new BufferedWriter(new FileWriter("rels.csv"));
2734
relFile.write("Start\tEnde\tType\tProperty\tCounter:long\n");
28-
final boolean sorted = args.length > 0 && args[0].equalsIgnoreCase("sorted");
35+
2936
if (sorted) {
30-
relCount = generateSortedRels(relCount, nodeFile, relFile);
37+
relCount = generateSortedRels(relCount, nodeFile, relFile, nodes, relsPerNode, types);
3138
} else {
32-
relCount = generateRandomRels(relCount, nodeFile, relFile);
39+
relCount = generateRandomRels(relCount, nodeFile, relFile, nodes, relsPerNode, types);
3340
}
3441
nodeFile.close();
3542
relFile.close();
36-
System.out.println("Creating " + NODES + " Nodes and " + relCount + (sorted? " sorted " : "") + " Relationships took " + ((System.currentTimeMillis() - time) / 1000) + " seconds.");
43+
long seconds = (System.currentTimeMillis() - time) / 1000;
44+
System.out.println("Creating " + nodes + " Nodes and " + relCount + (sorted? " sorted " : "") + " Relationships took " + seconds + " seconds.");
3745
}
3846

39-
private static long generateRandomRels(long relCount, BufferedWriter nodeFile, BufferedWriter relFile) throws IOException {
47+
private static long generateRandomRels(long relCount, BufferedWriter nodeFile, BufferedWriter relFile, int nodes, int relsPerNode, String[] types) throws IOException {
4048
Random rnd = new Random();
41-
for (int node = 0; node < NODES; node++) {
42-
final int rels = rnd.nextInt(RELS_PER_NODE);
49+
int numTypes = types.length;
50+
for (int node = 0; node < nodes; node++) {
51+
final int rels = rnd.nextInt(relsPerNode);
4352
nodeFile.write(node+"\t"+rels+"\tTEST\t"+node+"\n");
4453
for (int rel = rels; rel >= 0; rel--) {
4554
relCount++;
46-
final int node1 = rnd.nextInt(NODES);
47-
final int node2 = rnd.nextInt(NODES);
48-
relFile.write(node1 + "\t" + node2 + "\t" + TYPES[rel % NUM_TYPES] + "\t" + "Property"+"\t" + relCount+ "\n");
55+
final int node1 = rnd.nextInt(nodes);
56+
final int node2 = rnd.nextInt(nodes);
57+
relFile.write(node1 + "\t" + node2 + "\t" + types[rel % numTypes] + "\t" + "Property"+"\t" + relCount+ "\n");
4958
}
5059
}
5160
return relCount;
5261
}
53-
private static long generateSortedRels(long relCount, BufferedWriter nodeFile, BufferedWriter relFile) throws IOException {
62+
private static long generateSortedRels(long relCount, BufferedWriter nodeFile, BufferedWriter relFile, int nodes, int relsPerNode, String[] types) throws IOException {
5463
Random rnd = new Random();
55-
for (int node = 0; node < NODES; node++) {
56-
final int rels = rnd.nextInt(RELS_PER_NODE);
64+
int numTypes = types.length;
65+
for (int node = 0; node < nodes; node++) {
66+
final int rels = rnd.nextInt(relsPerNode);
5767
nodeFile.write(node+"\t"+rels+"\tTEST\t"+node+"\n");
5868
for (int rel = rels; rel >= 0; rel--) {
5969
relCount++;
60-
final int target = node + rnd.nextInt(NODES-node);
70+
final int target = node + rnd.nextInt(nodes -node);
6171
final boolean outgoing = rnd.nextBoolean();
6272
if (outgoing) {
63-
relFile.write(node + "\t" + target + "\t" + TYPES[rel % NUM_TYPES] + "\t" + "Property"+"\t" + relCount+ "\n");
73+
relFile.write(node + "\t" + target + "\t" + types[rel % numTypes] + "\t" + "Property"+"\t" + relCount+ "\n");
6474
} else {
65-
relFile.write(target + "\t" + node + "\t" + TYPES[rel % NUM_TYPES] + "\t" + "Property"+"\t" + relCount+ "\n");
75+
relFile.write(target + "\t" + node + "\t" + types[rel % numTypes] + "\t" + "Property"+"\t" + relCount+ "\n");
6676
}
6777
}
6878
}

0 commit comments

Comments
 (0)