use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class IndexLabelBuilder method checkFields.
private void checkFields(Set<Id> propertyIds) {
List<String> fields = this.indexFields;
E.checkNotEmpty(fields, "index fields", this.name);
Set<Id> olapPks = new IdSet(CollectionType.EC);
for (String field : fields) {
PropertyKey pkey = this.propertyKeyOrNull(field);
// In general this will not happen
E.checkArgument(pkey != null, "Can't build index on undefined property key " + "'%s' for '%s': '%s'", field, this.baseType.readableName(), this.baseValue);
E.checkArgument(pkey.aggregateType().isIndexable(), "The aggregate type %s is not indexable", pkey.aggregateType());
if (pkey.cardinality().multiple()) {
E.checkArgument(fields.size() == 1, "Not allowed to build union index on property" + " key '%s' whose cardinality is multiple", pkey.name());
}
if (pkey.olap()) {
olapPks.add(pkey.id());
}
}
if (!olapPks.isEmpty()) {
E.checkArgument(olapPks.size() == 1, "Can't build index on multiple olap properties, " + "but got fields '%s' for index label '%s'", fields, this.name);
E.checkArgument(olapPks.size() == fields.size(), "Can't build index on olap properties and oltp " + "properties in one index label, " + "but got fields '%s' for index label '%s'", fields, this.name);
E.checkArgument(this.indexType == IndexType.SECONDARY || this.indexType == IndexType.RANGE, "Only secondary and range index can be built on " + "olap property, but got index type '%s' on olap " + "property key '%s' for index label '%s'", this.indexType, fields.get(0), this.name);
}
List<String> properties = this.graph().mapPkId2Name(propertyIds);
E.checkArgument(properties.containsAll(fields), "Not all index fields '%s' are contained in " + "schema properties '%s'", fields, properties);
// Range index must build on single numeric column
if (this.indexType == IndexType.RANGE) {
this.checkFields4Range();
}
// Search index must build on single text column
if (this.indexType.isSearch()) {
E.checkArgument(fields.size() == 1, "Search index can only build on " + "one field, but got %s fields: '%s'", fields.size(), fields);
String field = fields.iterator().next();
DataType dataType = this.graph().propertyKey(field).dataType();
E.checkArgument(dataType.isText(), "Search index can only build on text property, " + "but got %s(%s)", dataType, field);
}
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class HugeEdge method properties.
@Watched(prefix = "edge")
// (Property<V>) prop
@SuppressWarnings("unchecked")
@Override
public <V> Iterator<Property<V>> properties(String... keys) {
this.ensureFilledProperties(true);
// Capacity should be about the following size
int propsCapacity = keys.length == 0 ? this.sizeOfProperties() : keys.length;
List<Property<V>> props = new ArrayList<>(propsCapacity);
if (keys.length == 0) {
for (HugeProperty<?> prop : this.getProperties()) {
assert prop instanceof Property;
props.add((Property<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 Property;
props.add((Property<V>) prop);
}
}
return props.iterator();
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class HugeEdge method sortValues.
@Watched(prefix = "edge")
protected List<Object> sortValues() {
List<Id> sortKeys = this.schemaLabel().sortKeys();
if (sortKeys.isEmpty()) {
return ImmutableList.of();
}
List<Object> propValues = new ArrayList<>(sortKeys.size());
for (Id sk : sortKeys) {
HugeProperty<?> property = this.getProperty(sk);
E.checkState(property != null, "The value of sort key '%s' can't be null", sk);
Object propValue = property.serialValue(true);
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 PropertyKeyBuilder method build.
@Override
public PropertyKey build() {
Id id = this.validOrGenerateId(HugeType.PROPERTY_KEY, this.id, this.name);
PropertyKey propertyKey = new PropertyKey(this.graph(), id, this.name);
propertyKey.dataType(this.dataType);
propertyKey.cardinality(this.cardinality);
propertyKey.aggregateType(this.aggregateType);
propertyKey.writeType(this.writeType);
propertyKey.userdata(this.userdata);
return propertyKey;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class PropertyKeyBuilder method create.
@Override
public PropertyKey create() {
// Create index label async
SchemaElement.TaskWithSchema propertyKeyWithTask = this.createWithTask();
Id task = propertyKeyWithTask.task();
if (task == IdGenerator.ZERO) {
/*
* Task id will be IdGenerator.ZERO if creating property key
* already exists or creating property key is oltp
*/
return propertyKeyWithTask.propertyKey();
}
// Wait task completed (change to sync mode)
HugeGraph graph = this.graph();
long timeout = graph.option(CoreOptions.TASK_WAIT_TIMEOUT);
try {
graph.taskScheduler().waitUntilTaskCompleted(task, timeout);
} catch (TimeoutException e) {
throw new HugeException("Failed to wait property key create task completed", e);
}
// Return property key without task-info
return propertyKeyWithTask.propertyKey();
}
Aggregations