Search in sources :

Example 11 with CoordinateReferenceSystem

use of org.neo4j.values.storable.CoordinateReferenceSystem 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 12 with CoordinateReferenceSystem

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

the class IndexConfigMigrationIT method shouldHaveCorrectDataAndIndexConfiguration.

@Test
void shouldHaveCorrectDataAndIndexConfiguration() throws IOException, IndexNotFoundKernelException {
    Path databaseDir = databaseLayout.databaseDirectory();
    unzip(getClass(), ZIP_FILE_3_5, databaseDir);
    // when
    DatabaseManagementServiceBuilder builder = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setConfig(GraphDatabaseSettings.allow_upgrade, true);
    DatabaseManagementService dbms = builder.build();
    try {
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        Set<CoordinateReferenceSystem> allCRS = Iterables.asSet(all());
        try (Transaction tx = db.beginTx()) {
            validateIndexes(tx);
            for (Node node : tx.getAllNodes()) {
                hasLabels(node, label1, label2, label3, label4);
                Object property = node.getProperty(propKey);
                if (property instanceof PointValue) {
                    allCRS.remove(((PointValue) property).getCoordinateReferenceSystem());
                }
            }
            assertTrue(allCRS.isEmpty(), "Expected all CRS to be represented in store, but missing " + allCRS);
            assertIndexConfiguration(db, tx);
            assertFulltextIndexConfiguration(db, tx);
            tx.commit();
        }
    } finally {
        dbms.shutdown();
    }
    // Assert old index files has been removed
    Path baseSchemaIndexFolder = IndexDirectoryStructure.baseSchemaIndexFolder(databaseDir);
    Set<Path> retiredIndexProviderDirectories = Set.of(baseSchemaIndexFolder.resolve("lucene"), baseSchemaIndexFolder.resolve("lucene-1.0"), baseSchemaIndexFolder.resolve("lucene_native-1.0"), baseSchemaIndexFolder.resolve("lucene_native-2.0"));
    try (Stream<Path> list = Files.list(baseSchemaIndexFolder)) {
        list.forEach(indexProviderDirectory -> assertFalse(retiredIndexProviderDirectories.contains(indexProviderDirectory), "Expected old index provider directories to be deleted during migration but store still had directory " + indexProviderDirectory));
    }
}
Also used : Path(java.nio.file.Path) PointValue(org.neo4j.values.storable.PointValue) Node(org.neo4j.graphdb.Node) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 13 with CoordinateReferenceSystem

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

the class IndexConfigMigrationIT method createSpatialData.

private static void createSpatialData(GraphDatabaseService db, Label... labels) {
    try (Transaction tx = db.beginTx()) {
        for (CoordinateReferenceSystem crs : all()) {
            Node node = tx.createNode(labels);
            int dim = crs.getDimension();
            double[] coords = new double[dim];
            node.setProperty(propKey, Values.pointValue(crs, coords));
        }
        tx.commit();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem)

Example 14 with CoordinateReferenceSystem

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

the class GeometryArrayType method asValue.

@Override
Value asValue(GenericKey state) {
    Point[] points = new Point[state.arrayLength];
    if (points.length > 0) {
        assertHasCoordinates(state);
        CoordinateReferenceSystem crs = CoordinateReferenceSystem.get((int) state.long1, (int) state.long2);
        int dimensions = dimensions(state);
        for (int i = 0; i < points.length; i++) {
            points[i] = GeometryType.asValue(state, crs, dimensions * i);
        }
    }
    return Values.pointArray(points);
}
Also used : GeometryType.putPoint(org.neo4j.kernel.impl.index.schema.GeometryType.putPoint) Point(org.neo4j.graphdb.spatial.Point) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) GeometryType.putPoint(org.neo4j.kernel.impl.index.schema.GeometryType.putPoint) Point(org.neo4j.graphdb.spatial.Point)

Example 15 with CoordinateReferenceSystem

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

the class GenericNativeIndexReader method query.

@Override
public void query(QueryContext context, IndexProgressor.EntityValueClient client, IndexQueryConstraints constraints, PropertyIndexQuery... query) {
    PropertyIndexQuery.GeometryRangePredicate geometryRangePredicate = getGeometryRangePredicateIfAny(query);
    if (geometryRangePredicate != null) {
        validateQuery(constraints, query);
        try {
            // If there's a GeometryRangeQuery among the predicates then this query changes from a straight-forward: build from/to and seek...
            // into a query that is split into multiple sub-queries. Predicates both before and after will have to be accompanied each sub-query.
            BridgingIndexProgressor multiProgressor = new BridgingIndexProgressor(client, descriptor.schema().getPropertyIds());
            client.initialize(descriptor, multiProgressor, query, constraints, false);
            double[] from = geometryRangePredicate.from() == null ? null : geometryRangePredicate.from().coordinate();
            double[] to = geometryRangePredicate.to() == null ? null : geometryRangePredicate.to().coordinate();
            CoordinateReferenceSystem crs = geometryRangePredicate.crs();
            SpaceFillingCurve curve = spaceFillingCurveSettings.forCrs(crs);
            List<SpaceFillingCurve.LongRange> ranges = curve.getTilesIntersectingEnvelope(from, to, configuration);
            for (SpaceFillingCurve.LongRange range : ranges) {
                // Here's a sub-query that we'll have to do for this geometry range. Build this query from all predicates
                // and when getting to the geometry range predicate that sparked these sub-query chenanigans, swap in this sub-query in its place.
                GenericKey treeKeyFrom = layout.newKey();
                GenericKey treeKeyTo = layout.newKey();
                initializeFromToKeys(treeKeyFrom, treeKeyTo);
                boolean needFiltering = initializeRangeForGeometrySubQuery(treeKeyFrom, treeKeyTo, query, crs, range);
                startSeekForInitializedRange(multiProgressor, treeKeyFrom, treeKeyTo, query, constraints, needFiltering, context.cursorContext());
            }
        } catch (IllegalArgumentException e) {
            // Invalid query ranges will cause this state (eg. min>max)
            client.initialize(descriptor, IndexProgressor.EMPTY, query, constraints, false);
        }
    } else {
        super.query(context, client, constraints, query);
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) SpaceFillingCurve(org.neo4j.gis.spatial.index.curves.SpaceFillingCurve) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) BridgingIndexProgressor(org.neo4j.kernel.api.index.BridgingIndexProgressor)

Aggregations

CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)21 Test (org.junit.jupiter.api.Test)10 HashMap (java.util.HashMap)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)5 PointValue (org.neo4j.values.storable.PointValue)5 SpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings)4 Value (org.neo4j.values.storable.Value)4 SpaceFillingCurve (org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)3 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Config (org.neo4j.configuration.Config)2 Node (org.neo4j.graphdb.Node)2 Transaction (org.neo4j.graphdb.Transaction)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)2 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)2 ConfiguredSpaceFillingCurveSettingsCache (org.neo4j.kernel.impl.index.schema.config.ConfiguredSpaceFillingCurveSettingsCache)2 IndexSpecificSpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings)2 DoubleArray (org.neo4j.values.storable.DoubleArray)2