Search in sources :

Example 11 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class PointPropertiesRecordFormatIT method createPointArrayPropertyOnLatestDatabase.

@Test
void createPointArrayPropertyOnLatestDatabase() {
    Path storeDir = testDirectory.homePath();
    Label pointNode = Label.label("PointNode");
    String propertyKey = "a";
    PointValue pointValue = pointValue(Cartesian, 1.0, 2.0);
    DatabaseManagementService managementService = startDatabaseService(storeDir);
    GraphDatabaseService database = getDefaultDatabase(managementService);
    try (Transaction transaction = database.beginTx()) {
        Node node = transaction.createNode(pointNode);
        node.setProperty(propertyKey, new PointValue[] { pointValue, pointValue });
        transaction.commit();
    }
    managementService.shutdown();
    managementService = startDatabaseService(storeDir);
    GraphDatabaseService restartedDatabase = getDefaultDatabase(managementService);
    try (Transaction tx = restartedDatabase.beginTx()) {
        try (ResourceIterator<Node> nodes = tx.findNodes(pointNode)) {
            Node node = nodes.next();
            PointValue[] points = (PointValue[]) node.getProperty(propertyKey);
            assertThat(points).hasSize(2);
        }
    }
    managementService.shutdown();
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) PointValue(org.neo4j.values.storable.PointValue) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 12 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class PointPropertiesRecordFormatIT method createPointPropertyOnLatestDatabase.

@Test
void createPointPropertyOnLatestDatabase() {
    Path storeDir = testDirectory.homePath();
    Label pointNode = Label.label("PointNode");
    String propertyKey = "a";
    PointValue pointValue = pointValue(Cartesian, 1.0, 2.0);
    DatabaseManagementService managementService = startDatabaseService(storeDir);
    GraphDatabaseService database = getDefaultDatabase(managementService);
    try (Transaction transaction = database.beginTx()) {
        Node node = transaction.createNode(pointNode);
        node.setProperty(propertyKey, pointValue);
        transaction.commit();
    }
    managementService.shutdown();
    managementService = startDatabaseService(storeDir);
    GraphDatabaseService restartedDatabase = getDefaultDatabase(managementService);
    try (Transaction transaction = restartedDatabase.beginTx()) {
        assertNotNull(transaction.findNode(pointNode, propertyKey, pointValue));
    }
    managementService.shutdown();
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) PointValue(org.neo4j.values.storable.PointValue) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 13 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class PropertyIndexQuery method range.

public static <VALUE extends Value> RangePredicate<?> range(int propertyKeyId, VALUE from, boolean fromInclusive, VALUE to, boolean toInclusive) {
    if (from == null && to == null) {
        throw new IllegalArgumentException("Cannot create RangePredicate without at least one bound");
    }
    ValueGroup valueGroup = from != null ? from.valueGroup() : to.valueGroup();
    switch(valueGroup) {
        case NUMBER:
            return NumberRangePredicate.create(propertyKeyId, (NumberValue) from, fromInclusive, (NumberValue) to, toInclusive);
        case TEXT:
            return new TextRangePredicate(propertyKeyId, (TextValue) from, fromInclusive, (TextValue) to, toInclusive);
        case GEOMETRY:
            PointValue pFrom = (PointValue) from;
            PointValue pTo = (PointValue) to;
            CoordinateReferenceSystem crs = pFrom != null ? pFrom.getCoordinateReferenceSystem() : pTo.getCoordinateReferenceSystem();
            return new GeometryRangePredicate(propertyKeyId, crs, pFrom, fromInclusive, pTo, toInclusive);
        default:
            return new RangePredicate<>(propertyKeyId, valueGroup, from, fromInclusive, to, toInclusive);
    }
}
Also used : PointValue(org.neo4j.values.storable.PointValue) ValueGroup(org.neo4j.values.storable.ValueGroup) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem)

Example 14 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class SchemaComplianceCheckerTest method shouldCheckIndexesWithLookupFiltering.

@Test
void shouldCheckIndexesWithLookupFiltering() throws Exception {
    // given
    LabelSchemaDescriptor descriptor = forLabel(label1, propertyKey1);
    long indexId = uniqueIndex(descriptor);
    long nodeId;
    try (AutoCloseable ignored = tx()) {
        PointValue value = pointValue(CoordinateReferenceSystem.WGS84, 2, 4);
        // (N1) w/ property
        {
            long propId = propertyStore.nextId(CursorContext.NULL);
            nodeId = node(nodeStore.nextId(CursorContext.NULL), propId, NULL, label1);
            property(propId, NULL, NULL, propertyValue(propertyKey1, value));
            indexValue(descriptor, indexId, nodeId, value);
        }
        // (N2) w/ property
        {
            long propId = propertyStore.nextId(CursorContext.NULL);
            long nodeId2 = node(nodeStore.nextId(CursorContext.NULL), propId, NULL, label1);
            property(propId, NULL, NULL, propertyValue(propertyKey1, value));
            indexValue(descriptor, indexId, nodeId2, value);
        }
    }
    // when
    checkIndexed(nodeId);
    // then it should be successful
    expect(ConsistencyReport.NodeConsistencyReport.class, report -> report.uniqueIndexNotUnique(any(), any(), anyLong()));
}
Also used : PointValue(org.neo4j.values.storable.PointValue) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.jupiter.api.Test)

Example 15 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class PrettyPrinterTest method shouldHandlePoints.

@Test
void shouldHandlePoints() {
    // Given
    PointValue pointValue = Values.pointValue(CoordinateReferenceSystem.Cartesian, 11d, 12d);
    PrettyPrinter printer = new PrettyPrinter();
    // When
    pointValue.writeTo(printer);
    // Then
    assertThat(printer.value()).isEqualTo("{geometry: {type: \"Point\", coordinates: [11.0, 12.0], " + "crs: {type: link, properties: " + "{href: \"http://spatialreference.org/ref/sr-org/7203/\", code: " + "7203}}}}");
}
Also used : PointValue(org.neo4j.values.storable.PointValue) Test(org.junit.jupiter.api.Test)

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