Skip to content

Rework tag translator #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0668ea2
replace Connection with DataSource in OSHDBH2/JDBC
rtroilo Oct 12, 2022
7e06523
fix complaining javadoc, add hasTag method to OSHDBTags
rtroilo Oct 17, 2022
ff52c34
extract TagTranslator to interface
rtroilo Oct 17, 2022
551905f
rename oshdb->osm method to lookup
rtroilo Oct 17, 2022
adf44c5
change owner ship of tagtranslator to oshdbdatabase, use datasource i…
rtroilo Oct 17, 2022
55d471f
fix fail build
rtroilo Oct 17, 2022
6390ca8
rework of tagtranslater, jdbc and cached
rtroilo Oct 17, 2022
88c38a7
fix broken javadoc
rtroilo Oct 18, 2022
b509437
cache keys in jdbctagtranslator
rtroilo Nov 3, 2022
9a4abd3
#470: make disposal of connection pool null-safe
mmerdes Nov 3, 2022
bf2ca58
#470: simplify method implementation
mmerdes Nov 3, 2022
31c2bb4
#470: refactor to smaller methods
mmerdes Nov 3, 2022
da15d5d
#470: refactor anonymous implementation to inner class
mmerdes Nov 3, 2022
912fd41
#470: remove redundant exception
mmerdes Nov 3, 2022
fa4e90c
#470: rename all test names to postfix-convention
mmerdes Nov 3, 2022
11d2cb4
#470: rename all test names to postfix-convention
mmerdes Nov 3, 2022
382d316
#470: fix misleading method name
mmerdes Nov 3, 2022
390ecff
#470: improve method implementation
mmerdes Nov 3, 2022
2265db8
#470: remove obsolete imports
mmerdes Nov 4, 2022
66cc448
#470: create tag-translator eagerly
mmerdes Nov 4, 2022
ae31ced
#470: cleanup: introduce static imports, remove redundant throws-clauses
mmerdes Nov 4, 2022
e61994f
#470: do not store keytables datasource anymore
mmerdes Nov 4, 2022
b4a1276
#470: use datasource instead of OSHDBDatabase
mmerdes Nov 4, 2022
c710f8d
#470: simplify nullability handling with Optional
mmerdes Nov 9, 2022
5f8d2d4
#470: specify pooling requirements for constructor argument Datasource
mmerdes Nov 9, 2022
4ba9380
#470: cleanup naming and imports
mmerdes Nov 9, 2022
f275a7e
#470: remove redundant join and cleanup whitespace in sql
mmerdes Nov 9, 2022
5c18dac
#470: cleanup formatting
mmerdes Nov 9, 2022
ff2d1c6
#470: extract abstract superclass for tag translator tests
mmerdes Nov 9, 2022
fe05611
#470: add test subclass to validate cached tag translator
mmerdes Nov 9, 2022
95aba03
#470: fix various warnings
mmerdes Nov 9, 2022
a4e9b5b
#470: fixe resource leak and copy-constructor issues
mmerdes Nov 9, 2022
4c19d20
Update CHANGELOG.md
rtroilo Nov 9, 2022
dae2996
Update CHANGELOG.md
rtroilo Nov 9, 2022
e6a6517
Merge branch 'master' into rework_tag-translator
joker234 Nov 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changelog
* remove Comparable interface from OSMEntity ([#449])
* remove deprecated filter methods `osmType`, `osmTag` and `osmEntityFlter` (which were replaced by [OSHDB `filter`s](https://github.com/GIScience/oshdb/blob/0.7/documentation/manual/filters.md#oshdb-filter)) ([#451])
* `OSMType.toString` returns lower-case name. ([#459])
* rework of handling separate keytables, see [#470] ([#470])

### new features

Expand Down Expand Up @@ -48,7 +49,7 @@ Changelog
[#454]: https://github.com/GIScience/oshdb/pull/454
[#459]: https://github.com/GIScience/oshdb/pull/459
[#467]: https://github.com/GIScience/oshdb/pull/467

[#470]: https://github.com/GIScience/oshdb/pull/470


## 0.7.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.sql.DataSource;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.lang.IgniteRunnable;
Expand All @@ -18,6 +19,8 @@
import org.heigit.ohsome.oshdb.util.exceptions.OSHDBException;
import org.heigit.ohsome.oshdb.util.exceptions.OSHDBTableNotFoundException;
import org.heigit.ohsome.oshdb.util.mappable.OSHDBMapReducible;
import org.heigit.ohsome.oshdb.util.tagtranslator.JdbcTagTranslator;
import org.heigit.ohsome.oshdb.util.tagtranslator.TagTranslator;

/**
* OSHDB database backend connector to a Ignite system.
Expand All @@ -40,6 +43,7 @@ public enum ComputeMode {
}

private final Ignite ignite;
private final TagTranslator tagTranslator;
private final boolean owner;
private ComputeMode computeMode = ComputeMode.LOCAL_PEEK;

Expand All @@ -50,8 +54,8 @@ public enum ComputeMode {
*
* @throws OSHDBException if cluster state is not active.
*/
public OSHDBIgnite() {
this(new File("ignite-config.xml"));
public OSHDBIgnite(DataSource keytables) {
this(new File("ignite-config.xml"), keytables);
}

/**
Expand All @@ -60,8 +64,8 @@ public OSHDBIgnite() {
* @param ignite Ignite instance to use.
* @throws OSHDBException if cluster state is not active.
*/
public OSHDBIgnite(Ignite ignite) {
this(ignite, false);
public OSHDBIgnite(Ignite ignite, DataSource keytables) {
this(ignite, false, keytables);
}

/**
Expand All @@ -70,8 +74,8 @@ public OSHDBIgnite(Ignite ignite) {
* @param igniteConfigFilePath ignite configuration file
* @throws OSHDBException if cluster state is not active.
*/
public OSHDBIgnite(String igniteConfigFilePath) {
this(new File(igniteConfigFilePath));
public OSHDBIgnite(String igniteConfigFilePath, DataSource keytables) {
this(new File(igniteConfigFilePath), keytables);
}

/**
Expand All @@ -80,13 +84,15 @@ public OSHDBIgnite(String igniteConfigFilePath) {
* @param igniteConfig ignite configuration file
* @throws OSHDBException if cluster state is not active.
*/
public OSHDBIgnite(File igniteConfig) {
this(startClient(igniteConfig), true);
public OSHDBIgnite(File igniteConfig, DataSource keytables) {
this(startClient(igniteConfig), true, keytables);
}

private OSHDBIgnite(Ignite ignite, boolean owner) {
public OSHDBIgnite(Ignite ignite, boolean owner, DataSource keytables) {
this.ignite = ignite;
this.owner = owner;
this.tagTranslator = new JdbcTagTranslator(keytables);

checkStateActive();
}

Expand All @@ -102,6 +108,11 @@ private void checkStateActive() {
}
}

@Override
public TagTranslator getTagTranslator() {
return tagTranslator;
}

@Override
public OSHDBIgnite prefix(String prefix) {
return (OSHDBIgnite) super.prefix(prefix);
Expand Down Expand Up @@ -196,10 +207,7 @@ public OSHDBIgnite onClose(IgniteRunnable action) {
* @return the currently set onClose callback
*/
public Optional<IgniteRunnable> onClose() {
if (this.onCloseCallback == null) {
return Optional.empty();
} else {
return Optional.of(this.onCloseCallback);
}
return Optional.ofNullable(this.onCloseCallback);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.api.db.OSHDBIgnite.ComputeMode.AFFINITY_CALL;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Set;
import java.util.stream.Collectors;
import org.heigit.ohsome.oshdb.api.db.OSHDBIgnite;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps;
import org.junit.jupiter.api.Test;

Expand All @@ -13,14 +13,14 @@
*
* <p>Runs the tests using the "affinity call" Ignite backend.</p>
*/
class TestMapReduceOSHDBIgniteAffinityCall extends TestMapReduceOSHDBIgnite {
class MapReduceOSHDBIgniteAffinityCallTest extends MapReduceOSHDBIgniteTest {
/**
* Creates the test runner using the ignite affinitycall backend.
*
* @throws Exception if something goes wrong
*/
TestMapReduceOSHDBIgniteAffinityCall() throws Exception {
super(new OSHDBIgnite(ignite).computeMode(OSHDBIgnite.ComputeMode.AFFINITY_CALL));
MapReduceOSHDBIgniteAffinityCallTest() throws Exception {
super(oshdb -> oshdb.computeMode(AFFINITY_CALL));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.heigit.ohsome.oshdb.api.tests;

import org.heigit.ohsome.oshdb.api.db.OSHDBIgnite;
import static org.heigit.ohsome.oshdb.api.db.OSHDBIgnite.ComputeMode.LOCAL_PEEK;

/**
* {@inheritDoc}
*
* <p>Runs the tests using the "local peek" Ignite backend.</p>
*/
class TestMapReduceOSHDBIgniteLocalPeek extends TestMapReduceOSHDBIgnite {
class MapReduceOSHDBIgniteLocalPeekTest extends MapReduceOSHDBIgniteTest {
/**
* Creates the test runner using the ignite localpeak backend.
*
* @throws Exception if something goes wrong
*/
TestMapReduceOSHDBIgniteLocalPeek() throws Exception {
super(new OSHDBIgnite(ignite).computeMode(OSHDBIgnite.ComputeMode.LOCAL_PEEK));
MapReduceOSHDBIgniteLocalPeekTest() throws Exception {
super(oshdb -> oshdb.computeMode(LOCAL_PEEK));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,50 @@

import static org.junit.jupiter.api.Assertions.assertThrows;

import org.heigit.ohsome.oshdb.api.db.OSHDBIgnite;
import org.heigit.ohsome.oshdb.util.exceptions.OSHDBTableNotFoundException;
import org.junit.jupiter.api.Test;

/**
* Tests for proper error messages is caches are not pnt on ignite.
*/
class TestMapReduceOSHDBIgniteMissingCache extends TestMapReduceOSHDBIgnite {
class MapReduceOSHDBIgniteMissingCacheTest extends MapReduceOSHDBIgniteTest {
/**
* Creates the test runner using an Ignite backend.
*
* @throws Exception if something goes wrong
*/
TestMapReduceOSHDBIgniteMissingCache() throws Exception {
super(new OSHDBIgnite(ignite));
MapReduceOSHDBIgniteMissingCacheTest() throws Exception {
super(oshdb -> {});
this.oshdb.prefix("<test caches not present>");
}

@Override
@Test()
void testOSMContributionView() throws Exception {
void testOSMContributionView() {
assertThrows(OSHDBTableNotFoundException.class, super::testOSMContributionView);
}

@Override
@Test()
void testOSMEntitySnapshotView() throws Exception {
void testOSMEntitySnapshotView() {
assertThrows(OSHDBTableNotFoundException.class, super::testOSMEntitySnapshotView);
}

@Override
@Test()
void testOSMContributionViewStream() throws Exception {
void testOSMContributionViewStream() {
assertThrows(OSHDBTableNotFoundException.class, super::testOSMContributionViewStream);
}

@Override
@Test()
void testOSMEntitySnapshotViewStream() throws Exception {
void testOSMEntitySnapshotViewStream() {
assertThrows(OSHDBTableNotFoundException.class, super::testOSMEntitySnapshotViewStream);
}

@Override
@Test()
void testTimeoutMapReduce() throws Exception {
void testTimeoutMapReduce() {
assertThrows(OSHDBTableNotFoundException.class, this::timeoutMapReduce);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.api.db.OSHDBIgnite.ComputeMode.SCAN_QUERY;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.heigit.ohsome.oshdb.api.db.OSHDBIgnite;
import org.junit.jupiter.api.Test;

/**
* {@inheritDoc}
*
* <p>Runs the tests using the "scan query" Ignite backend.</p>
*/
class TestMapReduceOSHDBIgniteScanQuery extends TestMapReduceOSHDBIgnite {
class MapReduceOSHDBIgniteScanQueryTest extends MapReduceOSHDBIgniteTest {
/**
* Creates the test runner using the ignite scanquery backend.
*
* @throws Exception if something goes wrong
*/
TestMapReduceOSHDBIgniteScanQuery() throws Exception {
super(new OSHDBIgnite(ignite).computeMode(OSHDBIgnite.ComputeMode.SCAN_QUERY));
MapReduceOSHDBIgniteScanQueryTest() throws Exception {
super(oshdb -> oshdb.computeMode(SCAN_QUERY));
}

@Override
@Test
void testTimeoutStream() throws Exception {
void testTimeoutStream() {
// ignore this test -> scanquery backend currently doesn't support timeouts for stream()
assertTrue(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.api.db.H2Support.pathToUrl;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.function.Consumer;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteDataStreamer;
Expand All @@ -21,13 +24,14 @@
import org.apache.ignite.logger.slf4j.Slf4jLogger;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
import org.h2.jdbcx.JdbcConnectionPool;
import org.heigit.ohsome.oshdb.api.db.OSHDBDatabase;
import org.heigit.ohsome.oshdb.api.db.OSHDBIgnite;
import org.heigit.ohsome.oshdb.grid.GridOSHNodes;
import org.heigit.ohsome.oshdb.util.CellId;
import org.heigit.ohsome.oshdb.util.TableNames;

abstract class TestMapReduceOSHDBIgnite extends TestMapReduce {
abstract class MapReduceOSHDBIgniteTest extends MapReduceTest {
static final Ignite ignite;

static {
Expand All @@ -46,16 +50,8 @@ abstract class TestMapReduceOSHDBIgnite extends TestMapReduce {
ignite = Ignition.start(cfg);
}

TestMapReduceOSHDBIgnite(OSHDBIgnite oshdb) throws Exception {
super(oshdb);

private static OSHDBDatabase initOshdb(Consumer<OSHDBIgnite> computeMode) {
final String prefix = "tests";
oshdb.prefix(prefix);

OSHDBH2 oshdbH2 = new OSHDBH2("../data/test-data");
this.keytables = oshdbH2;

Ignite ignite = ((OSHDBIgnite) this.oshdb).getIgnite();
ignite.cluster().state(ClusterState.ACTIVE);

CacheConfiguration<Long, GridOSHNodes> cacheCfg =
Expand All @@ -69,15 +65,19 @@ abstract class TestMapReduceOSHDBIgnite extends TestMapReduce {
ignite.getOrCreateCache(new CacheConfiguration<>(TableNames.T_WAYS.toString(prefix)));
ignite.getOrCreateCache(new CacheConfiguration<>(TableNames.T_RELATIONS.toString(prefix)));

JdbcConnectionPool oshdbH2 = JdbcConnectionPool.create(pathToUrl(Path.of("../data/test-data")), "sa",
"");

// load test data into ignite cache
try (IgniteDataStreamer<Long, GridOSHNodes> streamer = ignite.dataStreamer(cache.getName())) {
Connection h2Conn = oshdbH2.getConnection();
Statement h2Stmt = h2Conn.createStatement();
try (IgniteDataStreamer<Long, GridOSHNodes> streamer = ignite.dataStreamer(cache.getName());
Connection h2Conn = oshdbH2.getConnection();
Statement h2Stmt = h2Conn.createStatement();
) {

streamer.allowOverwrite(true);

try (final ResultSet rst =
h2Stmt.executeQuery("select level, id, data from " + TableNames.T_NODES.toString())) {
h2Stmt.executeQuery("select level, id, data from " + TableNames.T_NODES)) {
while (rst.next()) {
final int level = rst.getInt(1);
final long id = rst.getLong(2);
Expand All @@ -96,5 +96,14 @@ abstract class TestMapReduceOSHDBIgnite extends TestMapReduce {
}

ignite.cluster().state(ClusterState.ACTIVE_READ_ONLY);

var oshdb = new OSHDBIgnite(ignite, oshdbH2);
oshdb.prefix(prefix);
computeMode.accept(oshdb);
return oshdb;
}

MapReduceOSHDBIgniteTest(Consumer<OSHDBIgnite> computeMode) throws Exception {
super(initOshdb(computeMode));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.heigit.ohsome.oshdb.api.db;

import java.nio.file.Path;

public class H2Support {

private H2Support() {
}

public static String pathToUrl(Path path) {
var absolutePath = path.toAbsolutePath().toString();
absolutePath = absolutePath.replaceAll("\\.mv\\.db$", "");
return String.format("jdbc:h2:%s;ACCESS_MODE_DATA=r", absolutePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.heigit.ohsome.oshdb.api.mapreducer.MapReducer;
import org.heigit.ohsome.oshdb.util.exceptions.OSHDBTimeoutException;
import org.heigit.ohsome.oshdb.util.mappable.OSHDBMapReducible;
import org.heigit.ohsome.oshdb.util.tagtranslator.TagTranslator;

/**
* OSHDB database backend connector.
Expand All @@ -12,6 +13,8 @@ public abstract class OSHDBDatabase implements AutoCloseable {
private String prefix = "";
private Long timeout = null;

public abstract TagTranslator getTagTranslator();

/**
* Factory function that creates a mapReducer object of the appropriate data type class for this
* oshdb backend implemenation.
Expand Down
Loading