Search in sources :

Example 21 with PointValue

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);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.pointValue(org.neo4j.values.storable.Values.pointValue) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with PointValue

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);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.pointValue(org.neo4j.values.storable.Values.pointValue) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with PointValue

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);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.pointValue(org.neo4j.values.storable.Values.pointValue) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with PointValue

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;
    }
}
Also used : PointValue(org.neo4j.values.storable.PointValue) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) DateValue(org.neo4j.values.storable.DateValue) Values.intValue(org.neo4j.values.storable.Values.intValue)

Example 25 with PointValue

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");
}
Also used : PointValue(org.neo4j.values.storable.PointValue) SpaceFillingCurve(org.neo4j.gis.spatial.index.curves.SpaceFillingCurve) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) PointArray(org.neo4j.values.storable.PointArray) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PointValue (org.neo4j.values.storable.PointValue)32 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 Value (org.neo4j.values.storable.Value)9 EnumSource (org.junit.jupiter.params.provider.EnumSource)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 Transaction (org.neo4j.graphdb.Transaction)6 Pair (org.neo4j.internal.helpers.collection.Pair)6 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)5 Values.stringValue (org.neo4j.values.storable.Values.stringValue)5 Path (java.nio.file.Path)4 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)4 Node (org.neo4j.graphdb.Node)4 TextValue (org.neo4j.values.storable.TextValue)4 Values.pointValue (org.neo4j.values.storable.Values.pointValue)4 SpaceFillingCurve (org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3