Skip to content

Commit

Permalink
apacheGH-3026: spatial index per graph and kryo serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenz Buehmann authored and Aklakan committed Feb 26, 2025
1 parent a3983b2 commit 0829aa5
Show file tree
Hide file tree
Showing 43 changed files with 2,710 additions and 154 deletions.
92 changes: 92 additions & 0 deletions jena-arq/src/main/java/org/apache/jena/system/TxnCtl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jena.system;

import java.util.Objects;

import org.apache.jena.query.ReadWrite;
import org.apache.jena.query.TxnType;
import org.apache.jena.sparql.core.Transactional;

/**
* Txn variant for use with try-with-resources. Allows raising
* checked exceptions in an idiomatic way. Closing the TxnCtl
* instance will by default abort the transaction unless it
* has been manually committed.
* <p>
*
* Usage example:
* <pre>
* public void myMethod() throws IOException {
* try (TxnCtl txn = TxnCtl.begin(dataset, TxnType.WRITE)) {
* // Do work
* // Must manually call commit on success.
* txn.commit();
* }
* }
* </per>
*
* @param txn The transactional.
* @param txnType The transaction type.
* @return An instance of AutoCloseable that commits the transaction on success.
*/
public class TxnCtl
implements AutoCloseable
{
private Transactional txn;
private boolean b;

private TxnCtl(Transactional txn, boolean b) {
super();
this.txn = txn;
this.b = b;
}

public static TxnCtl begin(Transactional txn, ReadWrite readWrite) {
return begin(txn, TxnType.convert(readWrite));
}

public static TxnCtl begin(Transactional txn, TxnType txnType) {
Objects.requireNonNull(txn);
Objects.requireNonNull(txnType);
boolean b = txn.isInTransaction();
if ( b )
TxnOp.compatibleWithPromote(txnType, txn);
else
txn.begin(txnType);
return new TxnCtl(txn, b);
}

public void commit() {
if ( txn.isInTransaction() ) {

// May have been explicit commit or abort.
txn.commit();
}
}

@Override
public void close() {
if ( !b ) {
if ( txn.isInTransaction() )
// May have been explicit commit or abort.
txn.abort();
txn.end();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ private static void prepareSpatialExtension(Dataset dataset, ArgsConfig argsConf
if (!isEmpty) {
if (argsConfig.getSpatialIndexFile() != null) {
File spatialIndexFile = argsConfig.getSpatialIndexFile();
GeoSPARQLConfig.setupSpatialIndex(dataset, spatialIndexFile);
GeoSPARQLConfig.setupSpatialIndex(dataset, spatialIndexFile.toPath());
} else if (argsConfig.isTDBFileSetup()) {
File spatialIndexFile = new File(argsConfig.getTdbFile(), SPATIAL_INDEX_FILE);
GeoSPARQLConfig.setupSpatialIndex(dataset, spatialIndexFile);
GeoSPARQLConfig.setupSpatialIndex(dataset, spatialIndexFile.toPath());
} else {
GeoSPARQLConfig.setupSpatialIndex(dataset);
}
Expand Down
86 changes: 86 additions & 0 deletions jena-geosparql/deptree.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< org.apache.jena:jena-geosparql >-------------------
[INFO] Building Apache Jena - GeoSPARQL Engine 5.4.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.7.1:tree (default-cli) @ jena-geosparql ---
[INFO] org.apache.jena:jena-geosparql:jar:5.4.0-SNAPSHOT
[INFO] +- io.github.galbiston:expiring-map:jar:1.0.2:compile
[INFO] | \- org.slf4j:slf4j-api:jar:2.0.16:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] +- org.apache.jena:jena-arq:jar:5.4.0-SNAPSHOT:compile
[INFO] | +- org.apache.jena:jena-core:jar:5.4.0-SNAPSHOT:compile
[INFO] | | +- org.apache.jena:jena-base:jar:5.4.0-SNAPSHOT:compile
[INFO] | | | +- org.apache.commons:commons-csv:jar:1.13.0:compile
[INFO] | | | +- commons-io:commons-io:jar:2.18.0:compile
[INFO] | | | +- commons-codec:commons-codec:jar:1.18.0:compile
[INFO] | | | +- org.apache.commons:commons-compress:jar:1.27.1:compile
[INFO] | | | \- com.github.andrewoma.dexx:collection:jar:0.7:compile
[INFO] | | +- org.apache.jena:jena-iri3986:jar:5.4.0-SNAPSHOT:compile
[INFO] | | +- org.apache.jena:jena-iri:jar:5.4.0-SNAPSHOT:compile
[INFO] | | \- org.roaringbitmap:RoaringBitmap:jar:1.3.0:compile
[INFO] | +- com.google.code.gson:gson:jar:2.12.1:compile
[INFO] | | \- com.google.errorprone:error_prone_annotations:jar:2.36.0:compile
[INFO] | +- org.slf4j:jcl-over-slf4j:jar:2.0.16:compile
[INFO] | +- com.apicatalog:titanium-json-ld:jar:1.5.0:compile
[INFO] | +- org.glassfish:jakarta.json:jar:2.0.1:compile
[INFO] | +- com.google.protobuf:protobuf-java:jar:4.29.3:compile
[INFO] | +- org.apache.thrift:libthrift:jar:0.21.0:compile
[INFO] | \- org.apache.commons:commons-lang3:jar:3.17.0:compile
[INFO] +- org.apache.sis.core:sis-referencing:jar:1.4:compile
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.2:compile
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:2.1.3:compile
[INFO] | \- org.apache.sis.core:sis-metadata:jar:1.4:compile
[INFO] | \- org.apache.sis.core:sis-utility:jar:1.4:compile
[INFO] | +- org.opengis:geoapi:jar:3.0.2:compile
[INFO] | \- javax.measure:unit-api:jar:2.1.3:compile
[INFO] +- org.slf4j:jul-to-slf4j:jar:2.0.16:compile
[INFO] +- org.locationtech.jts:jts-core:jar:1.20.0:compile
[INFO] +- org.locationtech.jts.io:jts-io-common:jar:1.20.0:compile
[INFO] | \- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO] +- org.jdom:jdom2:jar:2.0.6.1:compile
[INFO] +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] +- org.apache.sedona:sedona-common:jar:1.6.0:compile
[INFO] | +- org.apache.commons:commons-math3:jar:3.6.1:compile
[INFO] | +- org.wololo:jts2geojson:jar:0.16.1:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.2:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-core:jar:2.12.2:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.2:compile
[INFO] | +- org.locationtech.spatial4j:spatial4j:jar:0.8:compile
[INFO] | +- com.google.geometry:s2-geometry:jar:2.0.0:compile
[INFO] | | \- com.google.guava:guava:jar:33.4.0-jre:compile
[INFO] | | +- com.google.guava:failureaccess:jar:1.0.2:compile
[INFO] | | +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] | | \- com.google.j2objc:j2objc-annotations:jar:3.0.0:compile
[INFO] | +- com.uber:h3:jar:4.1.1:compile
[INFO] | +- net.sf.geographiclib:GeographicLib-Java:jar:1.52:compile
[INFO] | \- com.github.ben-manes.caffeine:caffeine:jar:3.2.0:compile
[INFO] | \- org.jspecify:jspecify:jar:1.0.0:compile
[INFO] +- com.esotericsoftware:kryo:jar:4.0.2:compile
[INFO] | +- com.esotericsoftware:reflectasm:jar:1.11.3:compile
[INFO] | +- com.esotericsoftware:minlog:jar:1.3.0:compile
[INFO] | \- org.objenesis:objenesis:jar:2.5.1:compile
[INFO] +- org.ow2.asm:asm:jar:8.0.1:compile
[INFO] +- org.apache.sis.non-free:sis-embedded-data:jar:1.4:test
[INFO] | +- org.apache.derby:derby:jar:10.15.2.0:test
[INFO] | | \- org.apache.derby:derbyshared:jar:10.15.2.0:test
[INFO] | \- org.apache.derby:derbytools:jar:10.15.2.0:test
[INFO] +- org.junit.vintage:junit-vintage-engine:jar:5.11.4:test
[INFO] | +- org.junit.platform:junit-platform-engine:jar:1.11.4:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] | | \- org.junit.platform:junit-platform-commons:jar:1.11.4:test
[INFO] | +- junit:junit:jar:4.13.2:test
[INFO] | | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] \- org.apache.logging.log4j:log4j-slf4j2-impl:jar:2.24.3:test
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.24.3:test (optional)
[INFO] \- org.apache.logging.log4j:log4j-core:jar:2.24.3:test (optional)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.634 s
[INFO] Finished at: 2025-02-26T13:11:11+01:00
[INFO] ------------------------------------------------------------------------
114 changes: 99 additions & 15 deletions jena-geosparql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@

