Search in sources :

Example 1 with IndexSpecificSpaceFillingCurveSettings

use of org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings in project neo4j by neo4j.

the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithPointsWithinSameTile.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithPointsWithinSameTile(IndexOrder indexOrder) throws Exception {
    Config config = Config.defaults();
    IndexSpecificSpaceFillingCurveSettings indexSettings = IndexSpecificSpaceFillingCurveSettings.fromConfig(config);
    SpaceFillingCurve curve = indexSettings.forCrs(WGS84);
    // given
    // Many random points that all are close enough to each other to belong to the same tile on the space filling curve.
    int nbrOfValues = 10000;
    PointValue origin = Values.pointValue(WGS84, 0.0, 0.0);
    Long derivedValueForCenterPoint = curve.derivedValueFor(origin.coordinate());
    double[] centerPoint = curve.centerPointFor(derivedValueForCenterPoint);
    double xWidthMultiplier = curve.getTileWidth(0, curve.getMaxLevel()) / 2;
    double yWidthMultiplier = curve.getTileWidth(1, curve.getMaxLevel()) / 2;
    List<Pair<Long, Value>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        // NOTE: strings come after points in natural ascending sort order
        expected.add(entityWithProp(tx, "a"));
        expected.add(entityWithProp(tx, "b"));
        for (int i = 0; i < nbrOfValues / 8; i++) {
            double x1 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
            double x2 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
            double y1 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
            double y2 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
            expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y1)));
            expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y2)));
            expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y1)));
            expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y2)));
        }
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            for (int i = 0; i < nbrOfValues / 8; i++) {
                double x1 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
                double x2 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
                double y1 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
                double y2 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
                expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y1)));
                expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y2)));
                expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y1)));
                expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y2)));
            }
            expected.add(entityWithProp(tx, "c"));
            expected.add(entityWithProp(tx, "d"));
            entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
            assertResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : IndexSpecificSpaceFillingCurveSettings(org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PointValue(org.neo4j.values.storable.PointValue) Config(org.neo4j.configuration.Config) ArrayList(java.util.ArrayList) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) SpaceFillingCurve(org.neo4j.gis.spatial.index.curves.SpaceFillingCurve) Pair(org.neo4j.internal.helpers.collection.Pair) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with IndexSpecificSpaceFillingCurveSettings

use of org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings in project neo4j by neo4j.

the class GenericNativeIndexProvider method layout.

@Override
GenericLayout layout(IndexDescriptor descriptor, Path storeFile) {
    int numberOfSlots = descriptor.schema().getPropertyIds().length;
    IndexConfig indexConfig = descriptor.getIndexConfig();
    Map<CoordinateReferenceSystem, SpaceFillingCurveSettings> settings = SpatialIndexConfig.extractSpatialConfig(indexConfig);
    return new GenericLayout(numberOfSlots, new IndexSpecificSpaceFillingCurveSettings(settings));
}
Also used : IndexSpecificSpaceFillingCurveSettings(org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexSpecificSpaceFillingCurveSettings(org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings) SpaceFillingCurveSettings(org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem)

Example 3 with IndexSpecificSpaceFillingCurveSettings

use of org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings in project neo4j by neo4j.

the class GenericNativeIndexAccessorTest method dropShouldDeleteEntireIndexFolder.

@Test
void dropShouldDeleteEntireIndexFolder() {
    // given
    Path root = testDirectory.directory("root");
    IndexDirectoryStructure directoryStructure = IndexDirectoryStructure.directoriesByProvider(root).forProvider(GenericNativeIndexProvider.DESCRIPTOR);
    long indexId = 8;
    IndexDescriptor descriptor = forSchema(SchemaDescriptor.forLabel(1, 1)).withName("index").materialise(indexId);
    IndexSpecificSpaceFillingCurveSettings spatialSettings = mock(IndexSpecificSpaceFillingCurveSettings.class);
    IndexFiles indexFiles = new IndexFiles.Directory(fs, directoryStructure, descriptor.getId());
    DatabaseIndexContext databaseIndexContext = DatabaseIndexContext.builder(pageCache, fs, DEFAULT_DATABASE_NAME).build();
    GenericNativeIndexAccessor accessor = new GenericNativeIndexAccessor(databaseIndexContext, indexFiles, new GenericLayout(1, spatialSettings), immediate(), descriptor, spatialSettings, mock(SpaceFillingCurveConfiguration.class), SIMPLE_NAME_LOOKUP);
    // when
    accessor.drop();
    // then
    assertFalse(fs.fileExists(indexFiles.getBase()));
}
Also used : Path(java.nio.file.Path) IndexSpecificSpaceFillingCurveSettings(org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) SpaceFillingCurveConfiguration(org.neo4j.gis.spatial.index.curves.SpaceFillingCurveConfiguration) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TestDirectory(org.neo4j.test.rule.TestDirectory) Test(org.junit.jupiter.api.Test)

Example 4 with IndexSpecificSpaceFillingCurveSettings

use of org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings in project neo4j by neo4j.

the class GenericBlockBasedIndexPopulatorTest method instantiatePopulator.

private GenericBlockBasedIndexPopulator instantiatePopulator(IndexDescriptor indexDescriptor) throws IOException {
    Config config = Config.defaults();
    IndexSpecificSpaceFillingCurveSettings spatialSettings = IndexSpecificSpaceFillingCurveSettings.fromConfig(config);
    GenericLayout layout = new GenericLayout(1, spatialSettings);
    SpaceFillingCurveConfiguration configuration = SpaceFillingCurveSettingsFactory.getConfiguredSpaceFillingCurveConfiguration(config);
    GenericBlockBasedIndexPopulator populator = new GenericBlockBasedIndexPopulator(databaseIndexContext, indexFiles, layout, indexDescriptor, spatialSettings, configuration, false, heapBufferFactory((int) kibiBytes(40)), config, INSTANCE, tokenNameLookup);
    populator.create();
    return populator;
}
Also used : IndexSpecificSpaceFillingCurveSettings(org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings) Config(org.neo4j.configuration.Config) SpaceFillingCurveConfiguration(org.neo4j.gis.spatial.index.curves.SpaceFillingCurveConfiguration)

Aggregations

IndexSpecificSpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings)4 Config (org.neo4j.configuration.Config)2 SpaceFillingCurveConfiguration (org.neo4j.gis.spatial.index.curves.SpaceFillingCurveConfiguration)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 SpaceFillingCurve (org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)1 Pair (org.neo4j.internal.helpers.collection.Pair)1 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)1 IndexConfig (org.neo4j.internal.schema.IndexConfig)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)1 SpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings)1 TestDirectory (org.neo4j.test.rule.TestDirectory)1 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)1 PointValue (org.neo4j.values.storable.PointValue)1