use of com.baidu.hugegraph.util.collection.IdSet 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.util.collection.IdSet in project incubator-hugegraph by apache.
the class IdSetTest method testIdSetRemove.
@Test
public void testIdSetRemove() {
Random random = new Random();
Set<Long> numbers = new HashSet<>();
Set<UUID> uuids = new HashSet<>();
Set<String> strings = new HashSet<>();
for (CollectionType type : CollectionType.values()) {
idSet = new IdSet(type);
for (int i = 1; i < SIZE; i++) {
long number = random.nextLong();
numbers.add(number);
idSet.add(IdGenerator.of(number));
}
for (int i = 0; i < SIZE; i++) {
UUID uuid = UUID.randomUUID();
uuids.add(uuid);
idSet.add(IdGenerator.of(uuid));
}
for (int i = 0; i < SIZE; i++) {
String string = RandomStringUtils.randomAlphanumeric(10);
strings.add(string);
idSet.add(IdGenerator.of(string));
}
Assert.assertEquals(numbers.size() + uuids.size() + strings.size(), idSet.size());
LongHashSet numberIds = Whitebox.getInternalState(idSet, "numberIds");
Assert.assertEquals(numbers.size(), numberIds.size());
Set<Id> nonNumberIds = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertEquals(uuids.size() + strings.size(), nonNumberIds.size());
for (long number : numbers) {
idSet.remove(IdGenerator.of(number));
}
Assert.assertEquals(nonNumberIds.size(), idSet.size());
for (UUID uuid : uuids) {
idSet.remove(IdGenerator.of(uuid));
}
for (String string : strings) {
idSet.remove(IdGenerator.of(string));
}
Assert.assertTrue(idSet.isEmpty());
numbers.clear();
uuids.clear();
strings.clear();
idSet.clear();
}
}
use of com.baidu.hugegraph.util.collection.IdSet in project incubator-hugegraph by apache.
the class AbstractTransaction method injectOlapPkIfNeeded.
private void injectOlapPkIfNeeded(Query query) {
if (!query.resultType().isVertex() || !this.graph.readMode().showOlap()) {
return;
}
/*
* Control olap access by auth, only accessible olap property key
* will be queried
*/
Set<Id> olapPks = new IdSet(CollectionType.EC);
for (PropertyKey propertyKey : this.graph.graph().propertyKeys()) {
if (propertyKey.olap()) {
olapPks.add(propertyKey.id());
}
}
query.olapPks(olapPks);
}
use of com.baidu.hugegraph.util.collection.IdSet in project incubator-hugegraph by apache.
the class CollectionFactoryTest method testIdSet.
@Test
public void testIdSet() {
factory = new CollectionFactory(CollectionType.EC);
IdSet idSet = factory.newIdSet();
Set<Id> ids = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertInstanceOf(UnifiedSet.class, ids);
Assert.assertInstanceOf(LongHashSet.class, Whitebox.getInternalState(idSet, "numberIds"));
factory = new CollectionFactory(CollectionType.FU);
idSet = factory.newIdSet();
ids = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertInstanceOf(ObjectOpenHashSet.class, ids);
Assert.assertInstanceOf(LongHashSet.class, Whitebox.getInternalState(idSet, "numberIds"));
factory = new CollectionFactory(CollectionType.JCF);
idSet = factory.newIdSet();
ids = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertInstanceOf(HashSet.class, ids);
Assert.assertInstanceOf(LongHashSet.class, Whitebox.getInternalState(idSet, "numberIds"));
idSet = CollectionFactory.newIdSet(CollectionType.EC);
ids = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertInstanceOf(UnifiedSet.class, ids);
Assert.assertInstanceOf(LongHashSet.class, Whitebox.getInternalState(idSet, "numberIds"));
idSet = CollectionFactory.newIdSet(CollectionType.FU);
ids = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertInstanceOf(ObjectOpenHashSet.class, ids);
Assert.assertInstanceOf(LongHashSet.class, Whitebox.getInternalState(idSet, "numberIds"));
idSet = CollectionFactory.newIdSet(CollectionType.JCF);
ids = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertInstanceOf(HashSet.class, ids);
Assert.assertInstanceOf(LongHashSet.class, Whitebox.getInternalState(idSet, "numberIds"));
}
use of com.baidu.hugegraph.util.collection.IdSet in project incubator-hugegraph by apache.
the class IdSetTest method testIdSetWithOnlyNumberId.
@Test
public void testIdSetWithOnlyNumberId() {
Random random = new Random();
Set<Long> numbers = new HashSet<>();
for (CollectionType type : CollectionType.values()) {
idSet = new IdSet(type);
for (int i = 1; i < SIZE; i++) {
long number = random.nextLong();
numbers.add(number);
idSet.add(IdGenerator.of(number));
}
Assert.assertEquals(numbers.size(), idSet.size());
LongHashSet numberIds = Whitebox.getInternalState(idSet, "numberIds");
Assert.assertEquals(numbers.size(), numberIds.size());
Set<Id> nonNumberIds = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertTrue(nonNumberIds.isEmpty());
numbers.clear();
idSet.clear();
}
}
Aggregations