<dependencies>

<dependency>
<groupId>io.github.galbiston</groupId>
<artifactId>expiring-map</artifactId>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
Expand All @@ -44,18 +54,6 @@
<groupId>org.apache.sis.core</groupId>
<artifactId>sis-referencing</artifactId>
</dependency>

<!-- Evntually this wil be:
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
-->

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -82,6 +80,90 @@
<artifactId>commons-collections4</artifactId>
</dependency>

<!-- Kryo serialization via Apache Sedona -->

<!--
<dependency>
<groupId>org.apache.sedona</groupId>
<artifactId>sedona-spark-common-3.5_2.13</artifactId>
<version>1.6.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.12</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minicluster</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.geotools</groupId>
<artifactId>gt-geotiff</artifactId>
</exclusion>
<exclusion>
<groupId>org.geotools</groupId>
<artifactId>gt-coverage</artifactId>
</exclusion>
</exclusions>
</dependency>
-->

<dependency>
<groupId>org.apache.sedona</groupId>
<artifactId>sedona-common</artifactId>
<version>1.6.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.12</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minicluster</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.geotools</groupId>
<artifactId>gt-geotiff</artifactId>
</exclusion>
<exclusion>
<groupId>org.geotools</groupId>
<artifactId>gt-coverage</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- H3Utils only exists in newer sedona-common versions -->
<!--
<dependency>
<groupId>org.apache.sedona</groupId>
<artifactId>sedona-common</artifactId>
<version>1.6.0</version>
</dependency>
-->

<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>4.0.2</version>
</dependency>

<!-- Resolve conflicts between jenax/tika/nashorn/hadoop/kryo-->
<!--
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>8.0.1</version>
</dependency>
-->

<!-- Non-free; testing only -->
<dependency>
<groupId>org.apache.sis.non-free</groupId>
Expand All @@ -102,6 +184,8 @@
<scope>test</scope>
</dependency>



</dependencies>

<build>
Expand Down Expand Up @@ -133,11 +217,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<executions>
<execution>
<id>attach-sources-test</id>
<id>attach-sources-test</id>
<goals>
<goal>test-jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void init() {
if ( initialized )
return ;
synchronized (initLock) {
if ( initialized ) {
if ( initialized || System.getProperty("jena.geosparql.skip", "false").equalsIgnoreCase("true") ) {
JenaSystem.logLifecycle("InitGeoSPARQL - skip") ;
return ;
}
Expand Down
Loading

0 comments on commit 0829aa5

Please sign in to comment.