use of org.neo4j.internal.schema.IndexOrder in project neo4j by neo4j.
the class SimpleIndexAccessorCompatibility method shouldRangeSeekInOrderWithExpectedSize.
private void shouldRangeSeekInOrderWithExpectedSize(IndexOrder order, RangeSeekMode rangeSeekMode, int expectedSize, Object... objects) throws Exception {
PropertyIndexQuery range;
switch(rangeSeekMode) {
case CLOSED:
range = range(100, Values.of(objects[0]), true, Values.of(objects[objects.length - 1]), true);
break;
case OPEN_END:
range = range(100, Values.of(objects[0]), true, null, false);
break;
case OPEN_START:
range = range(100, null, false, Values.of(objects[objects.length - 1]), true);
break;
default:
throw new IllegalStateException();
}
IndexOrderCapability indexOrders = orderCapability(range);
if (order == IndexOrder.ASCENDING) {
Assume.assumeTrue("Assume support for order " + order, indexOrders.supportsAsc());
} else if (order == IndexOrder.DESCENDING) {
Assume.assumeTrue("Assume support for order " + order, indexOrders.supportsDesc());
}
List<ValueIndexEntryUpdate<?>> additions = Arrays.stream(objects).map(o -> add(1, descriptor.schema(), o)).collect(Collectors.toList());
Collections.shuffle(additions, random.random());
updateAndCommit(additions);
SimpleEntityValueClient client = new SimpleEntityValueClient();
try (AutoCloseable ignored = query(client, order, range)) {
List<Long> seenIds = assertClientReturnValuesInOrder(client, order);
assertThat(seenIds.size()).isEqualTo(expectedSize);
}
}
use of org.neo4j.internal.schema.IndexOrder 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.schema.IndexOrder in project neo4j by neo4j.
the class DefaultTokenIndexReader method query.
@Override
public void query(IndexProgressor.EntityTokenClient client, IndexQueryConstraints constraints, TokenPredicate query, EntityRange range, CursorContext cursorContext) {
try {
final int tokenId = query.tokenId();
final IndexOrder order = constraints.order();
Seeker<TokenScanKey, TokenScanValue> seeker = seekerForToken(range, tokenId, order, cursorContext);
IndexProgressor progressor = new TokenScanValueIndexProgressor(seeker, client, order, range);
client.initialize(progressor, tokenId, order);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.neo4j.internal.schema.IndexOrder in project neo4j by neo4j.
the class NativeIndexAccessorTests method throwForUnsupportedIndexOrder.
@Test
void throwForUnsupportedIndexOrder() {
// Unsupported index order for query
try (var reader = accessor.newValueReader()) {
IndexOrder unsupportedOrder = IndexOrder.DESCENDING;
// <- Any spatial value would do
PropertyIndexQuery.ExactPredicate unsupportedQuery = PropertyIndexQuery.exact(0, PointValue.MAX_VALUE);
var e = assertThrows(UnsupportedOperationException.class, () -> reader.query(NULL_CONTEXT, new SimpleEntityValueClient(), constrained(unsupportedOrder, false), unsupportedQuery));
assertThat(e.getMessage()).contains("unsupported order").contains(unsupportedOrder.toString()).contains(unsupportedQuery.toString());
}
}
Aggregations