use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class HugeVertex method properties.
@Watched(prefix = "vertex")
// (VertexProperty<V>) prop
@SuppressWarnings("unchecked")
@Override
public <V> Iterator<VertexProperty<V>> properties(String... keys) {
// TODO: Compatible with TinkerPop properties() (HugeGraph-742)
this.ensureFilledProperties(true);
// Capacity should be about the following size
int propsCapacity = keys.length == 0 ? this.sizeOfProperties() : keys.length;
List<VertexProperty<V>> props = new ArrayList<>(propsCapacity);
if (keys.length == 0) {
for (HugeProperty<?> prop : this.getProperties()) {
assert prop instanceof VertexProperty;
props.add((VertexProperty<V>) prop);
}
} else {
for (String key : keys) {
Id pkeyId;
try {
pkeyId = this.graph().propertyKey(key).id();
} catch (IllegalArgumentException ignored) {
continue;
}
HugeProperty<?> prop = this.getProperty(pkeyId);
if (prop == null) {
// Not found
continue;
}
assert prop instanceof VertexProperty;
props.add((VertexProperty<V>) prop);
}
}
return props.iterator();
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class HugeVertex method primaryValues.
@Watched(prefix = "vertex")
protected List<Object> primaryValues() {
E.checkArgument(this.label.idStrategy() == IdStrategy.PRIMARY_KEY, "The id strategy '%s' don't have primary keys", this.label.idStrategy());
List<Id> primaryKeys = this.label.primaryKeys();
E.checkArgument(!primaryKeys.isEmpty(), "Primary key can't be empty for id strategy '%s'", IdStrategy.PRIMARY_KEY);
boolean encodeNumber = this.graph().option(CoreOptions.VERTEX_ENCODE_PK_NUMBER);
List<Object> propValues = new ArrayList<>(primaryKeys.size());
for (Id pk : primaryKeys) {
HugeProperty<?> property = this.getProperty(pk);
E.checkState(property != null, "The value of primary key '%s' can't be null", this.graph().propertyKey(pk).name());
Object propValue = property.serialValue(encodeNumber);
if (Strings.EMPTY.equals(propValue)) {
propValue = ConditionQuery.INDEX_VALUE_EMPTY;
}
propValues.add(propValue);
}
return propValues;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class HugeVertex method constructEdge.
public HugeEdge constructEdge(String label, HugeVertex vertex, Object... keyValues) {
ElementKeys elemKeys = HugeElement.classifyKeys(keyValues);
// Check id (must be null)
if (elemKeys.id() != null) {
throw Edge.Exceptions.userSuppliedIdsNotSupported();
}
Id id = null;
// Check target vertex
E.checkArgumentNotNull(vertex, "Target vertex can't be null");
// Check label
E.checkArgument(label != null && !label.isEmpty(), "Edge label can't be null or empty");
EdgeLabel edgeLabel = this.graph().edgeLabel(label);
// Check link
E.checkArgument(edgeLabel.checkLinkEqual(this.schemaLabel().id(), vertex.schemaLabel().id()), "Undefined link of edge label '%s': '%s' -> '%s'", label, this.label(), vertex.label());
// Check sortKeys
List<Id> keys = this.graph().mapPkName2Id(elemKeys.keys());
E.checkArgument(keys.containsAll(edgeLabel.sortKeys()), "The sort key(s) must be set for the edge " + "with label: '%s'", edgeLabel.name());
// Check whether passed all non-null props
@SuppressWarnings("unchecked") Collection<Id> nonNullKeys = CollectionUtils.subtract(edgeLabel.properties(), edgeLabel.nullableKeys());
if (!keys.containsAll(nonNullKeys)) {
@SuppressWarnings("unchecked") Collection<Id> missed = CollectionUtils.subtract(nonNullKeys, keys);
E.checkArgument(false, "All non-null property keys: %s " + "of edge label '%s' must be set, " + "but missed keys: %s", this.graph().mapPkId2Name(nonNullKeys), edgeLabel.name(), this.graph().mapPkId2Name(missed));
}
HugeEdge edge = new HugeEdge(this, id, edgeLabel, vertex);
// Set properties
ElementHelper.attachProperties(edge, keyValues);
edge.assignId();
return edge;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class IndexLabelRebuildJob method schemaElement.
private SchemaElement schemaElement() {
HugeType type = this.schemaType();
Id id = this.schemaId();
switch(type) {
case VERTEX_LABEL:
return this.graph().vertexLabel(id);
case EDGE_LABEL:
return this.graph().edgeLabel(id);
case INDEX_LABEL:
return this.graph().indexLabel(id);
default:
throw new AssertionError(String.format("Invalid HugeType '%s' for rebuild", type));
}
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class OlapPropertyKeyClearJob method execute.
@Override
public Object execute() {
Id olap = this.schemaId();
// Clear olap data table
this.params().graphTransaction().clearOlapPk(olap);
// Clear corresponding index data
clearIndexLabel(this.params(), olap);
return null;
}
Aggregations