use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class FusiformSimilarityTraverser method matchMinNeighborCount.
private boolean matchMinNeighborCount(HugeVertex vertex, Directions direction, String label, int minNeighbors, long degree) {
Iterator<Edge> edges;
long neighborCount;
EdgeLabel edgeLabel = null;
Id labelId = null;
if (label != null) {
edgeLabel = this.graph().edgeLabel(label);
labelId = edgeLabel.id();
}
if (edgeLabel != null && edgeLabel.frequency() == Frequency.SINGLE) {
edges = this.edgesOfVertex(vertex.id(), direction, labelId, minNeighbors);
neighborCount = IteratorUtils.count(edges);
} else {
edges = this.edgesOfVertex(vertex.id(), direction, labelId, degree);
Set<Id> neighbors = newIdSet();
while (edges.hasNext()) {
Id target = ((HugeEdge) edges.next()).id().otherVertexId();
neighbors.add(target);
if (neighbors.size() >= minNeighbors) {
break;
}
}
neighborCount = neighbors.size();
}
return neighborCount >= minNeighbors;
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class HugeEdgeProperty method remove.
@Override
public void remove() {
assert this.owner instanceof HugeEdge;
EdgeLabel edgeLabel = ((HugeEdge) this.owner).schemaLabel();
E.checkArgument(edgeLabel.nullableKeys().contains(this.propertyKey().id()), "Can't remove non-null edge property '%s'", this);
this.owner.graph().removeEdgeProperty(this);
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class IndexLabelRebuildJob method rebuildIndex.
private void rebuildIndex(SchemaLabel label, Collection<Id> indexLabelIds) {
SchemaTransaction schemaTx = this.params().schemaTransaction();
GraphTransaction graphTx = this.params().graphTransaction();
Consumer<?> indexUpdater = (elem) -> {
for (Id id : indexLabelIds) {
graphTx.updateIndex(id, (HugeElement) elem, false);
}
};
LockUtil.Locks locks = new LockUtil.Locks(schemaTx.graphName());
try {
locks.lockWrites(LockUtil.INDEX_LABEL_REBUILD, indexLabelIds);
Set<IndexLabel> ils = indexLabelIds.stream().map(this.graph()::indexLabel).collect(Collectors.toSet());
for (IndexLabel il : ils) {
if (il.status() == SchemaStatus.CREATING) {
continue;
}
schemaTx.updateSchemaStatus(il, SchemaStatus.REBUILDING);
}
this.removeIndex(indexLabelIds);
/*
* Note: Here must commit index transaction firstly.
* Because remove index convert to (id like <?>:personByCity):
* `delete from index table where label = ?`,
* But append index will convert to (id like Beijing:personByCity):
* `update index element_ids += xxx where field_value = ?
* and index_label_name = ?`,
* They have different id lead to it can't compare and optimize
*/
graphTx.commit();
try {
if (label.type() == HugeType.VERTEX_LABEL) {
@SuppressWarnings("unchecked") Consumer<Vertex> consumer = (Consumer<Vertex>) indexUpdater;
graphTx.traverseVerticesByLabel((VertexLabel) label, consumer, false);
} else {
assert label.type() == HugeType.EDGE_LABEL;
@SuppressWarnings("unchecked") Consumer<Edge> consumer = (Consumer<Edge>) indexUpdater;
graphTx.traverseEdgesByLabel((EdgeLabel) label, consumer, false);
}
graphTx.commit();
} catch (Throwable e) {
for (IndexLabel il : ils) {
schemaTx.updateSchemaStatus(il, SchemaStatus.INVALID);
}
throw e;
}
for (IndexLabel il : ils) {
schemaTx.updateSchemaStatus(il, SchemaStatus.CREATED);
}
} finally {
locks.unlock();
}
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class Example1 method testRemove.
public static void testRemove(final HugeGraph graph) {
// remove vertex (and its edges)
List<Vertex> vertices = graph.traversal().V().hasLabel("person").has("age", 19).toList();
assert vertices.size() == 1;
Vertex james = vertices.get(0);
Vertex book6 = graph.addVertex(T.label, "book", "name", "java-6");
james.addEdge("look", book6, "timestamp", "2017-5-2 12:00:08.0");
james.addEdge("look", book6, "timestamp", "2017-5-3 12:00:08.0");
graph.tx().commit();
assert graph.traversal().V(book6.id()).bothE().hasNext();
LOG.info(">>>> removing vertex: {}", james);
james.remove();
graph.tx().commit();
assert !graph.traversal().V(james.id()).hasNext();
assert !graph.traversal().V(book6.id()).bothE().hasNext();
// remove edge
VertexLabel author = graph.schema().getVertexLabel("author");
String authorId = String.format("%s:%s", author.id().asString(), "11");
EdgeLabel authored = graph.edgeLabel("authored");
VertexLabel book = graph.schema().getVertexLabel("book");
String book2Id = String.format("%s:%s", book.id().asString(), "java-2");
String edgeId = String.format("S%s>%s>%s>S%s", authorId, authored.id(), "", book2Id);
List<Edge> edges = graph.traversal().E(edgeId).toList();
assert edges.size() == 1;
Edge edge = edges.get(0);
LOG.info(">>>> removing edge: {}", edge);
edge.remove();
graph.tx().commit();
assert !graph.traversal().E(edgeId).hasNext();
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class SchemaCoreTest method assertELEqual.
protected void assertELEqual(String label, Id id) {
EdgeLabel edgeLabel = graph().edgeLabel(label);
Assert.assertEquals(id, edgeLabel.id());
}
Aggregations