use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException in project neo4j by neo4j.
the class Operations method validateNoExistingNodeWithExactValues.
/**
* Check so that there is not an existing node with the exact match of label and property
*/
private void validateNoExistingNodeWithExactValues(IndexBackedConstraintDescriptor constraint, PropertyIndexQuery.ExactPredicate[] propertyValues, long modifiedNode) throws UniquePropertyValueValidationException, UnableToValidateConstraintException {
IndexDescriptor index = allStoreHolder.indexGetForName(constraint.getName());
try (FullAccessNodeValueIndexCursor valueCursor = cursors.allocateFullAccessNodeValueIndexCursor(ktx.cursorContext(), memoryTracker);
IndexReaders indexReaders = new IndexReaders(index, allStoreHolder)) {
assertIndexOnline(index);
SchemaDescriptor schema = index.schema();
long[] labelIds = schema.lockingKeys();
if (labelIds.length != 1) {
throw new UnableToValidateConstraintException(constraint, new AssertionError(format("Constraint indexes are not expected to be multi-token indexes, " + "but the constraint %s was referencing an index with the following schema: %s.", constraint.userDescription(token), schema.userDescription(token))), token);
}
// Take a big fat lock, and check for existing node in index
ktx.lockClient().acquireExclusive(ktx.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelIds[0], propertyValues));
allStoreHolder.nodeIndexSeekWithFreshIndexReader(valueCursor, indexReaders.createReader(), propertyValues);
if (valueCursor.next() && valueCursor.nodeReference() != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(valueCursor.nodeReference(), NO_SUCH_NODE, PropertyIndexQuery.asValueTuple(propertyValues)), token);
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e, token);
}
}
use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException in project neo4j by neo4j.
the class SchemaComplianceChecker method queryIndexOrEmpty.
private static LongIterator queryIndexOrEmpty(ValueIndexReader reader, PropertyIndexQuery[] query) {
try {
NodeValueIterator indexedNodeIds = new NodeValueIterator();
reader.query(NULL_CONTEXT, indexedNodeIds, unconstrained(), query);
return indexedNodeIds;
} catch (IndexNotApplicableKernelException e) {
throw new RuntimeException(format("Consistency checking error: index provider does not support exact query %s", Arrays.toString(query)), e);
}
}
use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException in project neo4j by neo4j.
the class NativeIndexAccessorTests method expectIndexOrder.
private static void expectIndexOrder(Value[] allValues, ValueGroup valueGroup, ValueIndexReader reader, IndexOrder supportedOrder, PropertyIndexQuery.RangePredicate<?> supportedQuery) throws IndexNotApplicableKernelException {
Value[] expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == valueGroup).toArray(Value[]::new);
if (supportedOrder == IndexOrder.ASCENDING) {
Arrays.sort(expectedValues, Values.COMPARATOR);
} else if (supportedOrder == IndexOrder.DESCENDING) {
Arrays.sort(expectedValues, Values.COMPARATOR.reversed());
}
SimpleEntityValueClient client = new SimpleEntityValueClient();
reader.query(NULL_CONTEXT, client, constrained(supportedOrder, true), supportedQuery);
int i = 0;
while (client.next()) {
assertEquals(expectedValues[i++], client.values[0], "values in order");
}
assertEquals(i, expectedValues.length, "found all values");
}
use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException in project neo4j by neo4j.
the class FusionIndexReader method query.
@Override
public void query(QueryContext context, IndexProgressor.EntityValueClient cursor, IndexQueryConstraints constraints, PropertyIndexQuery... predicates) throws IndexNotApplicableKernelException {
IndexSlot slot = slotSelector.selectSlot(predicates, PropertyIndexQuery::valueCategory);
if (slot != null) {
instanceSelector.select(slot).query(context, cursor, constraints, predicates);
} else {
if (constraints.isOrdered()) {
throw new UnsupportedOperationException(format("Tried to query index with unsupported order %s. Supported orders for query %s are %s.", constraints.order(), Arrays.toString(predicates), IndexOrder.NONE));
}
BridgingIndexProgressor multiProgressor = new BridgingIndexProgressor(cursor, descriptor.schema().getPropertyIds());
cursor.initialize(descriptor, multiProgressor, predicates, constraints, false);
try {
instanceSelector.forAll(reader -> {
try {
reader.query(context, multiProgressor, constraints, predicates);
} catch (IndexNotApplicableKernelException e) {
throw new InnerException(e);
}
});
} catch (InnerException e) {
throw e.getCause();
}
}
}
use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException in project neo4j by neo4j.
the class SimpleValueIndexReader method toLuceneQuery.
private static Query toLuceneQuery(PropertyIndexQuery... predicates) throws IndexNotApplicableKernelException {
PropertyIndexQuery predicate = predicates[0];
switch(predicate.type()) {
case exact:
Value[] values = new Value[predicates.length];
for (int i = 0; i < predicates.length; i++) {
assert predicates[i].type() == exact : "Exact followed by another query predicate type is not supported at this moment.";
values[i] = ((PropertyIndexQuery.ExactPredicate) predicates[i]).value();
}
return LuceneDocumentStructure.newSeekQuery(values);
case exists:
for (PropertyIndexQuery p : predicates) {
if (p.type() != IndexQueryType.exists) {
throw new IndexNotApplicableKernelException("Exists followed by another query predicate type is not supported.");
}
}
return LuceneDocumentStructure.newScanQuery();
case range:
assertNotComposite(predicates);
if (predicate.valueGroup() == ValueGroup.TEXT) {
PropertyIndexQuery.TextRangePredicate sp = (PropertyIndexQuery.TextRangePredicate) predicate;
return LuceneDocumentStructure.newRangeSeekByStringQuery(sp.from(), sp.fromInclusive(), sp.to(), sp.toInclusive());
}
throw new UnsupportedOperationException(format("Range scans of value group %s are not supported", predicate.valueGroup()));
case stringPrefix:
assertNotComposite(predicates);
PropertyIndexQuery.StringPrefixPredicate spp = (PropertyIndexQuery.StringPrefixPredicate) predicate;
return LuceneDocumentStructure.newRangeSeekByPrefixQuery(spp.prefix().stringValue());
case stringContains:
assertNotComposite(predicates);
PropertyIndexQuery.StringContainsPredicate scp = (PropertyIndexQuery.StringContainsPredicate) predicate;
return LuceneDocumentStructure.newWildCardStringQuery(scp.contains().stringValue());
case stringSuffix:
assertNotComposite(predicates);
PropertyIndexQuery.StringSuffixPredicate ssp = (PropertyIndexQuery.StringSuffixPredicate) predicate;
return LuceneDocumentStructure.newSuffixStringQuery(ssp.suffix().stringValue());
default:
// todo figure out a more specific exception
throw new RuntimeException("Index query not supported: " + Arrays.toString(predicates));
}
}
Aggregations