From be6a377751ce585785700b2c6c3d6a9eb8e33aa3 Mon Sep 17 00:00:00 2001 From: Vilnis Termanis Date: Tue, 31 May 2022 11:36:14 +0100 Subject: [PATCH] jena-geosparql - Add assembler option to disable spatial index - Now have to/from-file, in-memory and no index options --- .../jena/geosparql/assembler/GeoAssembler.java | 13 +++++++++---- .../jena/geosparql/assembler/VocabGeoSPARQL.java | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/GeoAssembler.java b/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/GeoAssembler.java index 5eb53c29217..ef1bff50f94 100644 --- a/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/GeoAssembler.java +++ b/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/GeoAssembler.java @@ -117,6 +117,11 @@ public DatasetGraph createDataset(Assembler a, Resource root) { if (root.hasProperty(pSpatialIndexFile) ) spatialIndexFilename = GraphUtils.getStringValue(root, pSpatialIndexFile); + // Spatial Index enabled. + boolean spatialIndexEnabled = true; + if (root.hasProperty(pSpatialIndexEnabled) ) + spatialIndexEnabled = getBooleanValue(root, pSpatialIndexEnabled); + // ---- Build Dataset dataset = DatasetFactory.wrap(base); @@ -148,7 +153,7 @@ public DatasetGraph createDataset(Assembler a, Resource root) { GeoSPARQLConfig.setupNoIndex(queryRewrite); } - prepareSpatialExtension(dataset, spatialIndexFilename); + prepareSpatialExtension(dataset, spatialIndexEnabled, spatialIndexFilename); return base; } @@ -165,13 +170,13 @@ private static List getListInteger(Resource r, Property p, int len) { return integerList; } - private static void prepareSpatialExtension(Dataset dataset, String spatialIndex){ + private static void prepareSpatialExtension(Dataset dataset, boolean spatialIndexEnabled, String spatialIndex){ boolean isEmpty = dataset.calculate(()->dataset.isEmpty()); - if ( isEmpty && spatialIndex != null ) { + if ( isEmpty && spatialIndexEnabled && spatialIndex != null ) { LOG.warn("Dataset empty. Spatial Index not constructed. Server will require restarting after adding data and any updates to build Spatial Index."); return; } - if ( isEmpty ) + if ( isEmpty || !spatialIndexEnabled ) // Nothing to do. return; diff --git a/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/VocabGeoSPARQL.java b/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/VocabGeoSPARQL.java index 49dafdd635b..1ffb2990f20 100644 --- a/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/VocabGeoSPARQL.java +++ b/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/VocabGeoSPARQL.java @@ -73,6 +73,9 @@ private static Property property(String shortName) { // "File to load or store the spatial index. Default to " + SPATIAL_INDEX_FILE + " in TDB folder if using TDB and not set. Otherwise spatial index is not stored. public static final Property pSpatialIndexFile = property("spatialIndexFile"); + // Whether to load/generate the spatial index at all (defaults to True). With this off, the value of spatialIndexFile will be ignored. + public static final Property pSpatialIndexEnabled = property("spatialIndexEnabled"); + // Dataset public static final Property pDataset = property("dataset"); }