use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class IndexLabelBuilder method checkFields4Range.
private void checkFields4Range() {
if (this.indexType != IndexType.RANGE) {
return;
}
List<String> fields = this.indexFields;
E.checkArgument(fields.size() == 1, "Range index can only build on " + "one field, but got %s fields: '%s'", fields.size(), fields);
String field = fields.iterator().next();
PropertyKey property = this.graph().propertyKey(field);
E.checkArgument(!property.cardinality().multiple(), "Not allowed to build range index on property " + "'%s' whose cardinality is multiple", field);
DataType dataType = this.graph().propertyKey(field).dataType();
E.checkArgument(dataType.isNumber() || dataType.isDate(), "Range index can only build on numeric or " + "date property, but got %s(%s)", dataType, field);
switch(dataType) {
case BYTE:
case INT:
this.indexType = IndexType.RANGE_INT;
break;
case FLOAT:
this.indexType = IndexType.RANGE_FLOAT;
break;
case LONG:
case DATE:
this.indexType = IndexType.RANGE_LONG;
break;
case DOUBLE:
this.indexType = IndexType.RANGE_DOUBLE;
break;
default:
throw new AssertionError("Invalid datatype: " + dataType);
}
}
use of com.baidu.hugegraph.schema.PropertyKey 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.schema.PropertyKey in project incubator-hugegraph by apache.
the class IndexLabelBuilder method oneNumericField.
private boolean oneNumericField() {
if (this.indexFields.size() != 1) {
return false;
}
String field = this.indexFields.get(0);
PropertyKey propertyKey = this.graph().propertyKey(field);
DataType dataType = propertyKey.dataType();
return dataType.isNumber() || dataType.isDate();
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class HugeEdge method property.
@Override
public <V> Property<V> property(String key, V value) {
PropertyKey propertyKey = this.graph().propertyKey(key);
// Check key in edge label
E.checkArgument(this.label.properties().contains(propertyKey.id()), "Invalid property '%s' for edge label '%s'", key, this.label());
// Sort-Keys can only be set once
if (this.schemaLabel().sortKeys().contains(propertyKey.id())) {
E.checkArgument(!this.hasProperty(propertyKey.id()), "Can't update sort key: '%s'", key);
}
return this.addProperty(propertyKey, value, !this.fresh());
}
use of com.baidu.hugegraph.schema.PropertyKey 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;
}
Aggregations