use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class AbstractIndexProvidedOrderTest method shouldProvideResultInOrderIfCapable.
@Test
void shouldProvideResultInOrderIfCapable() throws KernelException {
int prop = token.propertyKey(PROPERTY_KEY);
RandomValues randomValues = randomRule.randomValues();
IndexReadSession index = read.indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
for (int i = 0; i < N_ITERATIONS; i++) {
ValueType type = randomValues.among(targetedTypes);
IndexOrderCapability order = index.reference().getCapability().orderCapability(type.valueGroup.category());
if (order.supportsAsc()) {
expectResultInOrder(randomValues, type, prop, index, IndexOrder.ASCENDING);
}
if (order.supportsDesc()) {
expectResultInOrder(randomValues, type, prop, index, IndexOrder.DESCENDING);
}
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseFullAccessNodeValueIndexCursor.
@Test
void shouldReuseFullAccessNodeValueIndexCursor() throws Exception {
int prop = token.propertyKey("prop");
IndexDescriptor indexDescriptor = tx.schemaRead().indexGetForName(NODE_PROP_INDEX_NAME);
Predicates.awaitEx(() -> tx.schemaRead().indexGetState(indexDescriptor) == ONLINE, 1, MINUTES);
IndexReadSession indexSession = tx.dataRead().indexReadSession(indexDescriptor);
NodeValueIndexCursor c1 = cursors.allocateFullAccessNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
read.nodeIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.exact(prop, "zero"));
c1.close();
NodeValueIndexCursor c2 = cursors.allocateFullAccessNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithStringInMemoryAndConcurrentUpdate.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithStringInMemoryAndConcurrentUpdate(IndexOrder indexOrder) throws Exception {
String a = "a";
String b = "b";
String c = "c";
createIndex();
TextValue expectedFirst = indexOrder == IndexOrder.ASCENDING ? stringValue(a) : stringValue(c);
TextValue expectedLast = indexOrder == IndexOrder.ASCENDING ? stringValue(c) : stringValue(a);
try (KernelTransaction tx = beginTransaction()) {
int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
entityWithProp(tx, a);
entityWithProp(tx, c);
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
try (var cursor = getEntityValueIndexCursor(tx)) {
PropertyIndexQuery query = PropertyIndexQuery.stringPrefix(prop, stringValue(""));
entityIndexSeek(tx, index, cursor, constrained(indexOrder, true), query);
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(expectedFirst);
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(expectedLast);
concurrentInsert(b);
assertFalse(cursor.next(), () -> "Did not expect to find anything more but found " + cursor.propertyValue(0));
}
tx.commit();
}
// Verify we see all data in the end
try (KernelTransaction tx = beginTransaction()) {
int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
try (var cursor = getEntityValueIndexCursor(tx)) {
PropertyIndexQuery query = PropertyIndexQuery.stringPrefix(prop, stringValue(""));
entityIndexSeek(tx, index, cursor, constrained(indexOrder, true), query);
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(expectedFirst);
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(stringValue(b));
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(expectedLast);
assertFalse(cursor.next());
}
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithPointsWithinSameTile.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithPointsWithinSameTile(IndexOrder indexOrder) throws Exception {
Config config = Config.defaults();
IndexSpecificSpaceFillingCurveSettings indexSettings = IndexSpecificSpaceFillingCurveSettings.fromConfig(config);
SpaceFillingCurve curve = indexSettings.forCrs(WGS84);
// given
// Many random points that all are close enough to each other to belong to the same tile on the space filling curve.
int nbrOfValues = 10000;
PointValue origin = Values.pointValue(WGS84, 0.0, 0.0);
Long derivedValueForCenterPoint = curve.derivedValueFor(origin.coordinate());
double[] centerPoint = curve.centerPointFor(derivedValueForCenterPoint);
double xWidthMultiplier = curve.getTileWidth(0, curve.getMaxLevel()) / 2;
double yWidthMultiplier = curve.getTileWidth(1, curve.getMaxLevel()) / 2;
List<Pair<Long, Value>> expected = new ArrayList<>();
try (KernelTransaction tx = beginTransaction()) {
// NOTE: strings come after points in natural ascending sort order
expected.add(entityWithProp(tx, "a"));
expected.add(entityWithProp(tx, "b"));
for (int i = 0; i < nbrOfValues / 8; i++) {
double x1 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
double x2 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
double y1 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
double y2 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y1)));
expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y2)));
expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y1)));
expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y2)));
}
tx.commit();
}
createIndex();
// when
try (KernelTransaction tx = beginTransaction()) {
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
try (var cursor = getEntityValueIndexCursor(tx)) {
for (int i = 0; i < nbrOfValues / 8; i++) {
double x1 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
double x2 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
double y1 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
double y2 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y1)));
expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y2)));
expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y1)));
expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y2)));
}
expected.add(entityWithProp(tx, "c"));
expected.add(entityWithProp(tx, "d"));
entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
assertResultsInOrder(expected, cursor, indexOrder);
}
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class RelationshipIndexTransactionStateTest method assertEntityAndValueForScan.
@Override
void assertEntityAndValueForScan(Set<Pair<Long, Value>> expected, KernelTransaction tx, IndexDescriptor index, boolean needsValues, Object anotherValueFoundByQuery) throws Exception {
IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
try (RelationshipValueIndexCursor relationships = tx.cursors().allocateRelationshipValueIndexCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().relationshipIndexScan(indexSession, relationships, unordered(needsValues));
assertEntityAndValue(expected, tx, needsValues, anotherValueFoundByQuery, new RelationshipCursorAdapter(relationships));
}
}
Aggregations