use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient 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.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.
the class IndexAccessorCompatibility method query.
protected List<Long> query(PropertyIndexQuery... predicates) throws Exception {
try (ValueIndexReader reader = accessor.newValueReader()) {
SimpleEntityValueClient nodeValueClient = new SimpleEntityValueClient();
reader.query(NULL_CONTEXT, nodeValueClient, unconstrained(), predicates);
List<Long> list = new LinkedList<>();
while (nodeValueClient.next()) {
long entityId = nodeValueClient.reference;
if (passesFilter(entityId, predicates)) {
list.add(entityId);
}
}
Collections.sort(list);
return list;
}
}
use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient 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.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.
the class CompositeIndexAccessorCompatibility method shouldSeekInOrderExactWithRange.
private void shouldSeekInOrderExactWithRange(IndexOrder order, Object o0, Object o1, Object o2, Object o3, Object o4, Object o5) throws Exception {
// Todo use random value instead
Object baseValue = 1;
PropertyIndexQuery exact = exact(100, baseValue);
PropertyIndexQuery range = range(200, Values.of(o0), true, Values.of(o5), true);
IndexOrderCapability indexOrders = orderCapability(exact, 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());
}
updateAndCommit(asList(add(1, descriptor.schema(), baseValue, o0), add(1, descriptor.schema(), baseValue, o5), add(1, descriptor.schema(), baseValue, o1), add(1, descriptor.schema(), baseValue, o4), add(1, descriptor.schema(), baseValue, o2), add(1, descriptor.schema(), baseValue, o3)));
SimpleEntityValueClient client = new SimpleEntityValueClient();
try (AutoCloseable ignored = query(client, order, exact, range)) {
List<Long> seenIds = assertClientReturnValuesInOrder(client, order);
assertThat(seenIds.size()).isEqualTo(6);
}
}
use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.
the class CompositeIndexAccessorCompatibility method mustThrowOnIllegalCompositeQueriesAndMustNotThrowOnLegalQueries.
/* Composite query validity */
/**
* This test verify behavior for all different index patterns on a two column composite index.
* A composite query need to have decreasing precision among the queries.
* This means a range or exists query can only be followed by and exists query.
* Prefix query is also included under "range".
* Contains or suffix queries are not allowed in a composite query at all.
*
* Those are all the different combinations:
* x = exact
* < = range (also include stringPrefix)
* - = exists
* ! = stringContains or stringSuffix
* ? = any predicate
* Index patterns
* x x ok
* x < ok
* x - ok
* < x not ok
* < < not ok
* < - ok
* - x not ok
* - < not ok
* - - ok
* ! ? not ok
*/
@Test
public void mustThrowOnIllegalCompositeQueriesAndMustNotThrowOnLegalQueries() throws Exception {
Assume.assumeTrue("Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries());
// given
Value someValue = Values.of(true);
TextValue someString = stringValue("");
PropertyIndexQuery firstExact = exact(100, someValue);
PropertyIndexQuery firstRange = range(100, someValue, true, someValue, true);
PropertyIndexQuery firstPrefix = stringPrefix(100, someString);
PropertyIndexQuery firstExist = exists(100);
PropertyIndexQuery firstSuffix = stringSuffix(100, someString);
PropertyIndexQuery firstContains = stringContains(100, someString);
PropertyIndexQuery secondExact = exact(200, someValue);
PropertyIndexQuery secondRange = range(200, someValue, true, someValue, true);
PropertyIndexQuery secondExist = exists(200);
PropertyIndexQuery secondPrefix = stringPrefix(100, someString);
PropertyIndexQuery secondSuffix = stringSuffix(100, someString);
PropertyIndexQuery secondContains = stringContains(100, someString);
List<Pair<PropertyIndexQuery[], Boolean>> queries = Arrays.asList(of(new PropertyIndexQuery[] { firstExact, secondExact }, true), of(new PropertyIndexQuery[] { firstExact, secondRange }, true), of(new PropertyIndexQuery[] { firstExact, secondExist }, true), of(new PropertyIndexQuery[] { firstExact, secondPrefix }, true), of(new PropertyIndexQuery[] { firstExact, secondSuffix }, false), of(new PropertyIndexQuery[] { firstExact, secondContains }, false), of(new PropertyIndexQuery[] { firstRange, secondExact }, false), of(new PropertyIndexQuery[] { firstRange, secondRange }, false), of(new PropertyIndexQuery[] { firstRange, secondExist }, true), of(new PropertyIndexQuery[] { firstRange, secondPrefix }, false), of(new PropertyIndexQuery[] { firstRange, secondSuffix }, false), of(new PropertyIndexQuery[] { firstRange, secondContains }, false), of(new PropertyIndexQuery[] { firstPrefix, secondExact }, false), of(new PropertyIndexQuery[] { firstPrefix, secondRange }, false), of(new PropertyIndexQuery[] { firstPrefix, secondExist }, true), of(new PropertyIndexQuery[] { firstPrefix, secondPrefix }, false), of(new PropertyIndexQuery[] { firstPrefix, secondSuffix }, false), of(new PropertyIndexQuery[] { firstPrefix, secondContains }, false), of(new PropertyIndexQuery[] { firstExist, secondExact }, false), of(new PropertyIndexQuery[] { firstExist, secondRange }, false), of(new PropertyIndexQuery[] { firstExist, secondExist }, true), of(new PropertyIndexQuery[] { firstExist, secondPrefix }, false), of(new PropertyIndexQuery[] { firstExist, secondSuffix }, false), of(new PropertyIndexQuery[] { firstExist, secondContains }, false), of(new PropertyIndexQuery[] { firstSuffix, secondExact }, false), of(new PropertyIndexQuery[] { firstSuffix, secondRange }, false), of(new PropertyIndexQuery[] { firstSuffix, secondExist }, false), of(new PropertyIndexQuery[] { firstSuffix, secondPrefix }, false), of(new PropertyIndexQuery[] { firstSuffix, secondSuffix }, false), of(new PropertyIndexQuery[] { firstSuffix, secondContains }, false), of(new PropertyIndexQuery[] { firstContains, secondExact }, false), of(new PropertyIndexQuery[] { firstContains, secondRange }, false), of(new PropertyIndexQuery[] { firstContains, secondExist }, false), of(new PropertyIndexQuery[] { firstContains, secondPrefix }, false), of(new PropertyIndexQuery[] { firstContains, secondSuffix }, false), of(new PropertyIndexQuery[] { firstContains, secondContains }, false));
SimpleEntityValueClient client = new SimpleEntityValueClient();
try (ValueIndexReader reader = accessor.newValueReader()) {
for (Pair<PropertyIndexQuery[], Boolean> pair : queries) {
PropertyIndexQuery[] theQuery = pair.first();
Boolean legal = pair.other();
if (legal) {
// when
reader.query(NULL_CONTEXT, client, unconstrained(), theQuery);
// then should not throw
} else {
try {
// when
reader.query(NULL_CONTEXT, client, unconstrained(), theQuery);
fail("Expected index reader to throw for illegal composite query. Query was, " + Arrays.toString(theQuery));
} catch (IllegalArgumentException e) {
// then
assertThat(e.getMessage()).contains("Tried to query index with illegal composite query.");
}
}
}
}
}
Aggregations