Clean up / reorganize non-useful / duplicate code

This commit is contained in:
Michael Lieberman
2015-01-19 14:38:28 -05:00
parent 6196dc7d8f
commit 332df1fea4
16 changed files with 183 additions and 186 deletions

View File

@@ -109,7 +109,8 @@ public final class AccumuloBulkIngester {
*/
public PropertyBuilder addVertex(String id) throws MutationsRejectedException {
Mutation m = new Mutation(id);
m.put(AccumuloGraph.LABEL, AccumuloGraph.EXISTS, AccumuloGraph.EMPTY);
m.put(Constants.LABEL.getBytes(),
Constants.EXISTS.getBytes(), Constants.EMPTY);
vertexWriter.addMutation(m);
return new PropertyBuilder(vertexWriter, id);
}
@@ -169,14 +170,18 @@ public final class AccumuloBulkIngester {
*/
public PropertyBuilder addEdge(String id, String src, String dest, String label) throws MutationsRejectedException {
Mutation m = new Mutation(id);
m.put(AccumuloGraph.LABEL, (dest + "_" + src).getBytes(), AccumuloByteSerializer.serialize(label));
m.put(Constants.LABEL.getBytes(), (dest + "_" + src).getBytes(), AccumuloByteSerializer.serialize(label));
edgeWriter.addMutation(m);
m = new Mutation(dest);
m.put(AccumuloGraph.INEDGE, (src + AccumuloGraph.IDDELIM + id).getBytes(), (AccumuloGraph.IDDELIM + label).getBytes());
m.put(Constants.IN_EDGE.getBytes(),
(src + Constants.ID_DELIM + id).getBytes(),
(Constants.ID_DELIM + label).getBytes());
vertexWriter.addMutation(m);
m = new Mutation(src);
m.put(AccumuloGraph.OUTEDGE, (dest + AccumuloGraph.IDDELIM + id).getBytes(), (AccumuloGraph.IDDELIM + label).getBytes());
m.put(Constants.OUT_EDGE.getBytes(),
(dest + Constants.ID_DELIM + id).getBytes(),
(Constants.ID_DELIM + label).getBytes());
vertexWriter.addMutation(m);
return new PropertyBuilder(edgeWriter, id);
}
@@ -212,7 +217,7 @@ public final class AccumuloBulkIngester {
private void addProperty(BatchWriter writer, String id, String key, Object value) throws MutationsRejectedException {
byte[] newByteVal = AccumuloByteSerializer.serialize(value);
Mutation m = new Mutation(id);
m.put(key.getBytes(), AccumuloGraph.EMPTY, newByteVal);
m.put(key.getBytes(), Constants.EMPTY, newByteVal);
writer.addMutation(m);
}
@@ -296,7 +301,7 @@ public final class AccumuloBulkIngester {
* @return
*/
public PropertyBuilder add(String key, Object value) {
mutation.put(key.getBytes(), AccumuloGraph.EMPTY, AccumuloByteSerializer.serialize(value));
mutation.put(key.getBytes(), Constants.EMPTY, AccumuloByteSerializer.serialize(value));
return this;
}

View File

@@ -108,7 +108,7 @@ public abstract class AccumuloElement implements Element {
@Override
public <T> T removeProperty(String key) {
if (StringFactory.LABEL.equals(key) ||
AccumuloGraph.SLABEL.equals(key)) {
Constants.LABEL.equals(key)) {
throw new AccumuloGraphException("Cannot remove the " + StringFactory.LABEL + " property.");
}

View File

@@ -14,7 +14,6 @@
*/
package edu.jhuapl.tinkerpop;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -27,15 +26,12 @@ import java.util.SortedSet;
import java.util.regex.Pattern;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.BatchDeleter;
import org.apache.accumulo.core.client.BatchScanner;
import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.IteratorSetting;
import org.apache.accumulo.core.client.MultiTableBatchWriter;
import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.admin.TableOperations;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
@@ -130,30 +126,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
protected AccumuloGraphConfiguration config;
public static final byte[] EMPTY = new byte[0];
public static final String IDDELIM = "_";
public static final String SLABEL = "L";
public static final String SINEDGE = "I";
public static final String SOUTEDGE = "O";
public static final String SEXISTS = "E";
public static final byte[] EXISTS = SEXISTS.getBytes();
public static final byte[] LABEL = SLABEL.getBytes();
public static final byte[] INEDGE = SINEDGE.getBytes();
public static final byte[] OUTEDGE = SOUTEDGE.getBytes();
public static final Text TEXISTS = new Text(EXISTS);
public static final Text TINEDGE = new Text(INEDGE);
public static final Text TOUTEDGE = new Text(OUTEDGE);
public static final Text TLABEL = new Text(LABEL);
MultiTableBatchWriter writer;
BatchWriter vertexBW;
BatchWriter edgeBW;
private ElementCaches caches;
VertexTableWrapper vertexWrapper;
EdgeTableWrapper edgeWrapper;
private BatchWriter vertexBW;
public AccumuloGraph(Configuration cfg) {
this(new AccumuloGraphConfiguration(cfg));
@@ -168,30 +141,28 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
config.validate();
this.config = config;
this.caches = new ElementCaches(config);
AccumuloGraphUtils.handleCreateAndClear(config);
try {
globals = new GlobalInstances(this, config,
config.getConnector().createMultiTableBatchWriter(config
.getBatchWriterConfig()), new ElementCaches(config));
} catch (Exception e) {
throw new AccumuloGraphException(e);
}
globals.setVertexWrapper(new VertexTableWrapper(globals));
globals.setEdgeWrapper(new EdgeTableWrapper(globals));
try {
setupWriters();
} catch (Exception e) {
throw new AccumuloGraphException(e);
}
globals = new GlobalInstances(this, config, writer, caches);
vertexWrapper = new VertexTableWrapper(globals);
edgeWrapper = new EdgeTableWrapper(globals);
globals.setVertexWrapper(vertexWrapper);
globals.setEdgeWrapper(edgeWrapper);
}
private void setupWriters() throws Exception {
writer = config.getConnector().createMultiTableBatchWriter(config.getBatchWriterConfig());
vertexBW = writer.getBatchWriter(config.getVertexTableName());
edgeBW = writer.getBatchWriter(config.getEdgeTableName());
vertexBW = globals.getMtbw().getBatchWriter(config.getVertexTableName());
}
/**
@@ -214,43 +185,31 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
protected Scanner getScanner(String tablename) {
try {
return config.getConnector().createScanner(tablename, config.getAuthorizations());
} catch (TableNotFoundException e) {
e.printStackTrace();
} catch (AccumuloException e) {
e.printStackTrace();
} catch (AccumuloSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
return config.getConnector().createScanner(tablename,
config.getAuthorizations());
} catch (Exception e) {
throw new AccumuloGraphException(e);
}
return null;
}
// Aliases for the lazy
protected Scanner getMetadataScanner() {
private Scanner getMetadataScanner() {
return getScanner(config.getMetadataTableName());
}
protected Scanner getVertexIndexScanner() {
public Scanner getVertexIndexScanner() {
return getScanner(config.getVertexKeyIndexTableName());
}
protected Scanner getEdgeIndexScanner() {
private Scanner getEdgeIndexScanner() {
return getScanner(config.getEdgeKeyIndexTableName());
}
protected BatchWriter getVertexIndexWriter() {
private BatchWriter getVertexIndexWriter() {
return getWriter(config.getVertexKeyIndexTableName());
}
protected BatchWriter getMetadataWriter() {
return getWriter(config.getMetadataTableName());
}
protected BatchWriter getEdgeIndexWriter() {
private BatchWriter getEdgeIndexWriter() {
return getWriter(config.getEdgeKeyIndexTableName());
}
@@ -258,21 +217,16 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
return getScanner(config.getKeyMetadataTableName());
}
protected BatchWriter getKeyMetadataWriter() {
private BatchWriter getKeyMetadataWriter() {
return getWriter(config.getKeyMetadataTableName());
}
public BatchWriter getWriter(String tablename) {
try {
return writer.getBatchWriter(tablename);
} catch (AccumuloException e) {
e.printStackTrace();
} catch (AccumuloSecurityException e) {
e.printStackTrace();
} catch (TableNotFoundException e) {
e.printStackTrace();
return globals.getMtbw().getBatchWriter(tablename);
} catch (Exception e) {
throw new AccumuloGraphException(e);
}
return null;
}
private BatchScanner getElementBatchScanner(Class<? extends Element> type) {
@@ -313,10 +267,10 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
vert = new AccumuloVertex(globals, myID);
vertexWrapper.writeVertex(vert);
globals.getVertexWrapper().writeVertex(vert);
checkedFlush();
caches.cache(vert, Vertex.class);
globals.getCaches().cache(vert, Vertex.class);
return vert;
}
@@ -328,7 +282,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
}
String myID = id.toString();
Vertex vertex = caches.retrieve(myID, Vertex.class);
Vertex vertex = globals.getCaches().retrieve(myID, Vertex.class);
if (vertex != null) {
return vertex;
}
@@ -343,21 +297,21 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
preload = new String[]{};
}
Map<String, Object> props = vertexWrapper.readProperties(vertex, preload);
Map<String, Object> props = globals.getVertexWrapper().readProperties(vertex, preload);
if (props == null) {
return null;
}
((AccumuloElement) vertex).cacheAllProperties(props);
}
caches.cache(vertex, Vertex.class);
globals.getCaches().cache(vertex, Vertex.class);
return vertex;
}
@Override
public void removeVertex(Vertex vertex) {
caches.remove(vertex.getId(), Vertex.class);
globals.getCaches().remove(vertex.getId(), Vertex.class);
if (!config.getIndexableGraphDisabled())
clearIndex(vertex.getId());
@@ -388,11 +342,12 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
Entry<Key,Value> e = iter.next();
Key k = e.getKey();
if (k.getColumnFamily().equals(TOUTEDGE) || k.getColumnFamily().equals(TINEDGE)) {
ranges.add(new Range(k.getColumnQualifier().toString().split(IDDELIM)[1]));
if (k.getColumnFamily().toString().equals(Constants.OUT_EDGE) ||
k.getColumnFamily().toString().equals(Constants.IN_EDGE)) {
ranges.add(new Range(k.getColumnQualifier().toString().split(Constants.ID_DELIM)[1]));
Mutation vm = new Mutation(k.getColumnQualifier().toString().split(IDDELIM)[0]);
vm.putDelete(invert(k.getColumnFamily()), new Text(vertex.getId().toString() + IDDELIM + k.getColumnQualifier().toString().split(IDDELIM)[1]));
Mutation vm = new Mutation(k.getColumnQualifier().toString().split(Constants.ID_DELIM)[0]);
vm.putDelete(invert(k.getColumnFamily()), new Text(vertex.getId().toString() + Constants.ID_DELIM + k.getColumnQualifier().toString().split(Constants.ID_DELIM)[1]));
vertexBW.addMutation(vm);
} else {
Mutation m = new Mutation(e.getValue().get());
@@ -455,10 +410,8 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
}
private Text invert(Text columnFamily) {
if (columnFamily.toString().equals(INEDGE)) {
return TOUTEDGE;
}
return TINEDGE;
return columnFamily.toString().equals(Constants.IN_EDGE) ?
new Text(Constants.OUT_EDGE) : new Text(Constants.IN_EDGE);
}
@Override
@@ -483,19 +436,19 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
public Vertex next(PeekingIterator<Entry<Key,Value>> iterator) {
Key key = iterator.next().getKey();
Vertex v = caches.retrieve(key.getColumnQualifier().toString(), Vertex.class);
Vertex v = globals.getCaches().retrieve(key.getColumnQualifier().toString(), Vertex.class);
v = (v == null ? new AccumuloVertex(globals, key.getColumnQualifier().toString()) : v);
((AccumuloElement) v).cacheProperty(key.getColumnFamily().toString(),
AccumuloByteSerializer.deserialize(key.getRow().getBytes()));
caches.cache(v, Vertex.class);
globals.getCaches().cache(v, Vertex.class);
return v;
}
};
} else {
return vertexWrapper.getVertices(key, value);
return globals.getVertexWrapper().getVertices(key, value);
}
}
@@ -515,12 +468,12 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
// TODO we arent suppose to make sure the given edge ID doesn't already
// exist?
edgeWrapper.writeEdge(edge);
vertexWrapper.writeEdgeEndpoints(edge);
globals.getEdgeWrapper().writeEdge(edge);
globals.getVertexWrapper().writeEdgeEndpoints(edge);
checkedFlush();
caches.cache(edge, Edge.class);
globals.getCaches().cache(edge, Edge.class);
return edge;
}
@@ -532,7 +485,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
}
String myID = id.toString();
Edge edge = caches.retrieve(myID, Edge.class);
Edge edge = globals.getCaches().retrieve(myID, Edge.class);
if (edge != null) {
return edge;
}
@@ -548,14 +501,14 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
preload = new String[]{};
}
Map<String, Object> props = edgeWrapper.readProperties(edge, preload);
Map<String, Object> props = globals.getEdgeWrapper().readProperties(edge, preload);
if (props == null) {
return null;
}
((AccumuloElement) edge).cacheAllProperties(props);
}
caches.cache(edge, Edge.class);
globals.getCaches().cache(edge, Edge.class);
return edge;
}
@@ -565,7 +518,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
if (!config.getIndexableGraphDisabled())
clearIndex(edge.getId());
caches.remove(edge.getId(), Edge.class);
globals.getCaches().remove(edge.getId(), Edge.class);
Scanner s = getElementScanner(Edge.class);
s.setRange(new Range(edge.getId().toString()));
@@ -577,8 +530,8 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
while (iter.hasNext()) {
Entry<Key,Value> e = iter.next();
Key k = e.getKey();
if (k.getColumnFamily().equals(TLABEL)) {
String[] ids = k.getColumnQualifier().toString().split(IDDELIM);
if (k.getColumnFamily().toString().equals(Constants.LABEL)) {
String[] ids = k.getColumnQualifier().toString().split(Constants.ID_DELIM);
inVert = new Text(ids[0]);
outVert = new Text(ids[1]);
} else {
@@ -619,7 +572,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
public Iterable<Edge> getEdges(String key, Object value) {
nullCheckProperty(key, value);
if (key.equalsIgnoreCase("label")) {
key = SLABEL;
key = Constants.LABEL;
}
if (config.getAutoIndex() || getIndexedKeys(Edge.class).contains(key)) {
@@ -635,12 +588,12 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
public Edge next(PeekingIterator<Entry<Key,Value>> iterator) {
Entry<Key,Value> kv = iterator.next();
Edge e = caches.retrieve(kv.getKey().getColumnQualifier().toString(), Edge.class);
Edge e = globals.getCaches().retrieve(kv.getKey().getColumnQualifier().toString(), Edge.class);
e = (e == null ? new AccumuloEdge(globals, kv.getKey().getColumnQualifier().toString()) : e);
((AccumuloElement) e).cacheProperty(kv.getKey().getColumnFamily().toString(),
AccumuloByteSerializer.deserialize(kv.getKey().getRow().getBytes()));
caches.cache(e, Edge.class);
globals.getCaches().cache(e, Edge.class);
return e;
}
};
@@ -662,8 +615,8 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
Key k = iterator.next().getKey();
if (k.getColumnFamily().compareTo(AccumuloGraph.TLABEL) == 0) {
String[] vals = k.getColumnQualifier().toString().split(AccumuloGraph.IDDELIM);
if (k.getColumnFamily().toString().equals(Constants.LABEL)) {
String[] vals = k.getColumnQualifier().toString().split(Constants.ID_DELIM);
return new AccumuloEdge(globals, k.getRow().toString(),
new AccumuloVertex(globals, vals[0]),
new AccumuloVertex(globals, vals[1]), null);
@@ -687,14 +640,14 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
@Override
public void shutdown() {
try {
writer.close();
vertexWrapper.close();
edgeWrapper.close();
globals.getMtbw().close();
globals.getVertexWrapper().close();
globals.getEdgeWrapper().close();
} catch (MutationsRejectedException e) {
e.printStackTrace();
}
caches.clear(Vertex.class);
caches.clear(Edge.class);
globals.getCaches().clear(Vertex.class);
globals.getCaches().clear(Edge.class);
}
// public methods not defined by Graph interface, but potentially useful for
@@ -731,7 +684,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
public void flush() {
try {
writer.flush();
globals.getMtbw().flush();
} catch (MutationsRejectedException e) {
throw new AccumuloGraphException(e);
}
@@ -740,6 +693,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
/**
* @deprecated Move this somewhere appropriate
*/
@Deprecated
void checkedFlush() {
if (config.getAutoFlush()) {
flush();
@@ -760,6 +714,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
* @param key
* @param val
*/
@Deprecated
void setPropertyForIndexes(Class<? extends Element> type, Element element, String key, Object val) {
checkProperty(key, val);
try {
@@ -775,7 +730,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
bw.addMutation(m);
}
Mutation m = new Mutation(newByteVal);
m.put(key.getBytes(), element.getId().toString().getBytes(), EMPTY);
m.put(key.getBytes(), element.getId().toString().getBytes(), Constants.EMPTY);
bw.addMutation(m);
checkedFlush();
}
@@ -797,6 +752,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
* @param key
* @return
*/
@Deprecated
void removePropertyFromIndex(Class<? extends Element> type, Element element,
String key, Object obj) {
try {
@@ -849,7 +805,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
if (config.getIndexableGraphDisabled())
throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
Scanner s = this.getMetadataScanner();
Scanner s = getMetadataScanner();
try {
s.setRange(new Range(indexName, indexName));
if (s.iterator().hasNext())
@@ -857,7 +813,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
BatchWriter writer = getWriter(config.getMetadataTableName());
Mutation m = new Mutation(indexName);
m.put(indexClass.getSimpleName().getBytes(), EMPTY, EMPTY);
m.put(indexClass.getSimpleName().getBytes(), Constants.EMPTY, Constants.EMPTY);
try {
writer.addMutation(m);
} catch (MutationsRejectedException e) {
@@ -960,7 +916,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
BatchWriter w = getKeyMetadataWriter();
BatchDeleter bd = null;
Mutation m = new Mutation(key);
m.putDelete(elementClass.getSimpleName().getBytes(), EMPTY);
m.putDelete(elementClass.getSimpleName().getBytes(), Constants.EMPTY);
try {
bd = config.getConnector().createBatchDeleter(table, config.getAuthorizations(), config.getMaxWriteThreads(), config.getBatchWriterConfig());
w.addMutation(m);
@@ -985,7 +941,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
BatchWriter w = getKeyMetadataWriter();
Mutation m = new Mutation(key);
m.put(elementClass.getSimpleName().getBytes(), EMPTY, EMPTY);
m.put(elementClass.getSimpleName().getBytes(), Constants.EMPTY, Constants.EMPTY);
try {
w.addMutation(m);
} catch (MutationsRejectedException e) {
@@ -1005,7 +961,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
Key k = entry.getKey();
Value v = entry.getValue();
Mutation mu = new Mutation(v.get());
mu.put(k.getColumnFamily().getBytes(), k.getRow().getBytes(), EMPTY);
mu.put(k.getColumnFamily().getBytes(), k.getRow().getBytes(), Constants.EMPTY);
try {
bw.addMutation(mu);
} catch (MutationsRejectedException e) {

View File

@@ -0,0 +1,37 @@
/* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.jhuapl.tinkerpop;
/**
* Collect up various constants here.
* @author Michael Lieberman
*
*/
public class Constants {
private Constants() { }
public static final String ID_DELIM = "_";
public static final byte[] EMPTY = new byte[0];
/**
* Prefixes for various Accumulo entries.
*/
public static final String LABEL = "L";
public static final String IN_EDGE = "I";
public static final String OUT_EDGE = "O";
public static final String EXISTS = "E";
}

View File

@@ -24,6 +24,7 @@ import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration;
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration.InstanceType;
import edu.jhuapl.tinkerpop.Constants;
public class EdgeInputFormat extends InputFormatBase<Text,Edge> {
@@ -84,10 +85,10 @@ public class EdgeInputFormat extends InputFormatBase<Text,Edge> {
String eid = currentKey.getRow().toString();
String colf = currentKey.getColumnFamily().toString();
switch (colf) {
case AccumuloGraph.SLABEL:
case Constants.LABEL:
currentK.set(eid);
edge.prepareId(eid);
String[] ids = currentKey.getColumnQualifier().toString().split(parent.IDDELIM);
String[] ids = currentKey.getColumnQualifier().toString().split(Constants.ID_DELIM);
edge.setSourceId(ids[1]);
edge.setDestId(ids[0]);
edge.setLabel(AccumuloByteSerializer.deserialize(entry.getValue().get()).toString());

View File

@@ -24,6 +24,7 @@ import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration;
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration.InstanceType;
import edu.jhuapl.tinkerpop.Constants;
public class VertexInputFormat extends InputFormatBase<Text,Vertex> {
static AccumuloGraphConfiguration conf;
@@ -85,17 +86,17 @@ public class VertexInputFormat extends InputFormatBase<Text,Vertex> {
String vid = currentKey.getRow().toString();
String colf = currentKey.getColumnFamily().toString();
switch (colf) {
case AccumuloGraph.SLABEL:
case Constants.LABEL:
currentK.set(vid);
vertex.prepareId(vid);
break;
case AccumuloGraph.SINEDGE:
String[] parts = currentKey.getColumnQualifier().toString().split(AccumuloGraph.IDDELIM);
case Constants.IN_EDGE:
String[] parts = currentKey.getColumnQualifier().toString().split(Constants.ID_DELIM);
String label = new String(entry.getValue().get());
vertex.prepareEdge(parts[1], parts[0], label, vid);
break;
case AccumuloGraph.SOUTEDGE:
parts = currentKey.getColumnQualifier().toString().split(AccumuloGraph.IDDELIM);
case Constants.OUT_EDGE:
parts = currentKey.getColumnQualifier().toString().split(Constants.ID_DELIM);
label = new String(entry.getValue().get());
vertex.prepareEdge(parts[1], vid, label, parts[0]);
break;

View File

@@ -20,7 +20,7 @@ import com.google.common.collect.Lists;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.Constants;
public class EdgeEndpointsMutator {
@@ -39,14 +39,14 @@ public class EdgeEndpointsMutator {
String outVertexId = edge.getVertex(Direction.OUT).getId().toString();
Mutation in = new Mutation(inVertexId);
in.put(AccumuloGraph.INEDGE,
(outVertexId + AccumuloGraph.IDDELIM + edge.getId()).getBytes(),
(AccumuloGraph.IDDELIM + edge.getLabel()).getBytes());
in.put(Constants.IN_EDGE.getBytes(),
(outVertexId + Constants.ID_DELIM + edge.getId()).getBytes(),
(Constants.ID_DELIM + edge.getLabel()).getBytes());
Mutation out = new Mutation(outVertexId);
out.put(AccumuloGraph.OUTEDGE,
(inVertexId + AccumuloGraph.IDDELIM + edge.getId()).getBytes(),
(AccumuloGraph.IDDELIM + edge.getLabel()).getBytes());
out.put(Constants.OUT_EDGE.getBytes(),
(inVertexId + Constants.ID_DELIM + edge.getId()).getBytes(),
(Constants.ID_DELIM + edge.getLabel()).getBytes());
return Lists.newArrayList(in, out);
}
@@ -64,12 +64,12 @@ public class EdgeEndpointsMutator {
String outVertexId = edge.getVertex(Direction.OUT).getId().toString();
Mutation in = new Mutation(inVertexId);
in.putDelete(AccumuloGraph.INEDGE,
(outVertexId + AccumuloGraph.IDDELIM + edge.getId()).getBytes());
in.putDelete(Constants.IN_EDGE.getBytes(),
(outVertexId + Constants.ID_DELIM + edge.getId()).getBytes());
Mutation out = new Mutation(outVertexId);
out.putDelete(AccumuloGraph.OUTEDGE,
(inVertexId + AccumuloGraph.IDDELIM + edge.getId()).getBytes());
out.putDelete(Constants.OUT_EDGE.getBytes(),
(inVertexId + Constants.ID_DELIM + edge.getId()).getBytes());
return Lists.newArrayList(in, out);
}

View File

@@ -21,7 +21,7 @@ import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.Constants;
public final class EdgeMutator {
@@ -37,8 +37,8 @@ public final class EdgeMutator {
Object outVertexId = edge.getVertex(Direction.OUT).getId();
Mutation m = new Mutation(edge.getId().toString());
m.put(AccumuloGraph.LABEL,
(inVertexId + AccumuloGraph.IDDELIM + outVertexId).getBytes(),
m.put(Constants.LABEL.getBytes(),
(inVertexId + Constants.ID_DELIM + outVertexId).getBytes(),
AccumuloByteSerializer.serialize(edge.getLabel()));
return Lists.newArrayList(m);
@@ -57,8 +57,8 @@ public final class EdgeMutator {
Object outVertexId = edge.getVertex(Direction.OUT).getId();
Mutation m = new Mutation(edge.getId().toString());
m.putDelete(AccumuloGraph.LABEL,
(inVertexId + AccumuloGraph.IDDELIM + outVertexId).getBytes());
m.putDelete(Constants.LABEL.getBytes(),
(inVertexId + Constants.ID_DELIM + outVertexId).getBytes());
return Lists.newArrayList(m);
}

View File

@@ -19,7 +19,7 @@ import org.apache.accumulo.core.data.Mutation;
import com.google.common.collect.Lists;
import com.tinkerpop.blueprints.Element;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.Constants;
public class ClearPropertyMutator extends BasePropertyMutator {
@@ -30,7 +30,7 @@ public class ClearPropertyMutator extends BasePropertyMutator {
@Override
public Iterable<Mutation> create() {
Mutation m = new Mutation(element.getId().toString());
m.putDelete(key.getBytes(), AccumuloGraph.EMPTY);
m.putDelete(key.getBytes(), Constants.EMPTY);
return Lists.newArrayList(m);
}
}

View File

@@ -20,7 +20,7 @@ import com.google.common.collect.Lists;
import com.tinkerpop.blueprints.Element;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.Constants;
public class WritePropertyMutator extends BasePropertyMutator {
@@ -35,7 +35,7 @@ public class WritePropertyMutator extends BasePropertyMutator {
public Iterable<Mutation> create() {
byte[] bytes = AccumuloByteSerializer.serialize(value);
Mutation m = new Mutation(element.getId().toString());
m.put(key.getBytes(), AccumuloGraph.EMPTY, bytes);
m.put(key.getBytes(), Constants.EMPTY, bytes);
return Lists.newArrayList(m);
}
}

View File

@@ -19,7 +19,7 @@ import org.apache.accumulo.core.data.Mutation;
import com.google.common.collect.Lists;
import com.tinkerpop.blueprints.Vertex;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.Constants;
public class AddVertexMutator extends BaseVertexMutator {
@@ -30,7 +30,8 @@ public class AddVertexMutator extends BaseVertexMutator {
@Override
public Iterable<Mutation> create() {
Mutation m = new Mutation((String) vertex.getId());
m.put(AccumuloGraph.LABEL, AccumuloGraph.EXISTS, AccumuloGraph.EMPTY);
m.put(Constants.LABEL.getBytes(),
Constants.EXISTS.getBytes(), Constants.EMPTY);
return Lists.newArrayList(m);
}
}

View File

@@ -21,9 +21,9 @@ import org.apache.accumulo.core.data.Value;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloEdge;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.AccumuloGraphException;
import edu.jhuapl.tinkerpop.AccumuloVertex;
import edu.jhuapl.tinkerpop.Constants;
import edu.jhuapl.tinkerpop.GlobalInstances;
/**
@@ -52,9 +52,9 @@ public class EdgeParser extends ElementParser<AccumuloEdge> {
private AccumuloEdge makeEdge(String id, Iterable<Entry<Key,Value>> entries) {
for (Entry<Key, Value> entry : entries) {
String cf = entry.getKey().getColumnFamily().toString();
if (AccumuloGraph.SLABEL.equals(cf)) {
if (Constants.LABEL.equals(cf)) {
String cq = entry.getKey().getColumnQualifier().toString();
String[] parts = cq.split(AccumuloGraph.IDDELIM);
String[] parts = cq.split(Constants.ID_DELIM);
String inVertexId = parts[0];
String outVertexId = parts[1];
String label = AccumuloByteSerializer.deserialize(entry.getValue().get());

View File

@@ -22,7 +22,7 @@ import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Value;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.Constants;
/**
* TODO
@@ -57,8 +57,8 @@ public class PropertyParser implements EntryParser<Map<String, Object>> {
* @return
*/
private static boolean isExistenceKey(Key key) {
return AccumuloGraph.TLABEL.equals(key.getColumnFamily()) &&
AccumuloGraph.TEXISTS.equals(key.getColumnQualifier());
return Constants.LABEL.equals(key.getColumnFamily().toString()) &&
Constants.EXISTS.equals(key.getColumnQualifier().toString());
}
}

View File

@@ -30,9 +30,9 @@ import com.tinkerpop.blueprints.Edge;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloEdge;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.AccumuloGraphException;
import edu.jhuapl.tinkerpop.AccumuloVertex;
import edu.jhuapl.tinkerpop.Constants;
import edu.jhuapl.tinkerpop.GlobalInstances;
import edu.jhuapl.tinkerpop.ScannerIterable;
import edu.jhuapl.tinkerpop.mutator.Mutators;
@@ -70,7 +70,7 @@ public class EdgeTableWrapper extends ElementTableWrapper {
public Iterable<Edge> getEdges() {
Scanner scan = getScanner();
scan.fetchColumnFamily(AccumuloGraph.TLABEL);
scan.fetchColumnFamily(new Text(Constants.LABEL));
if (globals.getConfig().getPreloadedProperties() != null) {
for (String key : globals.getConfig().getPreloadedProperties()) {
@@ -109,7 +109,7 @@ public class EdgeTableWrapper extends ElementTableWrapper {
try {
s.setRange(new Range(edge.getId().toString()));
s.fetchColumnFamily(AccumuloGraph.TLABEL);
s.fetchColumnFamily(new Text(Constants.LABEL));
Iterator<Entry<Key,Value>> iter = s.iterator();
if (!iter.hasNext()) {
dump();
@@ -119,7 +119,7 @@ public class EdgeTableWrapper extends ElementTableWrapper {
Entry<Key, Value> entry = iter.next();
String cq = entry.getKey().getColumnQualifier().toString();
String[] ids = cq.split(AccumuloGraph.IDDELIM);
String[] ids = cq.split(Constants.ID_DELIM);
String label = AccumuloByteSerializer.deserialize(entry.getValue().get());

View File

@@ -33,7 +33,7 @@ import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.util.StringFactory;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.Constants;
import edu.jhuapl.tinkerpop.GlobalInstances;
import edu.jhuapl.tinkerpop.mutator.property.ClearPropertyMutator;
import edu.jhuapl.tinkerpop.mutator.property.WritePropertyMutator;
@@ -73,12 +73,8 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
s.setRange(new Range(element.getId().toString()));
Text colf = null;
if (StringFactory.LABEL.equals(key)) {
colf = AccumuloGraph.TLABEL;
} else {
colf = new Text(key);
}
Text colf = StringFactory.LABEL.equals(key)
? new Text(Constants.LABEL) : new Text(key);
s.fetchColumnFamily(colf);
V value = null;
@@ -103,7 +99,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
public Map<String, Object> readProperties(Element element, String... propertyKeys) {
Scanner s = getScanner();
s.setRange(new Range(element.getId().toString()));
s.fetchColumnFamily(AccumuloGraph.TLABEL);
s.fetchColumnFamily(new Text(Constants.LABEL));
for (String key : propertyKeys) {
s.fetchColumnFamily(new Text(key));
@@ -135,9 +131,9 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
s.close();
// Remove some special keys.
keys.remove(AccumuloGraph.TINEDGE.toString());
keys.remove(AccumuloGraph.TLABEL.toString());
keys.remove(AccumuloGraph.TOUTEDGE.toString());
keys.remove(Constants.IN_EDGE);
keys.remove(Constants.LABEL);
keys.remove(Constants.OUT_EDGE);
return keys;
}
@@ -175,7 +171,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
for (String lab : labels) {
if (regex.length() != 0)
regex.append("|");
regex.append(".*"+AccumuloGraph.IDDELIM+"\\Q").append(lab).append("\\E$");
regex.append(".*"+Constants.ID_DELIM+"\\Q").append(lab).append("\\E$");
}
IteratorSetting is = new IteratorSetting(10, "edgeValueFilter", RegExFilter.class);

View File

@@ -38,8 +38,8 @@ import com.tinkerpop.blueprints.util.StringFactory;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
import edu.jhuapl.tinkerpop.AccumuloEdge;
import edu.jhuapl.tinkerpop.AccumuloElement;
import edu.jhuapl.tinkerpop.AccumuloGraph;
import edu.jhuapl.tinkerpop.AccumuloVertex;
import edu.jhuapl.tinkerpop.Constants;
import edu.jhuapl.tinkerpop.GlobalInstances;
import edu.jhuapl.tinkerpop.ScannerIterable;
import edu.jhuapl.tinkerpop.mutator.vertex.AddVertexMutator;
@@ -86,12 +86,12 @@ public class VertexTableWrapper extends ElementTableWrapper {
Scanner scan = getScanner();
scan.setRange(new Range(vertex.getId().toString()));
if (direction.equals(Direction.IN)) {
scan.fetchColumnFamily(AccumuloGraph.TINEDGE);
scan.fetchColumnFamily(new Text(Constants.IN_EDGE));
} else if (direction.equals(Direction.OUT)) {
scan.fetchColumnFamily(AccumuloGraph.TOUTEDGE);
scan.fetchColumnFamily(new Text(Constants.OUT_EDGE));
} else {
scan.fetchColumnFamily(AccumuloGraph.TINEDGE);
scan.fetchColumnFamily(AccumuloGraph.TOUTEDGE);
scan.fetchColumnFamily(new Text(Constants.IN_EDGE));
scan.fetchColumnFamily(new Text(Constants.OUT_EDGE));
}
if (labels.length > 0) {
@@ -108,11 +108,11 @@ public class VertexTableWrapper extends ElementTableWrapper {
Entry<Key,Value> kv = iterator.next();
String[] parts = kv.getKey().getColumnQualifier().toString().split(AccumuloGraph.IDDELIM);
String[] parts = kv.getKey().getColumnQualifier().toString().split(Constants.ID_DELIM);
String label = (new String(kv.getValue().get())).split("_")[1];
AccumuloEdge edge;
if (kv.getKey().getColumnFamily().toString().equalsIgnoreCase(AccumuloGraph.SINEDGE)) {
if (kv.getKey().getColumnFamily().toString().equalsIgnoreCase(Constants.IN_EDGE)) {
edge = new AccumuloEdge(globals, parts[1],
new AccumuloVertex(globals, kv.getKey().getRow().toString()),
new AccumuloVertex(globals, parts[0]), label);
@@ -132,12 +132,12 @@ public class VertexTableWrapper extends ElementTableWrapper {
Scanner scan = getScanner();
scan.setRange(new Range(vertex.getId().toString()));
if (direction.equals(Direction.IN)) {
scan.fetchColumnFamily(AccumuloGraph.TINEDGE);
scan.fetchColumnFamily(new Text(Constants.IN_EDGE));
} else if (direction.equals(Direction.OUT)) {
scan.fetchColumnFamily(AccumuloGraph.TOUTEDGE);
scan.fetchColumnFamily(new Text(Constants.OUT_EDGE));
} else {
scan.fetchColumnFamily(AccumuloGraph.TINEDGE);
scan.fetchColumnFamily(AccumuloGraph.TOUTEDGE);
scan.fetchColumnFamily(new Text(Constants.IN_EDGE));
scan.fetchColumnFamily(new Text(Constants.OUT_EDGE));
}
if (labels != null && labels.length > 0) {
@@ -152,7 +152,7 @@ public class VertexTableWrapper extends ElementTableWrapper {
// TODO could also check local cache before creating a new
// instance?
String[] parts = iterator.next().getKey().getColumnQualifier()
.toString().split(AccumuloGraph.IDDELIM);
.toString().split(Constants.ID_DELIM);
AccumuloVertex vertex = new AccumuloVertex(globals, parts[0]);
globals.getCaches().cache(vertex, Vertex.class);
@@ -164,7 +164,7 @@ public class VertexTableWrapper extends ElementTableWrapper {
public Iterable<Vertex> getVertices() {
Scanner scan = getScanner();
scan.fetchColumnFamily(AccumuloGraph.TLABEL);
scan.fetchColumnFamily(new Text(Constants.LABEL));
if (globals.getConfig().getPreloadedProperties() != null) {
for (String key : globals.getConfig().getPreloadedProperties()) {