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