use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class SchemaRuleSerialization35 method readIndexRule.
// PRIVATE
// READ INDEX
private static IndexDescriptor readIndexRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
String providerKey = getDecodedStringFrom(source);
String providerVersion = getDecodedStringFrom(source);
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
byte indexRuleType = source.get();
Optional<String> name;
switch(indexRuleType) {
case GENERAL_INDEX:
{
SchemaDescriptor schema = readSchema(source);
name = readRuleName(source);
IndexPrototype prototype = IndexPrototype.forSchema(schema, providerDescriptor);
if (schema.isFulltextSchemaDescriptor()) {
prototype = prototype.withIndexType(IndexType.FULLTEXT);
}
if (name.isPresent()) {
prototype = prototype.withName(name.get());
} else {
prototype = prototype.withName(defaultIndexName(id));
}
return prototype.materialise(id);
}
case UNIQUE_INDEX:
{
long readOwningConstraint = source.getLong();
SchemaDescriptor schema = readSchema(source);
name = readRuleName(source);
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema, providerDescriptor);
if (name.isPresent()) {
prototype = prototype.withName(name.get());
} else {
prototype = prototype.withName(defaultIndexName(id));
}
IndexDescriptor index = prototype.materialise(id);
if (readOwningConstraint != NO_OWNING_CONSTRAINT_YET) {
index = index.withOwningConstraintId(readOwningConstraint);
}
return index;
}
default:
throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseRelationshipIndexCursors.
@Test
void shouldReuseRelationshipIndexCursors() throws Exception {
// given
int connection;
int name;
String indexName = "myIndex";
IndexDescriptor index;
try (KernelTransaction tx = beginTransaction()) {
connection = tx.tokenWrite().relationshipTypeGetOrCreateForName("Connection");
name = tx.tokenWrite().propertyKeyGetOrCreateForName("name");
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, array(connection), array(name));
IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withName(indexName).withIndexType(IndexType.FULLTEXT);
index = tx.schemaWrite().indexCreate(prototype);
tx.commit();
}
Predicates.awaitEx(() -> tx.schemaRead().indexGetState(index) == ONLINE, 1, MINUTES);
RelationshipValueIndexCursor c1 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
read.relationshipIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.fulltextSearch("hello"));
c1.close();
RelationshipValueIndexCursor c2 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class SimpleRandomizedIndexAccessorCompatibility method generateUpdatesFromValues.
private List<ValueIndexEntryUpdate<?>> generateUpdatesFromValues(List<Value> values, MutableLong nextId) {
List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
for (Value value : values) {
ValueIndexEntryUpdate<SchemaDescriptor> update = add(nextId.getAndIncrement(), descriptor.schema(), value);
updates.add(update);
}
return updates;
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class CompositeIndexAccessorCompatibility method testExactMatchOnRandomCompositeValues.
@Test
public void testExactMatchOnRandomCompositeValues() throws Exception {
// given
ValueType[] types = randomSetOfSupportedTypes();
List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
Set<ValueTuple> duplicateChecker = new HashSet<>();
for (long id = 0; id < 10_000; id++) {
ValueIndexEntryUpdate<SchemaDescriptor> update;
do {
update = add(id, descriptor.schema(), random.randomValues().nextValueOfTypes(types), random.randomValues().nextValueOfTypes(types));
} while (!duplicateChecker.add(ValueTuple.of(update.values())));
updates.add(update);
}
updateAndCommit(updates);
// when
InMemoryTokens tokenNameLookup = new InMemoryTokens();
for (ValueIndexEntryUpdate<?> update : updates) {
// then
List<Long> hits = query(exact(0, update.values()[0]), exact(1, update.values()[1]));
assertEquals(update.describe(tokenNameLookup) + " " + hits, 1, hits.size());
assertThat(single(hits)).isEqualTo(update.getEntityId());
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class SchemaImpl method asConstraintDefinition.
private ConstraintDefinition asConstraintDefinition(ConstraintDescriptor constraint, TokenRead tokenRead) {
// internal storage engine API.
if (constraint.isNodePropertyExistenceConstraint() || constraint.isNodeKeyConstraint() || constraint.isUniquenessConstraint()) {
SchemaDescriptor schemaDescriptor = constraint.schema();
int[] entityTokenIds = schemaDescriptor.getEntityTokenIds();
Label[] labels = new Label[entityTokenIds.length];
for (int i = 0; i < entityTokenIds.length; i++) {
labels[i] = label(tokenRead.labelGetName(entityTokenIds[i]));
}
String[] propertyKeys = Arrays.stream(schemaDescriptor.getPropertyIds()).mapToObj(tokenRead::propertyKeyGetName).toArray(String[]::new);
if (constraint.isNodePropertyExistenceConstraint()) {
return new NodePropertyExistenceConstraintDefinition(actions, constraint, labels[0], propertyKeys);
} else if (constraint.isUniquenessConstraint()) {
return new UniquenessConstraintDefinition(actions, constraint, new IndexDefinitionImpl(actions, null, labels, propertyKeys, true));
} else {
return new NodeKeyConstraintDefinition(actions, constraint, new IndexDefinitionImpl(actions, null, labels, propertyKeys, true));
}
} else if (constraint.isRelationshipPropertyExistenceConstraint()) {
RelationTypeSchemaDescriptor descriptor = constraint.schema().asRelationshipTypeSchemaDescriptor();
return new RelationshipPropertyExistenceConstraintDefinition(actions, constraint, withName(tokenRead.relationshipTypeGetName(descriptor.getRelTypeId())), tokenRead.propertyKeyGetName(descriptor.getPropertyId()));
}
throw new IllegalArgumentException("Unknown constraint " + constraint);
}
Aggregations