started writing a test for SPARQL join optimization
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/5f4d8f67 Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/5f4d8f67 Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/5f4d8f67 Branch: refs/heads/develop Commit: 5f4d8f67fb5a8adb5c628ea060e6a266b4ede2e9 Parents: 867f218 Author: Sebastian Schaffert <[email protected]> Authored: Wed Apr 24 17:02:51 2013 +0200 Committer: Sebastian Schaffert <[email protected]> Committed: Wed Apr 24 17:02:51 2013 +0200 ---------------------------------------------------------------------- .../marmotta/kiwi/sparql/sail/KiWiSparqlSail.java | 10 + .../kiwi/sparql/test/KiWiSparqlJoinTest.java | 158 +++++++++++++++ .../marmotta/kiwi/sparql/test/demo-data.foaf | 70 +++++++ 3 files changed, 238 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5f4d8f67/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSail.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSail.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSail.java index ad0328b..88a37ef 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSail.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSail.java @@ -43,6 +43,11 @@ public class KiWiSparqlSail extends NotifyingSailWrapper { } + /** + * Get the root sail in the wrapped sail stack + * @param sail + * @return + */ private KiWiStore getRootSail(Sail sail) { if(sail instanceof KiWiStore) { return (KiWiStore) sail; @@ -53,6 +58,11 @@ public class KiWiSparqlSail extends NotifyingSailWrapper { } } + /** + * Get the root connection in a wrapped sail connection stack + * @param connection + * @return + */ private KiWiSailConnection getRootConnection(SailConnection connection) { if(connection instanceof KiWiSailConnection) { return (KiWiSailConnection) connection; http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5f4d8f67/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java new file mode 100644 index 0000000..bead1d5 --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java @@ -0,0 +1,158 @@ +/* + * 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.marmotta.kiwi.sparql.test; + +import org.apache.marmotta.kiwi.persistence.KiWiDialect; +import org.apache.marmotta.kiwi.persistence.h2.H2Dialect; +import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect; +import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; +import org.apache.marmotta.kiwi.sail.KiWiStore; +import org.apache.marmotta.kiwi.sparql.sail.KiWiSparqlSail; +import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.openrdf.repository.Repository; +import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.sail.SailRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * Test the KiWi SPARQL Join optimization. + * + * <ul> + * <li>PostgreSQL: + * <ul> + * <li>postgresql.url, e.g. jdbc:postgresql://localhost:5433/kiwitest?prepareThreshold=3</li> + * <li>postgresql.user (default: lmf)</li> + * <li>postgresql.pass (default: lmf)</li> + * </ul> + * </li> + * <li>MySQL: + * <ul> + * <li>mysql.url, e.g. jdbc:mysql://localhost:3306/kiwitest?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull</li> + * <li>mysql.user (default: lmf)</li> + * <li>mysql.pass (default: lmf</li> + * </ul> + * </li> + * <li>H2: + * <ul> + * <li>h2.url, e.g. jdbc:h2:mem;MVCC=true;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=10</li> + * <li>h2.user (default: lmf)</li> + * <li>h2.pass (default: lmf</li> + * </ul> + * </li> + * </ul> + * @author Sebastian Schaffert ([email protected]) + */ +@RunWith(Parameterized.class) +public class KiWiSparqlJoinTest { + + /** + * Return database configurations if the appropriate parameters have been set. + * + * @return an array (database name, url, user, password) + */ + @Parameterized.Parameters(name="Database Test {index}: {0} at {1}") + public static Iterable<Object[]> databases() { + String[] databases = {"H2", "PostgreSQL", "MySQL"}; + + List<Object[]> result = new ArrayList<Object[]>(databases.length); + for(String database : databases) { + if(System.getProperty(database.toLowerCase()+".url") != null) { + result.add(new Object[] { + database, + System.getProperty(database.toLowerCase()+".url"), + System.getProperty(database.toLowerCase()+".user","lmf"), + System.getProperty(database.toLowerCase()+".pass","lmf") + }); + } + } + return result; + } + + + private KiWiDialect dialect; + + private String jdbcUrl; + + private String jdbcUser; + + private String jdbcPass; + + private KiWiStore store; + + private KiWiSparqlSail ssail; + + private Repository repository; + + public KiWiSparqlJoinTest(String database, String jdbcUrl, String jdbcUser, String jdbcPass) { + this.jdbcPass = jdbcPass; + this.jdbcUrl = jdbcUrl; + this.jdbcUser = jdbcUser; + + if("H2".equals(database)) { + this.dialect = new H2Dialect(); + } else if("MySQL".equals(database)) { + this.dialect = new MySQLDialect(); + } else if("PostgreSQL".equals(database)) { + this.dialect = new PostgreSQLDialect(); + } + + DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, dialect); + } + + + @Before + public void initDatabase() throws RepositoryException { + store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred"); + ssail = new KiWiSparqlSail(store); + repository = new SailRepository(ssail); + repository.initialize(); + } + + @After + public void dropDatabase() throws RepositoryException, SQLException { + store.getPersistence().dropDatabase(); + repository.shutDown(); + } + + final Logger logger = + LoggerFactory.getLogger(this.getClass()); + + @Rule + public TestWatcher watchman = new TestWatcher() { + /** + * Invoked when a test is about to start + */ + @Override + protected void starting(Description description) { + logger.info("{} being run...", description.getMethodName()); + } + }; + +} http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5f4d8f67/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/demo-data.foaf ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/demo-data.foaf b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/demo-data.foaf new file mode 100644 index 0000000..c2d786b --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/demo-data.foaf @@ -0,0 +1,70 @@ +<!-- + ~ 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. + --> + +<rdf:RDF + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:foaf="http://xmlns.com/foaf/0.1/" + xmlns:dc="http://purl.org/dc/elements/1.1/"> + + <foaf:Person rdf:about="http://localhost:8080/LMF/resource/hans_meier" xmlns:foaf="http://xmlns.com/foaf/0.1/"> + <foaf:name>Hans Meier</foaf:name> + <dc:description>Hans Meier is a software engineer living in Salzburg</dc:description> + <foaf:interest rdf:resource="http://rdf.freebase.com/ns/en.software_engineering"/> + <foaf:interest rdf:resource="http://rdf.freebase.com/ns/en.linux"/> + <foaf:interest rdf:resource="http://dbpedia.org/resource/Java" /> + <foaf:interest rdf:resource="http://dbpedia.org/resource/Climbing"/> + <foaf:based_near rdf:resource="http://sws.geonames.org/2766824/"/> + <foaf:depiction rdf:resource="http://localhost:8080/LMF/resource/hans_meier.jpg"/> + + <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/sepp_huber" /> + <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/anna_schmidt"/> + + <foaf:account> + <foaf:OnlineAccount> + <foaf:accountName>Example</foaf:accountName> + <foaf:accountServiceHomepage>http://www.example.com</foaf:accountServiceHomepage> + </foaf:OnlineAccount> + </foaf:account> + </foaf:Person> + + <foaf:Person rdf:about="http://localhost:8080/LMF/resource/sepp_huber" xmlns:foaf="http://xmlns.com/foaf/0.1/"> + <foaf:name>Sepp Huber</foaf:name> + <dc:description>Sepp Huber is an alpinist living in Traunstein. He is a good climber, but not as famous as his cousin Alexander Huber.</dc:description> + <foaf:interest rdf:resource="http://dbpedia.org/resource/Mountaineering"/> + <foaf:interest rdf:resource="http://dbpedia.org/resource/Climbing"/> + <foaf:interest rdf:resource="http://localhost:8080/LMF/resource/Chess" /> + <foaf:based_near rdf:resource="http://dbpedia.org/resource/Traunstein"/> + + <foaf:knows rdf:resource="http://dbpedia.org/resource/Alexander_Huber" /> + <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/hans_meier" /> + </foaf:Person> + + <foaf:Person rdf:about="http://localhost:8080/LMF/resource/anna_schmidt" xmlns:foaf="http://xmlns.com/foaf/0.1/"> + <foaf:name>Anna Schmidt</foaf:name> + <dc:description>Anna Schmidt is working as PR manager for mountaineers coming from Garmisch-Partenkirchen. She likes mountaineering and is also a Linux enthusiast.</dc:description> + <foaf:interest rdf:resource="http://dbpedia.org/resource/Mountaineering"/> + <foaf:interest rdf:resource="http://dbpedia.org/resource/Linux"/> + <foaf:interest rdf:resource="http://localhost:8080/LMF/resource/Chess" /> + <foaf:based_near rdf:resource="http://dbpedia.org/resource/Garmisch-Partenkirchen"/> + <foaf:depiction rdf:resource="http://localhost:8080/LMF/resource/anna_schmidt.jpg"/> + + <foaf:knows rdf:resource="http://dbpedia.org/resource/Alexander_Huber" /> + <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/sepp_huber" /> + </foaf:Person> + + +</rdf:RDF>
