use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class TestGraph method initGratefulSchema.
@Watched
public void initGratefulSchema(IdStrategy idStrategy) {
SchemaManager schema = this.graph.schema();
schema.propertyKey("id").asInt().ifNotExist().create();
schema.propertyKey("weight").asInt().ifNotExist().create();
schema.propertyKey("name").ifNotExist().create();
schema.propertyKey("songType").asText().ifNotExist().create();
schema.propertyKey("performances").asInt().ifNotExist().create();
switch(idStrategy) {
case AUTOMATIC:
schema.vertexLabel("song").properties("id", "name", "songType", "performances").nullableKeys("id", "name", "songType", "performances").ifNotExist().create();
schema.vertexLabel("artist").properties("id", "name").nullableKeys("id", "name").ifNotExist().create();
break;
case CUSTOMIZE_STRING:
schema.vertexLabel("song").properties("id", "name", "songType", "performances").nullableKeys("id", "name", "songType", "performances").useCustomizeStringId().ifNotExist().create();
schema.vertexLabel("artist").properties("id", "name").nullableKeys("id", "name").useCustomizeStringId().ifNotExist().create();
break;
default:
throw new AssertionError(String.format("Id strategy must be customize or automatic"));
}
schema.edgeLabel("followedBy").link("song", "song").properties("weight").nullableKeys("weight").ifNotExist().create();
schema.edgeLabel("sungBy").link("song", "artist").ifNotExist().create();
schema.edgeLabel("writtenBy").link("song", "artist").ifNotExist().create();
schema.indexLabel("songByName").onV("song").by("name").ifNotExist().create();
schema.indexLabel("songBySongType").onV("song").by("songType").ifNotExist().create();
schema.indexLabel("songByPerf").onV("song").by("performances").ifNotExist().create();
schema.indexLabel("artistByName").onV("artist").by("name").ifNotExist().create();
schema.indexLabel("followedByByWeight").onE("followedBy").by("weight").range().ifNotExist().create();
}
use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class ConditionQuery method condition.
@Watched
public <T> T condition(Object key) {
List<Object> valuesEQ = InsertionOrderUtil.newList();
List<Object> valuesIN = InsertionOrderUtil.newList();
for (Condition c : this.conditions) {
if (c.isRelation()) {
Condition.Relation r = (Condition.Relation) c;
if (r.key().equals(key)) {
if (r.relation() == RelationType.EQ) {
valuesEQ.add(r.value());
} else if (r.relation() == RelationType.IN) {
Object value = r.value();
assert value instanceof List;
valuesIN.add(value);
}
}
}
}
if (valuesEQ.isEmpty() && valuesIN.isEmpty()) {
return null;
}
if (valuesEQ.size() == 1 && valuesIN.size() == 0) {
@SuppressWarnings("unchecked") T value = (T) valuesEQ.get(0);
return value;
}
if (valuesEQ.size() == 0 && valuesIN.size() == 1) {
@SuppressWarnings("unchecked") T value = (T) valuesIN.get(0);
return value;
}
Set<Object> intersectValues = InsertionOrderUtil.newSet();
for (Object value : valuesEQ) {
List<Object> valueAsList = ImmutableList.of(value);
if (intersectValues.isEmpty()) {
intersectValues.addAll(valueAsList);
} else {
CollectionUtil.intersectWithModify(intersectValues, valueAsList);
}
}
for (Object value : valuesIN) {
@SuppressWarnings("unchecked") List<Object> valueAsList = (List<Object>) value;
if (intersectValues.isEmpty()) {
intersectValues.addAll(valueAsList);
} else {
CollectionUtil.intersectWithModify(intersectValues, valueAsList);
}
}
if (intersectValues.size() == 0) {
return null;
}
E.checkState(intersectValues.size() == 1, "Illegal key '%s' with more than one value: %s", key, intersectValues);
@SuppressWarnings("unchecked") T value = (T) intersectValues.iterator().next();
return value;
}
use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class BackendMutation method optimizeUpdates.
/**
* The optimized scenes include but are not limited to:
* 1.If you want to delete an entry, the other mutations previously
* can be ignored.
* 2.As similar to the No.1 item, If you want to insert an entry,
* the other mutations previously also can be ignored.
* 3.If you append an entry and then eliminate it, the new action
* can override the old one.
*/
@Watched(prefix = "mutation")
private void optimizeUpdates(BackendEntry entry, Action action) {
final Id id = entry.id();
assert id != null;
final List<BackendAction> items = this.updates.get(entry.type(), id);
assert items != null;
boolean ignoreCurrent = false;
for (Iterator<BackendAction> iter = items.iterator(); iter.hasNext(); ) {
BackendAction originItem = iter.next();
Action originAction = originItem.action();
switch(action) {
case INSERT:
iter.remove();
break;
case DELETE:
if (originAction == Action.INSERT) {
throw incompatibleActionException(action, originAction);
} else if (originAction == Action.DELETE) {
ignoreCurrent = true;
} else {
iter.remove();
}
break;
case APPEND:
if (entry.type().isUniqueIndex() && originAction == Action.APPEND) {
throw new IllegalArgumentException(String.format("Unique constraint conflict is found in" + " transaction between %s and %s", entry, originItem.entry()));
}
if (originAction == Action.INSERT || originAction == Action.DELETE) {
throw incompatibleActionException(action, originAction);
} else {
Id subId = entry.subId();
Id originSubId = originItem.entry().subId();
assert subId != null;
if (subId == originSubId || subId.equals(originSubId)) {
iter.remove();
}
}
break;
case ELIMINATE:
if (originAction == Action.INSERT || originAction == Action.DELETE) {
throw incompatibleActionException(action, originAction);
} else {
Id subId = entry.subId();
Id originSubId = originItem.entry().subId();
assert subId != null;
if (subId == originSubId || subId.equals(originSubId)) {
iter.remove();
}
}
break;
default:
throw new AssertionError(String.format("Unknown mutate action: %s", action));
}
}
if (!ignoreCurrent) {
items.add(BackendAction.of(action, entry));
}
}
use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class HugeTraverser method edgesOfVertex.
@Watched
protected Iterator<Edge> edgesOfVertex(Id source, Directions dir, Map<Id, String> labels, long limit) {
if (labels == null || labels.isEmpty()) {
return this.edgesOfVertex(source, dir, (Id) null, limit);
}
ExtendableIterator<Edge> results = new ExtendableIterator<>();
for (Id label : labels.keySet()) {
E.checkNotNull(label, "edge label");
results.extend(this.edgesOfVertex(source, dir, label, limit));
}
if (limit == NO_LIMIT) {
return results;
}
long[] count = new long[1];
return new LimitIterator<>(results, e -> {
return count[0]++ >= limit;
});
}
use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class DoubleWayMultiPathsRecords method linkPath.
@Watched
protected final PathSet linkPath(int source, int target, boolean ring) {
PathSet paths = new PathSet();
PathSet sources = this.linkSourcePath(source);
PathSet targets = this.linkTargetPath(target);
for (Path tpath : targets) {
tpath.reverse();
for (Path spath : sources) {
if (!ring) {
// Avoid loop in path
if (CollectionUtils.containsAny(spath.vertices(), tpath.vertices())) {
continue;
}
}
List<Id> ids = new ArrayList<>(spath.vertices());
ids.addAll(tpath.vertices());
Id crosspoint = this.id(this.movingForward ? target : source);
paths.add(new Path(crosspoint, ids));
}
}
return paths;
}
Aggregations