Search in sources :

Example 16 with CoordinateReferenceSystem

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

Example 17 with CoordinateReferenceSystem

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

the class GenericNativeIndexProviderTest method completeConfigurationMustNotOverrideExistingSettings.

@Test
void completeConfigurationMustNotOverrideExistingSettings() {
    // Given
    DatabaseIndexContext context = DatabaseIndexContext.builder(null, null, DEFAULT_DATABASE_NAME).build();
    GenericNativeIndexProvider provider = new GenericNativeIndexProvider(context, IndexDirectoryStructure.NONE, null, Config.defaults());
    Map<String, Value> existingSettings = new HashMap<>();
    CoordinateReferenceSystem existingCrs = CoordinateReferenceSystem.Cartesian;
    DoubleArray min = Values.doubleArray(new double[] { 0, 0 });
    DoubleArray max = Values.doubleArray(new double[] { 1, 1 });
    existingSettings.put(spatialMinSettingForCrs(existingCrs).getSettingName(), min);
    existingSettings.put(spatialMaxSettingForCrs(existingCrs).getSettingName(), max);
    IndexConfig existingIndexConfig = IndexConfig.with(existingSettings);
    LabelSchemaDescriptor incompleteSchema = SchemaDescriptor.forLabel(1, 1);
    IndexDescriptor incompleteDescriptor = IndexPrototype.forSchema(incompleteSchema, IndexProviderDescriptor.UNDECIDED).withName("index").materialise(1).withIndexConfig(existingIndexConfig);
    // When
    IndexDescriptor completedDescriptor = provider.completeConfiguration(incompleteDescriptor);
    // Then
    IndexConfig completedIndexConfig = completedDescriptor.getIndexConfig();
    for (CoordinateReferenceSystem crs : CoordinateReferenceSystem.all()) {
        if (crs.equals(existingCrs)) {
            // Assert value
            assertEquals(min, completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
            assertEquals(max, completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
        } else {
            // Simply assert not null
            assertNotNull(completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
            assertNotNull(completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
        }
    }
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) HashMap(java.util.HashMap) Value(org.neo4j.values.storable.Value) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DoubleArray(org.neo4j.values.storable.DoubleArray) Test(org.junit.jupiter.api.Test)

Example 18 with CoordinateReferenceSystem

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

the class GenericNativeIndexProviderTest method mustCompleteIndexDescriptorConfigurationsWithSpatialConfig.

@Test
void mustCompleteIndexDescriptorConfigurationsWithSpatialConfig() {
    // Given
    DatabaseIndexContext context = DatabaseIndexContext.builder(null, null, DEFAULT_DATABASE_NAME).build();
    GenericNativeIndexProvider provider = new GenericNativeIndexProvider(context, IndexDirectoryStructure.NONE, null, Config.defaults());
    LabelSchemaDescriptor incompleteSchema = SchemaDescriptor.forLabel(1, 1);
    IndexDescriptor incompleteDescriptor = IndexPrototype.forSchema(incompleteSchema, IndexProviderDescriptor.UNDECIDED).withName("index").materialise(1);
    // When
    IndexDescriptor completedDescriptor = provider.completeConfiguration(incompleteDescriptor);
    // Then
    IndexConfig sinfulIndexConfig = incompleteDescriptor.getIndexConfig();
    IndexConfig completedIndexConfig = completedDescriptor.getIndexConfig();
    assertEquals(0, sinfulIndexConfig.entries().count(p -> true), "expected sinful index config to have no entries");
    for (CoordinateReferenceSystem crs : CoordinateReferenceSystem.all()) {
        assertNotNull(completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
        assertNotNull(completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
    }
}
Also used : DoubleArray(org.neo4j.values.storable.DoubleArray) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) HashMap(java.util.HashMap) Config(org.neo4j.configuration.Config) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) Value(org.neo4j.values.storable.Value) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexSettingUtil.spatialMinSettingForCrs(org.neo4j.graphdb.schema.IndexSettingUtil.spatialMinSettingForCrs) Values(org.neo4j.values.storable.Values) Test(org.junit.jupiter.api.Test) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) IndexSettingUtil.spatialMaxSettingForCrs(org.neo4j.graphdb.schema.IndexSettingUtil.spatialMaxSettingForCrs) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Map(java.util.Map) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexConfig(org.neo4j.internal.schema.IndexConfig) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 19 with CoordinateReferenceSystem

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

the class NativeIndexAccessorTests method getValues.

@Test
void getValues() throws IndexEntryConflictException, IndexNotApplicableKernelException {
    // given
    int nUpdates = 10000;
    Iterator<ValueIndexEntryUpdate<IndexDescriptor>> randomUpdateGenerator = valueCreatorUtil.randomUpdateGenerator(random);
    // noinspection unchecked
    ValueIndexEntryUpdate<IndexDescriptor>[] someUpdates = new ValueIndexEntryUpdate[nUpdates];
    for (int i = 0; i < nUpdates; i++) {
        someUpdates[i] = randomUpdateGenerator.next();
    }
    processAll(someUpdates);
    Value[] allValues = ValueCreatorUtil.extractValuesFromUpdates(someUpdates);
    // Pick one out of all added values and do a range query for the value group of that value
    Value value = random.among(allValues);
    ValueGroup valueGroup = value.valueGroup();
    IndexValueCapability valueCapability = indexCapability().valueCapability(valueGroup.category());
    if (!valueCapability.equals(IndexValueCapability.YES)) {
        // We don't need to do this test
        return;
    }
    PropertyIndexQuery.RangePredicate<?> supportedQuery;
    List<Value> expectedValues;
    if (Values.isGeometryValue(value)) {
        // Unless it's a point value in which case we query for the specific coordinate reference system instead
        CoordinateReferenceSystem crs = ((PointValue) value).getCoordinateReferenceSystem();
        supportedQuery = PropertyIndexQuery.range(0, crs);
        expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == ValueGroup.GEOMETRY).filter(v -> ((PointValue) v).getCoordinateReferenceSystem() == crs).collect(Collectors.toList());
    } else {
        supportedQuery = PropertyIndexQuery.range(0, valueGroup);
        expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == valueGroup).collect(Collectors.toList());
    }
    // when
    try (var reader = accessor.newValueReader()) {
        SimpleEntityValueClient client = new SimpleEntityValueClient();
        reader.query(NULL_CONTEXT, client, unorderedValues(), supportedQuery);
        // then
        while (client.next()) {
            Value foundValue = client.values[0];
            assertTrue(expectedValues.remove(foundValue), "found value that was not expected " + foundValue);
        }
        assertThat(expectedValues.size()).as("did not find all expected values").isEqualTo(0);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IndexOrder(org.neo4j.internal.schema.IndexOrder) Arrays(java.util.Arrays) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Iterators.filter(org.neo4j.internal.helpers.collection.Iterators.filter) NULL_CONTEXT(org.neo4j.internal.kernel.api.QueryContext.NULL_CONTEXT) Value(org.neo4j.values.storable.Value) RandomValues(org.neo4j.values.storable.RandomValues) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) IndexEntryUpdate.remove(org.neo4j.storageengine.api.IndexEntryUpdate.remove) Predicates.alwaysTrue(org.neo4j.function.Predicates.alwaysTrue) EMPTY_LONG_ARRAY(org.neo4j.collection.PrimitiveLongCollections.EMPTY_LONG_ARRAY) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) Collectors(java.util.stream.Collectors) PointValue(org.neo4j.values.storable.PointValue) String.format(java.lang.String.format) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Test(org.junit.jupiter.api.Test) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexQueryConstraints.unconstrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.unconstrained) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ValueCreatorUtil.countUniqueValues(org.neo4j.kernel.impl.index.schema.ValueCreatorUtil.countUniqueValues) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IndexCapability(org.neo4j.internal.schema.IndexCapability) IndexDirectoryStructure.directoriesByProvider(org.neo4j.kernel.api.index.IndexDirectoryStructure.directoriesByProvider) Iterables.asUniqueSet(org.neo4j.internal.helpers.collection.Iterables.asUniqueSet) IndexQueryConstraints.unorderedValues(org.neo4j.internal.kernel.api.IndexQueryConstraints.unorderedValues) IndexEntryUpdate.change(org.neo4j.storageengine.api.IndexEntryUpdate.change) Predicates.in(org.neo4j.function.Predicates.in) ArrayList(java.util.ArrayList) Values(org.neo4j.values.storable.Values) HashSet(java.util.HashSet) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexSample(org.neo4j.kernel.api.index.IndexSample) Iterator(java.util.Iterator) ValueType(org.neo4j.values.storable.ValueType) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) IndexQueryConstraints.constrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.constrained) PrimitiveLongCollections(org.neo4j.collection.PrimitiveLongCollections) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) LongIterator(org.eclipse.collections.api.iterator.LongIterator) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) Values.of(org.neo4j.values.storable.Values.of) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) ValueGroup(org.neo4j.values.storable.ValueGroup) Collections(java.util.Collections) ONLINE(org.neo4j.kernel.impl.api.index.IndexUpdateMode.ONLINE) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) PointValue(org.neo4j.values.storable.PointValue) ValueGroup(org.neo4j.values.storable.ValueGroup) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Test(org.junit.jupiter.api.Test)

Example 20 with CoordinateReferenceSystem

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

the class SpaceFillingCurveSettingsFactoryTest method shouldGetModifiedSpaceFillingCurveSettingsForWGS84_3D.

@Test
void shouldGetModifiedSpaceFillingCurveSettingsForWGS84_3D() {
    CoordinateReferenceSystem crs = CoordinateReferenceSystem.WGS84_3D;
    shouldGetCustomSettingsFor(crs, new double[] { -180, -90, -1000000 }, new double[] { 180, 90, 1000000 });
    shouldGetCustomSettingsFor(crs, new double[] { 0, -90, -1000000 }, new double[] { 180, 0, 1000000 });
    shouldGetCustomSettingsFor(crs, new double[] { -90, -45, -1000 }, new double[] { 90, 45, 1000 });
    shouldGetCustomSettingsFor(crs, new double[] { -90, -90, -1000 }, new double[] { 90, 45, 1000 });
    // invalid geographic limits should not affect settings or even the index, but will affect distance and bbox calculations
    shouldGetCustomSettingsFor(crs, new double[] { -1000, -1000, -1000 }, new double[] { 1000, 1000, 1000 });
}
Also used : CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) Test(org.junit.jupiter.api.Test)

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