use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexOrderTestBase method shouldRangeScanInOrderWithTxState.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldRangeScanInOrderWithTxState(IndexOrder indexOrder) throws Exception {
List<Pair<Long, Value>> expected = new ArrayList<>();
try (KernelTransaction tx = beginTransaction()) {
expected.add(entityWithProp(tx, "hello"));
entityWithProp(tx, "bellow");
expected.add(entityWithProp(tx, "schmello"));
expected.add(entityWithProp(tx, "low"));
expected.add(entityWithProp(tx, "trello"));
entityWithProp(tx, "yellow");
expected.add(entityWithProp(tx, "loww"));
entityWithProp(tx, "below");
tx.commit();
}
createIndex();
// when
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)) {
entityWithProp(tx, "allow");
expected.add(entityWithProp(tx, "now"));
expected.add(entityWithProp(tx, "jello"));
entityWithProp(tx, "willow");
PropertyIndexQuery query = PropertyIndexQuery.range(prop, "hello", true, "trello", true);
entityIndexSeek(tx, index, cursor, constrained(indexOrder, true), query);
assertResultsInOrder(expected, cursor, indexOrder);
}
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexOrderTestBase method shouldDoOrderedCompositeIndexScanWithPointsInBothValues.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldDoOrderedCompositeIndexScanWithPointsInBothValues(IndexOrder indexOrder) throws Exception {
List<Pair<Long, Value[]>> expected = new ArrayList<>();
try (KernelTransaction tx = beginTransaction()) {
expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, -500000), "a"));
expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, -500000), "a"));
expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, 500000), "a"));
expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, 500000), "a"));
expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, -500000), "b"));
expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, -500000), "b"));
expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, 500000), "b"));
expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, 500000), "b"));
expected.add(entityWithTwoProps(tx, "a", pointValue(Cartesian, -500000, -500000)));
expected.add(entityWithTwoProps(tx, "a", pointValue(Cartesian, 500000, -500000)));
expected.add(entityWithTwoProps(tx, "a", pointValue(Cartesian, -500000, 500000)));
expected.add(entityWithTwoProps(tx, "a", pointValue(Cartesian, 500000, 500000)));
tx.commit();
}
createCompositeIndex();
// when
try (KernelTransaction tx = beginTransaction()) {
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
try (var cursor = getEntityValueIndexCursor(tx)) {
entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
assertCompositeResultsInOrder(expected, cursor, indexOrder);
}
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithPointsAndNodesBefore.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithPointsAndNodesBefore(IndexOrder indexOrder) throws Exception {
List<Pair<Long, Value>> expected = new ArrayList<>();
try (KernelTransaction tx = beginTransaction()) {
// NOTE: arrays come before points in natural ascending sort order
expected.add(entityWithProp(tx, new String[] { "a" }));
expected.add(entityWithProp(tx, new String[] { "b" }));
expected.add(entityWithProp(tx, new String[] { "c" }));
expected.add(entityWithProp(tx, pointValue(Cartesian, -500000, -500000)));
expected.add(entityWithProp(tx, pointValue(Cartesian, 500000, -500000)));
expected.add(entityWithProp(tx, pointValue(Cartesian, -500000, 500000)));
expected.add(entityWithProp(tx, pointValue(Cartesian, 500000, 500000)));
tx.commit();
}
createIndex();
// when
try (KernelTransaction tx = beginTransaction()) {
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
try (var cursor = getEntityValueIndexCursor(tx)) {
expected.add(entityWithProp(tx, pointValue(Cartesian, -400000, -400000)));
expected.add(entityWithProp(tx, pointValue(Cartesian, 400000, -400000)));
expected.add(entityWithProp(tx, pointValue(Cartesian, -400000, 400000)));
expected.add(entityWithProp(tx, pointValue(Cartesian, 400000, 400000)));
expected.add(entityWithProp(tx, new String[] { "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 NodeIndexTransactionStateTest 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 (NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().nodeIndexScan(indexSession, nodes, unordered(needsValues));
assertEntityAndValue(expected, tx, needsValues, anotherValueFoundByQuery, new NodeCursorAdapter(nodes));
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexOrderTestBase method shouldPrefixScanInOrder.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldPrefixScanInOrder(IndexOrder indexOrder) throws Exception {
List<Pair<Long, Value>> expected = new ArrayList<>();
try (KernelTransaction tx = beginTransaction()) {
expected.add(entityWithProp(tx, "bee hive"));
entityWithProp(tx, "a");
expected.add(entityWithProp(tx, "become"));
expected.add(entityWithProp(tx, "be"));
expected.add(entityWithProp(tx, "bachelor"));
entityWithProp(tx, "street smart");
expected.add(entityWithProp(tx, "builder"));
entityWithProp(tx, "ceasar");
tx.commit();
}
createIndex();
// when
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)) {
entityWithProp(tx, "allow");
expected.add(entityWithProp(tx, "bastard"));
expected.add(entityWithProp(tx, "bully"));
entityWithProp(tx, "willow");
PropertyIndexQuery query = PropertyIndexQuery.stringPrefix(prop, stringValue("b"));
entityIndexSeek(tx, index, cursor, constrained(indexOrder, true), query);
assertResultsInOrder(expected, cursor, indexOrder);
}
}
}
Aggregations