use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.
the class IndexOrderTestBase method shouldNodeCompositeIndexScanInOrderWithPointsAndSingleNodeAfterwards.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeCompositeIndexScanInOrderWithPointsAndSingleNodeAfterwards(IndexOrder indexOrder) throws Exception {
List<Pair<Long, Value[]>> expected = new ArrayList<>();
try (KernelTransaction tx = beginTransaction()) {
expected.add(entityWithTwoProps(tx, new String[] { "a" }, new String[] { "b" }));
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, "b", new String[] { "b" }));
expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, -500000)));
expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, -500000)));
expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, 500000)));
expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, 500000)));
expected.add(entityWithTwoProps(tx, "c", new String[] { "b" }));
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.values.storable.PointValue 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.values.storable.PointValue in project neo4j by neo4j.
the class IndexOrderTestBase method shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithTwoGapsBetween.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithTwoGapsBetween(IndexOrder indexOrder) throws Exception {
List<Pair<Long, Value[]>> expected = new ArrayList<>();
try (KernelTransaction tx = beginTransaction()) {
expected.add(entityWithTwoProps(tx, new String[] { "a" }, new String[] { "b" }));
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, "b", new String[] { "b" }));
expected.add(entityWithTwoProps(tx, "b", new String[] { "c" }));
expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, -500000)));
expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, -500000)));
expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, 500000)));
expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, 500000)));
expected.add(entityWithTwoProps(tx, "c", new String[] { "b" }));
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.values.storable.PointValue in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method assertFoundEntitiesInOrder.
private void assertFoundEntitiesInOrder(ENTITY_VALUE_INDEX_CURSOR cursor, IndexOrder indexOrder) {
Value currentValue = null;
while (cursor.next()) {
long reference = entityParams.entityReference(cursor);
Value storedValue = entityParams.getPropertyValueFromStore(tx, cursors, reference);
// Sort order for points is explicitly handled by the client, see DefaultNodeValueIndexCursor
if (storedValue instanceof PointValue) {
continue;
}
if (currentValue != null) {
switch(indexOrder) {
case ASCENDING:
assertTrue(Values.COMPARATOR.compare(currentValue, storedValue) <= 0, "Requested ordering " + indexOrder + " was not respected.");
break;
case DESCENDING:
assertTrue(Values.COMPARATOR.compare(currentValue, storedValue) >= 0, "Requested ordering " + indexOrder + " was not respected.");
break;
case NONE:
// Don't verify
break;
default:
throw new UnsupportedOperationException("Can not verify ordering for " + indexOrder);
}
}
currentValue = storedValue;
}
}
use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.
the class GenericKeyStateTest method comparePointArraysMustOnlyReturnZeroForEqualArrays.
@Test
void comparePointArraysMustOnlyReturnZeroForEqualArrays() {
PointArray firstArray = random.randomValues().nextPointArray();
PointValue[] sourcePointValues = firstArray.asObjectCopy();
PointArray equalArray = Values.pointArray(sourcePointValues);
PointValue[] centerPointValues = new PointValue[sourcePointValues.length];
for (int i = 0; i < sourcePointValues.length; i++) {
PointValue sourcePointValue = sourcePointValues[i];
CoordinateReferenceSystem crs = sourcePointValue.getCoordinateReferenceSystem();
SpaceFillingCurve curve = noSpecificIndexSettings.forCrs(crs);
Long spaceFillingCurveValue = curve.derivedValueFor(sourcePointValue.coordinate());
centerPointValues[i] = Values.pointValue(crs, curve.centerPointFor(spaceFillingCurveValue));
}
PointArray centerArray = Values.pointArray(centerPointValues);
GenericKey firstKey = newKeyState();
firstKey.writeValue(firstArray, NEUTRAL);
GenericKey equalKey = newKeyState();
equalKey.writeValue(equalArray, NEUTRAL);
GenericKey centerKey = newKeyState();
centerKey.writeValue(centerArray, NEUTRAL);
GenericKey noCoordsKey = newKeyState();
noCoordsKey.writeValue(equalArray, NEUTRAL);
GeometryType.setNoCoordinates(noCoordsKey);
assertEquals(0, firstKey.compareValueTo(equalKey), "expected keys to be equal");
assertEquals(firstArray.compareToSequence(centerArray, AnyValues.COMPARATOR) != 0, firstKey.compareValueTo(centerKey) != 0, "expected keys to be equal if and only if source points are equal");
assertEquals(0, firstKey.compareValueTo(noCoordsKey), "expected keys to be equal");
}
Aggregations