use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class SchemaStorageIT method shouldWriteAndReadIndexConfig.
@Test
void shouldWriteAndReadIndexConfig() throws KernelException {
// given
IndexConfig expected = IndexConfig.with(MapUtil.genericMap("value.string", Values.stringValue("value"), "value.int", Values.intValue(1), "value.doubleArray", Values.doubleArray(new double[] { 0.4, 0.6, 1.0 }), "value.boolean", Values.booleanValue(true)));
var cursorContext = NULL;
SchemaDescriptor schema = forLabel(labelId(LABEL1), propId(PROP1));
long id = schemaStore.nextId(cursorContext);
IndexDescriptor storeIndexDescriptor = forSchema(schema).withName("index_" + id).materialise(id).withIndexConfig(expected);
storage.writeSchemaRule(storeIndexDescriptor, cursorContext, INSTANCE);
// when
IndexDescriptor schemaRule = (IndexDescriptor) storage.loadSingleSchemaRule(id, NULL);
// Clean up after ourselves.
storage.deleteSchemaRule(schemaRule, NULL);
// then
IndexConfig actual = schemaRule.getIndexConfig();
assertEquals(expected, actual, "Read index config not same as written, expected " + expected + ", actual " + actual);
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class SchemaStorageIT method shouldReturnIndexRuleForLabelAndVeryManyPropertiesComposite.
@Test
void shouldReturnIndexRuleForLabelAndVeryManyPropertiesComposite() {
String[] props = "abcdefghijklmnopqrstuvwxyzABCDEFGHJILKMNOPQRSTUVWXYZ".split("\\B");
createSchema(tx -> {
IndexCreator indexCreator = tx.schema().indexFor(Label.label(LABEL1));
for (String prop : props) {
indexCreator = indexCreator.on(prop);
}
indexCreator.create();
});
IndexDescriptor rule = single(storage.indexGetForSchema(TestIndexDescriptorFactory.forLabel(labelId(LABEL1), Arrays.stream(props).mapToInt(this::propId).toArray()), NULL));
assertNotNull(rule);
assertTrue(SchemaDescriptorPredicates.hasLabel(rule, labelId(LABEL1)));
for (String prop : props) {
assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(prop)));
}
assertFalse(rule.isUnique());
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class SchemaStorageIT method shouldListIndexRulesForLabelPropertyAndKind.
@Test
void shouldListIndexRulesForLabelPropertyAndKind() {
// Given
createSchema(uniquenessConstraint(LABEL1, PROP1), index(LABEL1, PROP2));
// When
IndexDescriptor rule = single(storage.indexGetForSchema(uniqueIndexDescriptor(LABEL1, PROP1), NULL));
// Then
assertNotNull(rule);
assertRule(rule, LABEL1, PROP1, true);
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class Operations method indexDrop.
@Override
public void indexDrop(SchemaDescriptor schema) throws SchemaKernelException {
exclusiveSchemaLock(schema);
Iterator<IndexDescriptor> iterator = Iterators.filter(index -> index.getIndexType() != IndexType.FULLTEXT, allStoreHolder.index(schema));
if (!iterator.hasNext()) {
String description = schema.userDescription(token);
throw new DropIndexFailureException("Unable to drop index on " + description + ". There is no such index.");
}
do {
IndexDescriptor existingIndex = iterator.next();
indexDrop(existingIndex);
} while (iterator.hasNext());
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class Operations method assertNoBlockingSchemaRulesExists.
private void assertNoBlockingSchemaRulesExists(ConstraintDescriptor constraint) throws EquivalentSchemaRuleAlreadyExistsException, IndexWithNameAlreadyExistsException, ConstraintWithNameAlreadyExistsException, AlreadyConstrainedException, AlreadyIndexedException {
final String name = constraint.getName();
if (name == null) {
throw new IllegalStateException("Expected constraint to always have a name by this point");
}
// Equivalent constraint
final List<ConstraintDescriptor> constraintsWithSameSchema = Iterators.asList(allStoreHolder.constraintsGetForSchema(constraint.schema()));
for (ConstraintDescriptor constraintWithSameSchema : constraintsWithSameSchema) {
if (constraint.equals(constraintWithSameSchema) && constraint.getName().equals(constraintWithSameSchema.getName())) {
throw new EquivalentSchemaRuleAlreadyExistsException(constraintWithSameSchema, CONSTRAINT_CREATION, token);
}
}
// Name conflict with other schema rule
assertSchemaRuleWithNameDoesNotExist(name);
// Already constrained
for (ConstraintDescriptor constraintWithSameSchema : constraintsWithSameSchema) {
final boolean creatingExistenceConstraint = constraint.type() == ConstraintType.EXISTS;
final boolean existingIsExistenceConstraint = constraintWithSameSchema.type() == ConstraintType.EXISTS;
if (creatingExistenceConstraint == existingIsExistenceConstraint) {
throw new AlreadyConstrainedException(constraintWithSameSchema, CONSTRAINT_CREATION, token);
}
}
// Already indexed
if (constraint.type() != ConstraintType.EXISTS) {
Iterator<IndexDescriptor> existingIndexes = allStoreHolder.index(constraint.schema());
if (existingIndexes.hasNext()) {
IndexDescriptor existingIndex = existingIndexes.next();
throw new AlreadyIndexedException(existingIndex.schema(), CONSTRAINT_CREATION, token);
}
}
// is being populated we will end up with two indexes on the same schema.
if (constraint.isIndexBackedConstraint() && ktx.hasTxStateWithChanges()) {
for (ConstraintDescriptor droppedConstraint : ktx.txState().constraintsChanges().getRemoved()) {
// If dropped and new constraint have similar backing index we cannot allow this constraint creation
if (droppedConstraint.isIndexBackedConstraint() && constraint.schema().equals(droppedConstraint.schema())) {
throw new UnsupportedOperationException(format("Trying to create constraint '%s' in same transaction as dropping '%s'. " + "This is not supported because they are both backed by similar indexes. " + "Please drop constraint in a separate transaction before creating the new one.", constraint.getName(), droppedConstraint.getName()));
}
}
}
}
Aggregations