Skip to content

Commit

Permalink
Supported "batchSize" on importing graphml
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jul 23, 2015
1 parent b424f8d commit daa3057
Showing 1 changed file with 17 additions and 6 deletions.
Expand Up @@ -56,6 +56,7 @@ public class OGraphMLReader {
private String edgeIdKey = null;
private String edgeLabelKey = null;
private boolean storeVertexIds = false;
private int batchSize = 1000;

/**
* @param graph
Expand All @@ -76,7 +77,7 @@ public OGraphMLReader(OrientBaseGraph graph) {
* thrown when the GraphML data is not correctly formatted
*/
public void inputGraph(final Graph inputGraph, final InputStream graphMLInputStream) throws IOException {
inputGraph(inputGraph, graphMLInputStream, 1000, null, null, null);
inputGraph(inputGraph, graphMLInputStream, batchSize, null, null, null);
}

/**
Expand All @@ -90,7 +91,7 @@ public void inputGraph(final Graph inputGraph, final InputStream graphMLInputStr
* thrown when the GraphML data is not correctly formatted
*/
public void inputGraph(final Graph inputGraph, final String filename) throws IOException {
inputGraph(inputGraph, filename, 1000, vertexIdKey, null, null);
inputGraph(inputGraph, filename, batchSize, vertexIdKey, null, null);
}

/**
Expand Down Expand Up @@ -349,7 +350,7 @@ public void setEdgeLabelKey(String edgeLabelKey) {
* thrown when the GraphML data is not correctly formatted
*/
public void inputGraph(final InputStream graphMLInputStream) throws IOException {
inputGraph(this.graph, graphMLInputStream, 1000, this.vertexIdKey, this.edgeIdKey, this.edgeLabelKey);
inputGraph(this.graph, graphMLInputStream, batchSize, this.vertexIdKey, this.edgeIdKey, this.edgeLabelKey);
}

/**
Expand All @@ -361,7 +362,7 @@ public void inputGraph(final InputStream graphMLInputStream) throws IOException
* thrown when the GraphML data is not correctly formatted
*/
public void inputGraph(final String filename) throws IOException {
inputGraph(this.graph, filename, 1000, this.vertexIdKey, this.edgeIdKey, this.edgeLabelKey);
inputGraph(this.graph, filename, batchSize, this.vertexIdKey, this.edgeIdKey, this.edgeLabelKey);
}

/**
Expand All @@ -388,26 +389,36 @@ public void inputGraph(final InputStream graphMLInputStream, int bufferSize) thr
* @throws IOException
* thrown when the GraphML data is not correctly formatted
*/
public void inputGraph(final String filename, int bufferSize) throws IOException {
public void inputGraph(final String filename, final int bufferSize) throws IOException {
inputGraph(this.graph, filename, bufferSize, this.vertexIdKey, this.edgeIdKey, this.edgeLabelKey);
}

public OGraphMLReader setOptions(final Map<String, List<String>> opts) {
for (Map.Entry<String, List<String>> opt : opts.entrySet()) {
if (opt.getKey().equalsIgnoreCase("storeVertexIds")) {
storeVertexIds = Boolean.parseBoolean(opt.getValue().get(0));
} else if (opt.getKey().equalsIgnoreCase("batchSize")) {
batchSize = Integer.parseInt(opt.getValue().get(0));
}
}
return this;
}

public int getBatchSize() {
return batchSize;
}

public void setBatchSize(final int batchSize) {
this.batchSize = batchSize;
}

protected void mapId(final Map<String, ORID> vertexMappedIdMap, final String vertexId, final ORID rid) {
if (vertexMappedIdMap.containsKey(vertexId))
throw new IllegalArgumentException("Vertex with id '" + vertexId + "' has been already loaded");
vertexMappedIdMap.put(vertexId, rid);
}

private Object typeCastValue(String key, String value, Map<String, String> keyTypes) {
private Object typeCastValue(final String key, final String value, final Map<String, String> keyTypes) {
String type = keyTypes.get(key);
if (null == type || type.equals(GraphMLTokens.STRING))
return value;
Expand Down

0 comments on commit daa3057

Please sign in to comment.