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");
}
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()));
}
}
}
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()));
}
}
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);
}
}
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 });
}
Aggregations