From dc77208299add0e8770e84b843c84ea6fde2e67d Mon Sep 17 00:00:00 2001 From: Brad Rushworth <67445484+brushworth@users.noreply.github.com> Date: Tue, 30 Jun 2020 13:57:49 +1000 Subject: [PATCH 1/3] RYA-534 Upgrade to RDF4J 3.2 and RYA-496 Upgrading to Accumulo 1.9.3 --- common/rya.provenance/pom.xml | 1 + .../rya/indexing/entity/model/Entity.java | 30 ++-- .../rya/indexing/entity/model/Property.java | 13 +- .../rya/indexing/entity/model/Type.java | 14 +- .../indexing/entity/model/TypedEntity.java | 20 ++- .../sail/config/RyaAccumuloSailConfig.java | 42 +++--- extras/kafka.connect/api/pom.xml | 1 + .../periodic.notification/twill.yarn/pom.xml | 2 +- extras/periodic.notification/twill/pom.xml | 7 +- .../api/conf/AccumuloMergeConfiguration.java | 2 +- .../export/api/conf/MergeConfiguration.java | 6 +- extras/rya.forwardchain/pom.xml | 3 +- .../app/query/StatementPatternIdManager.java | 25 ++-- extras/rya.prospector/pom.xml | 11 ++ extras/rya.reasoning/pom.xml | 9 +- .../queries/InMemoryQueryRepositoryTest.java | 39 +++--- .../client/command/RunQueryCommandIT.java | 27 ++-- .../kafka/KafkaRyaStreamsClientFactory.java | 22 ++- .../streams/querymanager/QueryManager.java | 65 +++++---- .../querymanager/QueryManagerDaemon.java | 35 +++-- .../querymanager/QueryManagerTest.java | 37 ++--- .../kafka/KafkaQueryChangeLogSourceIT.java | 44 +++--- .../kafka/LocalQueryExecutorIT.java | 18 +-- .../kafka/LocalQueryExecutorTest.java | 63 +++++---- .../mr/AccumuloHDFSFileInputFormat.java | 26 ++-- .../rya/accumulo/mr/RyaInputFormat.java | 25 +++- .../rya/accumulo/pig/AccumuloStorage.java | 31 ++-- pom.xml | 132 +++++++++++++----- sail/pom.xml | 1 + .../RdfCloudTripleStoreConnection.java | 9 +- 30 files changed, 437 insertions(+), 323 deletions(-) diff --git a/common/rya.provenance/pom.xml b/common/rya.provenance/pom.xml index 87c6e25d9..7096dba02 100644 --- a/common/rya.provenance/pom.xml +++ b/common/rya.provenance/pom.xml @@ -33,6 +33,7 @@ under the License. org.eclipse.rdf4j rdf4j-runtime + pom diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java index 6874a164a..5f0497820 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java @@ -18,7 +18,19 @@ */ package org.apache.rya.indexing.entity.model; -import static java.util.Objects.requireNonNull; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; +import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.log4j.Logger; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.indexing.entity.storage.EntityStorage; +import org.apache.rya.indexing.smarturi.SmartUriAdapter; +import org.apache.rya.indexing.smarturi.SmartUriException; +import org.eclipse.rdf4j.model.IRI; import java.util.ArrayList; import java.util.HashMap; @@ -28,21 +40,7 @@ import java.util.Objects; import java.util.Optional; -import org.apache.http.annotation.Immutable; -import org.apache.log4j.Logger; -import org.apache.rya.api.domain.RyaIRI; -import org.apache.rya.indexing.entity.storage.EntityStorage; -import org.apache.rya.indexing.smarturi.SmartUriAdapter; -import org.apache.rya.indexing.smarturi.SmartUriException; -import org.eclipse.rdf4j.model.IRI; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; - -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; +import static java.util.Objects.requireNonNull; /** * An {@link Entity} is a named concept that has at least one defined structure diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java index b44c52c09..0b9b77d58 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java @@ -18,16 +18,15 @@ */ package org.apache.rya.indexing.entity.model; -import static java.util.Objects.requireNonNull; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaType; import java.util.Objects; -import org.apache.http.annotation.Immutable; -import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; - -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * A value that has been set for an {@link TypedEntity}. diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java index a7c988b72..1a61812bf 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java @@ -18,18 +18,16 @@ */ package org.apache.rya.indexing.entity.model; -import static java.util.Objects.requireNonNull; - -import java.util.Objects; - -import org.apache.http.annotation.Immutable; +import com.google.common.collect.ImmutableSet; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import jdk.nashorn.internal.ir.annotations.Immutable; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.indexing.entity.storage.TypeStorage; -import com.google.common.collect.ImmutableSet; +import java.util.Objects; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * Defines the structure of an {@link TypedEntity}. diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java index 816e7fa51..fdce30dc2 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java @@ -18,23 +18,21 @@ */ package org.apache.rya.indexing.entity.model; -import static java.util.Objects.requireNonNull; +import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableMap; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; +import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaType; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; -import org.apache.http.annotation.Immutable; -import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; - -import com.google.common.collect.ImmutableCollection; -import com.google.common.collect.ImmutableMap; - -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; +import static java.util.Objects.requireNonNull; /** * A {@link TypedEntity} is a view of an {@link Entity} that has had a specific diff --git a/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaAccumuloSailConfig.java b/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaAccumuloSailConfig.java index 43af1fb81..37e9b226e 100644 --- a/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaAccumuloSailConfig.java +++ b/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaAccumuloSailConfig.java @@ -20,16 +20,16 @@ import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import org.eclipse.rdf4j.model.util.GraphUtil; -import org.eclipse.rdf4j.model.util.GraphUtilException; import org.eclipse.rdf4j.sail.config.AbstractSailImplConfig; import org.eclipse.rdf4j.sail.config.SailConfigException; +import java.util.Set; + /** * @deprecated Use {@link AccumuloRdfConfiguration} instead. */ @@ -117,9 +117,7 @@ public void validate() throws SailConfigException { public Resource export(final Model model) { final Resource implNode = super.export(model); - @SuppressWarnings("deprecation") - final - ValueFactory v = model.getValueFactory(); + final ValueFactory v = SimpleValueFactory.getInstance(); model.add(implNode, USER, v.createLiteral(user)); model.add(implNode, PASSWORD, v.createLiteral(password)); @@ -136,27 +134,27 @@ public void parse(final Model model, final Resource implNode) throws SailConfigE System.out.println("parsing"); try { - final Literal userLit = GraphUtil.getOptionalObjectLiteral(model, implNode, USER); - if (userLit != null) { - setUser(userLit.getLabel()); + final Set userLit = model.filter(implNode, USER, null).objects(); + if (userLit.size() == 1) { + setUser(userLit.iterator().next().stringValue()); } - final Literal pwdLit = GraphUtil.getOptionalObjectLiteral(model, implNode, PASSWORD); - if (pwdLit != null) { - setPassword(pwdLit.getLabel()); + final Set pwdLit = model.filter(implNode, PASSWORD, null).objects(); + if (pwdLit.size() == 1) { + setPassword(pwdLit.iterator().next().stringValue()); } - final Literal instLit = GraphUtil.getOptionalObjectLiteral(model, implNode, INSTANCE); - if (instLit != null) { - setInstance(instLit.getLabel()); + final Set instLit = model.filter(implNode, INSTANCE, null).objects(); + if (instLit.size() == 1) { + setInstance(instLit.iterator().next().stringValue()); } - final Literal zooLit = GraphUtil.getOptionalObjectLiteral(model, implNode, ZOOKEEPERS); - if (zooLit != null) { - setZookeepers(zooLit.getLabel()); + final Set zooLit = model.filter(implNode, ZOOKEEPERS, null).objects(); + if (zooLit.size() == 1) { + setZookeepers(zooLit.iterator().next().stringValue()); } - final Literal mockLit = GraphUtil.getOptionalObjectLiteral(model, implNode, IS_MOCK); - if (mockLit != null) { - setMock(Boolean.parseBoolean(mockLit.getLabel())); + final Set mockLit = model.filter(implNode, IS_MOCK, null).objects(); + if (mockLit.size() == 1) { + setMock(Boolean.parseBoolean(mockLit.iterator().next().stringValue())); } - } catch (final GraphUtilException e) { + } catch (final Exception e) { throw new SailConfigException(e.getMessage(), e); } } diff --git a/extras/kafka.connect/api/pom.xml b/extras/kafka.connect/api/pom.xml index fcc6a154e..df86d3943 100644 --- a/extras/kafka.connect/api/pom.xml +++ b/extras/kafka.connect/api/pom.xml @@ -68,6 +68,7 @@ org.eclipse.rdf4j rdf4j-runtime + pom org.slf4j diff --git a/extras/periodic.notification/twill.yarn/pom.xml b/extras/periodic.notification/twill.yarn/pom.xml index 00cb1905f..46bee18ec 100644 --- a/extras/periodic.notification/twill.yarn/pom.xml +++ b/extras/periodic.notification/twill.yarn/pom.xml @@ -43,7 +43,7 @@ org.apache.twill twill-yarn - 0.12.0 + ${twill.version} org.apache.rya diff --git a/extras/periodic.notification/twill/pom.xml b/extras/periodic.notification/twill/pom.xml index a4e8f7a9e..8f6d969af 100644 --- a/extras/periodic.notification/twill/pom.xml +++ b/extras/periodic.notification/twill/pom.xml @@ -77,12 +77,12 @@ com.google.guava - guava + guava org.apache.twill twill-api - 0.12.0 + ${twill.version} @@ -165,6 +165,9 @@ commons-logging:commons-logging org.slf4j:slf4j-log4j12 log4j:log4j + + + org.locationtech.spatial4j:spatial4j diff --git a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java index a35d5aab7..1a351147f 100644 --- a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java +++ b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java @@ -18,7 +18,7 @@ */ package org.apache.rya.export.api.conf; -import org.apache.http.annotation.Immutable; +import jdk.nashorn.internal.ir.annotations.Immutable; import org.apache.rya.export.InstanceType; /** diff --git a/extras/rya.export/export.api/src/main/java/org/apache/rya/export/api/conf/MergeConfiguration.java b/extras/rya.export/export.api/src/main/java/org/apache/rya/export/api/conf/MergeConfiguration.java index 96f7ed678..329589bd4 100644 --- a/extras/rya.export/export.api/src/main/java/org/apache/rya/export/api/conf/MergeConfiguration.java +++ b/extras/rya.export/export.api/src/main/java/org/apache/rya/export/api/conf/MergeConfiguration.java @@ -18,12 +18,12 @@ */ package org.apache.rya.export.api.conf; -import static com.google.common.base.Preconditions.checkNotNull; - -import org.apache.http.annotation.Immutable; +import jdk.nashorn.internal.ir.annotations.Immutable; import org.apache.rya.export.DBType; import org.apache.rya.export.MergePolicy; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Immutable configuration object to allow the MergeTool to connect to the parent and child * databases for data merging. diff --git a/extras/rya.forwardchain/pom.xml b/extras/rya.forwardchain/pom.xml index b5c275a39..4ade411f7 100644 --- a/extras/rya.forwardchain/pom.xml +++ b/extras/rya.forwardchain/pom.xml @@ -33,7 +33,8 @@ under the License. org.eclipse.rdf4j rdf4j-runtime - + pom + org.apache.rya rya.api diff --git a/extras/rya.pcj.fluo/pcj.fluo.app/src/main/java/org/apache/rya/indexing/pcj/fluo/app/query/StatementPatternIdManager.java b/extras/rya.pcj.fluo/pcj.fluo.app/src/main/java/org/apache/rya/indexing/pcj/fluo/app/query/StatementPatternIdManager.java index ee4c053bb..9a8505e21 100644 --- a/extras/rya.pcj.fluo/pcj.fluo.app/src/main/java/org/apache/rya/indexing/pcj/fluo/app/query/StatementPatternIdManager.java +++ b/extras/rya.pcj.fluo/pcj.fluo.app/src/main/java/org/apache/rya/indexing/pcj/fluo/app/query/StatementPatternIdManager.java @@ -18,23 +18,22 @@ */ package org.apache.rya.indexing.pcj.fluo.app.query; +import com.google.common.base.Joiner; +import com.google.common.base.Optional; +import com.google.common.collect.Sets; +import com.google.common.hash.Hashing; +import org.apache.fluo.api.client.TransactionBase; +import org.apache.fluo.api.data.Bytes; + +import java.util.HashSet; +import java.util.Set; + import static com.google.common.base.Preconditions.checkNotNull; import static org.apache.rya.indexing.pcj.fluo.app.IncrementalUpdateConstants.STATEMENT_PATTERN_ID; import static org.apache.rya.indexing.pcj.fluo.app.IncrementalUpdateConstants.VAR_DELIM; import static org.apache.rya.indexing.pcj.fluo.app.query.FluoQueryColumns.STATEMENT_PATTERN_IDS; import static org.apache.rya.indexing.pcj.fluo.app.query.FluoQueryColumns.STATEMENT_PATTERN_IDS_HASH; -import java.util.HashSet; -import java.util.Set; - -import org.apache.fluo.api.client.TransactionBase; -import org.apache.fluo.api.data.Bytes; - -import com.google.common.base.Joiner; -import com.google.common.base.Optional; -import com.google.common.collect.Sets; -import com.google.common.hash.Hashing; - /** * Utility class for updating and removing StatementPattern nodeIds in the Fluo table. All StatementPattern nodeIds are * stored in a single set under a single entry in the Fluo table. This is to eliminate the need for a scan to find all @@ -62,7 +61,7 @@ public static void addStatementPatternIds(TransactionBase tx, Set ids) { } String idString = builder.append(Joiner.on(VAR_DELIM).join(ids)).toString(); tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS, Bytes.of(idString)); - tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS_HASH, Bytes.of(Hashing.sha256().hashString(idString).toString())); + tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS_HASH, Bytes.of(Hashing.sha256().hashUnencodedChars(idString).toString())); } /** @@ -84,7 +83,7 @@ public static void removeStatementPatternIds(TransactionBase tx, Set ids storedIds.removeAll(ids); String idString = Joiner.on(VAR_DELIM).join(ids); tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS, Bytes.of(idString)); - tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS_HASH, Bytes.of(Hashing.sha256().hashString(idString).toString())); + tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS_HASH, Bytes.of(Hashing.sha256().hashUnencodedChars(idString).toString())); } } diff --git a/extras/rya.prospector/pom.xml b/extras/rya.prospector/pom.xml index 5ec2f2e53..8ed6f8de6 100644 --- a/extras/rya.prospector/pom.xml +++ b/extras/rya.prospector/pom.xml @@ -55,6 +55,17 @@ under the License. hadoop2 test + + org.powermock + powermock-module-junit4 + test + + + org.powermock + powermock-api-mockito2 + test + + diff --git a/extras/rya.reasoning/pom.xml b/extras/rya.reasoning/pom.xml index 21efb2000..9ad3d7b32 100644 --- a/extras/rya.reasoning/pom.xml +++ b/extras/rya.reasoning/pom.xml @@ -58,7 +58,7 @@ under the License. org.apache.accumulo accumulo-minicluster - compile + provided @@ -77,6 +77,7 @@ under the License. org.eclipse.rdf4j rdf4j-runtime + pom @@ -84,12 +85,18 @@ under the License. mrunit hadoop2 test + org.powermock powermock-module-junit4 test + + org.powermock + powermock-api-mockito2 + test + diff --git a/extras/rya.streams/api/src/test/java/org/apache/rya/streams/api/queries/InMemoryQueryRepositoryTest.java b/extras/rya.streams/api/src/test/java/org/apache/rya/streams/api/queries/InMemoryQueryRepositoryTest.java index 5a16e799a..daba34e32 100644 --- a/extras/rya.streams/api/src/test/java/org/apache/rya/streams/api/queries/InMemoryQueryRepositoryTest.java +++ b/extras/rya.streams/api/src/test/java/org/apache/rya/streams/api/queries/InMemoryQueryRepositoryTest.java @@ -18,11 +18,11 @@ */ package org.apache.rya.streams.api.queries; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import com.google.common.collect.Sets; +import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import org.apache.rya.streams.api.entity.StreamsQuery; +import org.apache.rya.streams.api.queries.QueryChangeLog.QueryChangeLogException; +import org.junit.Test; import java.util.HashSet; import java.util.Optional; @@ -31,12 +31,11 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.apache.rya.streams.api.entity.StreamsQuery; -import org.apache.rya.streams.api.queries.QueryChangeLog.QueryChangeLogException; -import org.junit.Test; - -import com.google.common.collect.Sets; -import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Unit tests the methods of {@link InMemoryQueryRepository}. @@ -83,7 +82,7 @@ public void initializedWithPopulatedChangeLog() throws Exception { final QueryChangeLog changeLog = new InMemoryQueryChangeLog(); final QueryRepository queries = new InMemoryQueryRepository( changeLog, SCHEDULE ); try { - queries.startAndWait(); + queries.startAsync(); // Add some queries and deletes to it. final Set expected = new HashSet<>(); expected.add( queries.add("query 1", true, true) ); @@ -98,10 +97,10 @@ public void initializedWithPopulatedChangeLog() throws Exception { final Set stored = initializedQueries.list(); assertEquals(expected, stored); } finally { - queries.stop(); + queries.stopAsync(); } } finally { - queries.stop(); + queries.stopAsync(); } } @@ -160,7 +159,7 @@ public void updateListenerNotify() throws Exception { // Setup a totally in memory QueryRepository. final QueryRepository queries = new InMemoryQueryRepository( new InMemoryQueryChangeLog(), SCHEDULE ); try { - queries.startAndWait(); + queries.startAsync(); // Add a query to it. final StreamsQuery query = queries.add("query 1", true, false); @@ -179,7 +178,7 @@ public void updateListenerNotify() throws Exception { queries.add("query 2", true, false); } finally { - queries.stop(); + queries.stopAsync(); } } @@ -191,8 +190,8 @@ public void updateListenerNotify_multiClient() throws Exception { final QueryRepository queries2 = new InMemoryQueryRepository( changeLog, SCHEDULE ); try { - queries.startAndWait(); - queries2.startAndWait(); + queries.startAsync(); + queries2.startAsync(); //show listener on repo that query was added to is being notified of the new query. final CountDownLatch repo1Latch = new CountDownLatch(1); @@ -226,8 +225,8 @@ public void updateListenerNotify_multiClient() throws Exception { assertTrue(repo2Latch.await(5, TimeUnit.SECONDS)); } catch(final InterruptedException e ) { } finally { - queries.stop(); - queries2.stop(); + queries.stopAsync(); + queries2.stopAsync(); } } diff --git a/extras/rya.streams/client/src/test/java/org/apache/rya/streams/client/command/RunQueryCommandIT.java b/extras/rya.streams/client/src/test/java/org/apache/rya/streams/client/command/RunQueryCommandIT.java index 9fbc2c627..07eb3e898 100644 --- a/extras/rya.streams/client/src/test/java/org/apache/rya/streams/client/command/RunQueryCommandIT.java +++ b/extras/rya.streams/client/src/test/java/org/apache/rya/streams/client/command/RunQueryCommandIT.java @@ -18,17 +18,8 @@ */ package org.apache.rya.streams.client.command; -import static org.junit.Assert.assertEquals; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; import org.apache.kafka.clients.consumer.Consumer; import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.common.serialization.StringDeserializer; @@ -60,8 +51,16 @@ import org.junit.Rule; import org.junit.Test; -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; /** * Integration tests the methods of {@link RunQueryCommand}. @@ -99,7 +98,7 @@ public void setup() { @After public void cleanup() throws Exception { - queryRepo.stopAndWait(); + queryRepo.stopAsync(); stmtProducer.close(); resultConsumer.close(); } diff --git a/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/KafkaRyaStreamsClientFactory.java b/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/KafkaRyaStreamsClientFactory.java index 0bf13d143..e267252fb 100644 --- a/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/KafkaRyaStreamsClientFactory.java +++ b/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/KafkaRyaStreamsClientFactory.java @@ -18,12 +18,9 @@ */ package org.apache.rya.streams.kafka; -import static java.util.Objects.requireNonNull; - -import java.util.Properties; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - +import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.kafka.clients.CommonClientConfigs; import org.apache.kafka.clients.consumer.Consumer; import org.apache.kafka.clients.consumer.ConsumerConfig; @@ -55,10 +52,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import java.util.Properties; +import java.util.UUID; +import java.util.concurrent.TimeUnit; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * Constructs instances of {@link RyaStreamsClient} that are connected to a Kafka cluster. @@ -111,7 +109,7 @@ public static RyaStreamsClient make( @Override public void close() { try { - queryRepo.stopAndWait(); + queryRepo.stopAsync(); } catch (final Exception e) { log.warn("Couldn't close a QueryRepository.", e); } @@ -123,7 +121,7 @@ public void close() { * Create a {@link Producer} that is able to write to a topic in Kafka. * * @param kafkaHostname - The Kafka broker hostname. (not null) - * @param kafkaPort - The Kafka broker port. + * @param kakfaPort - The Kafka broker port. * @param keySerializerClass - Serializes the keys. (not null) * @param valueSerializerClass - Serializes the values. (not null) * @return A {@link Producer} that can be used to write records to a topic. @@ -149,7 +147,7 @@ private static Producer makeProducer( * starting at the earliest point by default. * * @param kafkaHostname - The Kafka broker hostname. (not null) - * @param kafkaPort - The Kafka broker port. + * @param kakfaPort - The Kafka broker port. * @param keyDeserializerClass - Deserializes the keys. (not null) * @param valueDeserializerClass - Deserializes the values. (not null) * @return A {@link Consumer} that can be used to read records from a topic. diff --git a/extras/rya.streams/query-manager/src/main/java/org/apache/rya/streams/querymanager/QueryManager.java b/extras/rya.streams/query-manager/src/main/java/org/apache/rya/streams/querymanager/QueryManager.java index e6bd800e7..2d2f25249 100644 --- a/extras/rya.streams/query-manager/src/main/java/org/apache/rya/streams/querymanager/QueryManager.java +++ b/extras/rya.streams/query-manager/src/main/java/org/apache/rya/streams/querymanager/QueryManager.java @@ -18,7 +18,23 @@ */ package org.apache.rya.streams.querymanager; -import static java.util.Objects.requireNonNull; +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import com.google.common.util.concurrent.AbstractService; +import com.google.common.util.concurrent.UncheckedExecutionException; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.rya.streams.api.entity.StreamsQuery; +import org.apache.rya.streams.api.queries.ChangeLogEntry; +import org.apache.rya.streams.api.queries.InMemoryQueryRepository; +import org.apache.rya.streams.api.queries.QueryChange; +import org.apache.rya.streams.api.queries.QueryChangeLog; +import org.apache.rya.streams.api.queries.QueryChangeLogListener; +import org.apache.rya.streams.api.queries.QueryRepository; +import org.apache.rya.streams.querymanager.QueryChangeLogSource.SourceListener; +import org.apache.rya.streams.querymanager.QueryExecutor.QueryExecutorException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; @@ -35,25 +51,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.rya.streams.api.entity.StreamsQuery; -import org.apache.rya.streams.api.queries.ChangeLogEntry; -import org.apache.rya.streams.api.queries.InMemoryQueryRepository; -import org.apache.rya.streams.api.queries.QueryChange; -import org.apache.rya.streams.api.queries.QueryChangeLog; -import org.apache.rya.streams.api.queries.QueryChangeLogListener; -import org.apache.rya.streams.api.queries.QueryRepository; -import org.apache.rya.streams.querymanager.QueryChangeLogSource.SourceListener; -import org.apache.rya.streams.querymanager.QueryExecutor.QueryExecutorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; -import com.google.common.util.concurrent.AbstractService; -import com.google.common.util.concurrent.UncheckedExecutionException; - -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * A service for managing {@link StreamsQuery} running on a Rya Streams system. @@ -139,10 +137,12 @@ protected void doStart() { executor.submit(new QueryEventWorker(queryEvents, queryExecutor, blockingValue, blockingUnits, shutdownSignal)); // Start up the query execution framework. - queryExecutor.startAndWait(); + queryExecutor.startAsync(); + queryExecutor.awaitRunning(); // Startup the source that discovers new Query Change Logs. - changeLogSource.startAndWait(); + changeLogSource.startAsync(); + changeLogSource.awaitRunning(); // Subscribe the source a listener that writes to the LogEventWorker's work queue. changeLogSource.subscribe(new LogEventWorkGenerator(logEvents, blockingValue, blockingUnits, shutdownSignal)); @@ -176,14 +176,16 @@ protected void doStop() { // Stop the source of new Change Logs. try { - changeLogSource.stopAndWait(); + changeLogSource.stopAsync(); + changeLogSource.awaitTerminated(); } catch(final UncheckedExecutionException e) { log.warn("Could not stop the Change Log Source.", e); } // Stop the query execution framework. try { - queryExecutor.stopAndWait(); + queryExecutor.stopAsync(); + queryExecutor.awaitTerminated(); } catch(final UncheckedExecutionException e) { log.warn("Could not stop the Query Executor", e); } @@ -303,7 +305,7 @@ public String toString() { * {@link QueryChangeLogSource}. * * @param ryaInstance - The Rya Instance the created log is for. (not null) - * @param log - The created {@link QueryChangeLog. (not null) + * @param log - The created {@link QueryChangeLog}. (not null) * @return A {@link LogEvent} built using the provided values. */ public static LogEvent create(final String ryaInstance, final QueryChangeLog log) { @@ -499,7 +501,7 @@ static class LogEventWorkGenerator implements SourceListener { private final TimeUnit offerUnits; /** - * Constructs an instance of {@link QueryManagerSourceListener}. + * Constructs an instance of the {@link SourceListener} interface. * * @param workQueue - A blocking queue that will have {@link LogEvent}s offered to it. (not null) * @param offerValue - How long to wait when offering new work. @@ -548,7 +550,7 @@ public void notifyDelete(final String ryaInstanceName) { *

* Whenever a new log has been created, then it registers a {@link QueryEventWorkGenerator} * that generates {@link QueryEvent}s based on the content and updates to the discovered - * {@link QueryChagneLog}. + * {@link QueryChangeLog}. *

* Whenever a log is deleted, then the generator is stopped and a stop all {@link QueryEvent} * is written to the work queue. @@ -620,7 +622,8 @@ public void run() { // so that it may be shutdown later. final Scheduler scheduler = Scheduler.newFixedRateSchedule(0, blockingValue, blockingUnits); final QueryRepository repo = new InMemoryQueryRepository(logEvent.getQueryChangeLog().get(), scheduler); - repo.startAndWait(); + repo.startAsync(); + repo.awaitRunning(); repos.put(ryaInstance, repo); // Subscribe a worker that adds the Query Events to the queryWorkQueue queue. @@ -659,7 +662,8 @@ public void run() { // Shut down the query repository for the Rya instance. This ensures the listener will // not receive any more work that needs to be done. final QueryRepository deletedRepo = repos.remove(ryaInstance); - deletedRepo.stopAndWait(); + deletedRepo.stopAsync(); + deletedRepo.awaitTerminated(); // Add work that stops all of the queries related to the instance. final QueryEvent stopAllEvent = QueryEvent.stopALL(ryaInstance); @@ -675,7 +679,8 @@ public void run() { log.info("LogEventWorker shutting down..."); // Shutdown all of the QueryRepositories that were started. - repos.values().forEach(repo -> repo.stopAndWait()); + repos.values().forEach(repo -> repo.stopAsync()); + repos.values().forEach(repo -> repo.awaitTerminated()); log.info("LogEventWorker shut down."); } diff --git a/extras/rya.streams/query-manager/src/main/java/org/apache/rya/streams/querymanager/QueryManagerDaemon.java b/extras/rya.streams/query-manager/src/main/java/org/apache/rya/streams/querymanager/QueryManagerDaemon.java index 04a0382fb..b879eba60 100644 --- a/extras/rya.streams/query-manager/src/main/java/org/apache/rya/streams/querymanager/QueryManagerDaemon.java +++ b/extras/rya.streams/query-manager/src/main/java/org/apache/rya/streams/querymanager/QueryManagerDaemon.java @@ -18,16 +18,12 @@ */ package org.apache.rya.streams.querymanager; -import static java.util.Objects.requireNonNull; - -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; - -import javax.xml.bind.JAXBException; - +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; +import com.beust.jcommander.ParameterException; +import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.DaemonContext; import org.apache.commons.daemon.DaemonInitException; @@ -44,13 +40,14 @@ import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.ParameterException; -import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import javax.xml.bind.JAXBException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * JSVC integration code for a {@link QueryManager} to be used as a non-Windows daemon. @@ -122,13 +119,15 @@ public void init(final DaemonContext context) throws DaemonInitException, Except @Override public void start() throws Exception { log.info("Starting the Rya Streams Query Manager Daemon."); - manager.startAndWait(); + manager.startAsync(); + manager.awaitRunning(); } @Override public void stop() throws Exception { log.info("Stopping the Rya Streams Query Manager Daemon."); - manager.stopAndWait(); + manager.stopAsync(); + manager.awaitTerminated(); } @Override diff --git a/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/QueryManagerTest.java b/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/QueryManagerTest.java index f1c9e0f45..c2da67c63 100644 --- a/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/QueryManagerTest.java +++ b/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/QueryManagerTest.java @@ -18,17 +18,6 @@ */ package org.apache.rya.streams.querymanager; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - import org.apache.rya.streams.api.entity.StreamsQuery; import org.apache.rya.streams.api.queries.InMemoryQueryChangeLog; import org.apache.rya.streams.api.queries.QueryChange; @@ -36,6 +25,17 @@ import org.apache.rya.streams.querymanager.QueryChangeLogSource.SourceListener; import org.junit.Test; +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Unit tests the methods of {@link QueryManager}. */ @@ -75,11 +75,12 @@ public void testCreateQuery() throws Exception { final QueryManager qm = new QueryManager(qe, source, 50, TimeUnit.MILLISECONDS); try { - qm.startAndWait(); + qm.startAsync(); + qm.awaitRunning(); queryStarted.await(5, TimeUnit.SECONDS); verify(qe).startQuery(ryaInstance, query); } finally { - qm.stopAndWait(); + qm.stopAsync(); } } @@ -129,11 +130,12 @@ public void testDeleteQuery() throws Exception { final QueryManager qm = new QueryManager(qe, source, 50, TimeUnit.MILLISECONDS); try { - qm.startAndWait(); + qm.startAsync(); + qm.awaitRunning(); queryDeleted.await(5, TimeUnit.SECONDS); verify(qe).stopQuery(query.getQueryId()); } finally { - qm.stopAndWait(); + qm.stopAsync(); } } @@ -184,11 +186,12 @@ public void testUpdateQuery() throws Exception { final QueryManager qm = new QueryManager(qe, source, 50, TimeUnit.MILLISECONDS); try { - qm.startAndWait(); + qm.startAsync(); + qm.awaitRunning(); queryDeleted.await(10, TimeUnit.SECONDS); verify(qe).stopQuery(query.getQueryId()); } finally { - qm.stopAndWait(); + qm.stopAsync(); } } } \ No newline at end of file diff --git a/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/KafkaQueryChangeLogSourceIT.java b/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/KafkaQueryChangeLogSourceIT.java index 5914b789a..4bc4d3f43 100644 --- a/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/KafkaQueryChangeLogSourceIT.java +++ b/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/KafkaQueryChangeLogSourceIT.java @@ -18,15 +18,7 @@ */ package org.apache.rya.streams.querymanager.kafka; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - +import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; import org.apache.rya.streams.api.queries.QueryChangeLog; import org.apache.rya.streams.kafka.KafkaTopics; import org.apache.rya.streams.querymanager.QueryChangeLogSource; @@ -36,7 +28,14 @@ import org.junit.Rule; import org.junit.Test; -import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Integration tests the methods of {@link KafkaQueryChangeLogSource}. @@ -79,13 +78,14 @@ public void notifyDelete(final String ryaInstanceName) { } try { // Start the source. - source.startAndWait(); + source.startAsync(); + source.awaitRunning(); // If the latch isn't counted down, then fail the test. assertTrue( created.await(5, TimeUnit.SECONDS) ); } finally { - source.stopAndWait(); + source.stopAsync(); } } @@ -113,7 +113,8 @@ public void notifyDelete(final String ryaInstanceName) { } try { // Start the source. - source.startAndWait(); + source.startAsync(); + source.awaitRunning(); // Wait twice the polling duration to ensure it iterates at least once. Thread.sleep(200); @@ -125,7 +126,7 @@ public void notifyDelete(final String ryaInstanceName) { } // If the latch isn't counted down, then fail the test. assertTrue( created.await(5, TimeUnit.SECONDS) ); } finally { - source.stopAndWait(); + source.stopAsync(); } } @@ -161,7 +162,8 @@ public void notifyDelete(final String ryaInstanceName) { try { // Start the source - source.startAndWait(); + source.startAsync(); + source.awaitRunning(); // Wait for it to indicate the topic was created. assertTrue( created.await(5, TimeUnit.SECONDS) ); @@ -173,7 +175,7 @@ public void notifyDelete(final String ryaInstanceName) { assertTrue( deleted.await(5, TimeUnit.SECONDS) ); } finally { - source.stopAndWait(); + source.stopAsync(); } } @@ -205,7 +207,8 @@ public void notifyDelete(final String ryaInstanceName) { } try { // Start the source - source.startAndWait(); + source.startAsync(); + source.awaitRunning(); // Wait for that first listener to indicate the topic was created. This means that one has been cached. assertTrue( created.await(5, TimeUnit.SECONDS) ); @@ -226,7 +229,7 @@ public void notifyDelete(final String ryaInstanceName) { } assertTrue( newListenerCreated.await(5, TimeUnit.SECONDS) ); } finally { - source.stopAndWait(); + source.stopAsync(); } } @@ -240,7 +243,8 @@ public void unsubscribedDoesNotReceiveNotifications() throws Exception { try { // Start the source. - source.startAndWait(); + source.startAsync(); + source.awaitRunning(); // Create a listener that flips a boolean to true when it is notified. final AtomicBoolean notified = new AtomicBoolean(false); @@ -271,7 +275,7 @@ public void notifyDelete(final String ryaInstanceName) { // Show the boolean was never flipped to true. assertFalse(notified.get()); } finally { - source.stopAndWait(); + source.stopAsync(); } } } \ No newline at end of file diff --git a/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/LocalQueryExecutorIT.java b/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/LocalQueryExecutorIT.java index fcb3a4674..624ef35b1 100644 --- a/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/LocalQueryExecutorIT.java +++ b/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/LocalQueryExecutorIT.java @@ -18,12 +18,7 @@ */ package org.apache.rya.streams.querymanager.kafka; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - +import com.google.common.collect.Lists; import org.apache.kafka.clients.consumer.Consumer; import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.common.serialization.StringDeserializer; @@ -50,7 +45,11 @@ import org.junit.Rule; import org.junit.Test; -import com.google.common.collect.Lists; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; /** * Integration tests the methods of {@link LocalQueryExecutor}. @@ -124,7 +123,8 @@ public void runQuery() throws Exception { final String kafkaServers = kafka.getKafkaHostname() + ":" + kafka.getKafkaPort(); final KafkaStreamsFactory jobFactory = new SingleThreadKafkaStreamsFactory(kafkaServers); final QueryExecutor executor = new LocalQueryExecutor(createKafkaTopic, jobFactory); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Start the query. executor.startQuery(ryaInstance, sQuery); @@ -144,7 +144,7 @@ public void runQuery() throws Exception { assertEquals(expected, results); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } } \ No newline at end of file diff --git a/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/LocalQueryExecutorTest.java b/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/LocalQueryExecutorTest.java index efbcf4bba..b58aad11a 100644 --- a/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/LocalQueryExecutorTest.java +++ b/extras/rya.streams/query-manager/src/test/java/org/apache/rya/streams/querymanager/kafka/LocalQueryExecutorTest.java @@ -18,17 +18,7 @@ */ package org.apache.rya.streams.querymanager.kafka; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Set; -import java.util.UUID; - +import com.google.common.collect.Sets; import org.apache.kafka.streams.KafkaStreams; import org.apache.rya.streams.api.entity.StreamsQuery; import org.apache.rya.streams.kafka.KafkaStreamsFactory; @@ -36,7 +26,16 @@ import org.apache.rya.streams.querymanager.QueryExecutor; import org.junit.Test; -import com.google.common.collect.Sets; +import java.util.Set; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * Unit tests the methods of {@link LocalQueryExecutor}. @@ -62,7 +61,8 @@ public void startQuery() throws Exception { // Start the executor that will be tested. final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Tell the executor to start the query. executor.startQuery(ryaInstance, query); @@ -70,7 +70,7 @@ public void startQuery() throws Exception { // Show a job was started for that query's ID. verify(queryJob).start(); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } @@ -84,12 +84,13 @@ public void stopQuery_serviceNotStarted() throws Exception { public void stopQuery_queryNotRunning() throws Exception { // Start an executor. final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), mock(KafkaStreamsFactory.class)); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Try to stop a query that was never stareted. executor.stopQuery(UUID.randomUUID()); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } @@ -106,7 +107,8 @@ public void stopQuery() throws Exception { // Start the executor that will be tested. final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Tell the executor to start the query. executor.startQuery(ryaInstance, query); @@ -117,7 +119,7 @@ public void stopQuery() throws Exception { // Show a job was stopped for that query's ID. verify(queryJob).close(); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } @@ -143,7 +145,8 @@ public void stopAll_noneForThatRyaInstance() throws Exception { // Start the executor that will be tested. final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Tell the executor to start the queries. executor.startQuery(ryaInstance, query1); @@ -161,7 +164,7 @@ public void stopAll_noneForThatRyaInstance() throws Exception { verify(queryJob2, never()).close(); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } @@ -182,7 +185,8 @@ public void stopAll() throws Exception { // Start the executor that will be tested. final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Tell the executor to start the queries. executor.startQuery(ryaInstance1, query1); @@ -200,7 +204,7 @@ public void stopAll() throws Exception { verify(queryJob2).close(); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } @@ -214,7 +218,8 @@ public void getRunningQueryIds_serviceNotStarted() throws Exception { public void getRunningQueryIds_noneStarted() throws Exception { // Start an executor. final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), mock(KafkaStreamsFactory.class)); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Get the list of running queries. final Set runningQueries = executor.getRunningQueryIds(); @@ -222,7 +227,7 @@ public void getRunningQueryIds_noneStarted() throws Exception { // Show no queries are reported as running. assertTrue(runningQueries.isEmpty()); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } @@ -242,7 +247,8 @@ public void getRunningQueryIds_noneStopped() throws Exception { // Start the executor that will be tested. final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Start the queries. executor.startQuery(ryaInstance, query1); @@ -257,7 +263,7 @@ public void getRunningQueryIds_noneStopped() throws Exception { assertEquals(expected, executor.getRunningQueryIds()); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } @@ -277,7 +283,8 @@ public void getRunningQueryIds_stoppedNoLongerListed() throws Exception { // Start the executor that will be tested. final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory); - executor.startAndWait(); + executor.startAsync(); + executor.awaitRunning(); try { // Start the queries. executor.startQuery(ryaInstance, query1); @@ -294,7 +301,7 @@ public void getRunningQueryIds_stoppedNoLongerListed() throws Exception { assertEquals(expected, executor.getRunningQueryIds()); } finally { - executor.stopAndWait(); + executor.stopAsync(); } } } \ No newline at end of file diff --git a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/AccumuloHDFSFileInputFormat.java b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/AccumuloHDFSFileInputFormat.java index 63929bb79..132993f56 100644 --- a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/AccumuloHDFSFileInputFormat.java +++ b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/AccumuloHDFSFileInputFormat.java @@ -19,25 +19,18 @@ * under the License. */ -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - +import com.google.common.base.Preconditions; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Instance; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.client.admin.TableOperations; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; -import org.apache.accumulo.core.data.ByteSequence; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.file.FileSKVIterator; import org.apache.accumulo.core.file.rfile.RFileOperations; import org.apache.accumulo.core.security.Authorizations; -import org.apache.accumulo.core.util.ArgumentChecker; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.FileStatus; @@ -52,6 +45,12 @@ import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.input.FileSplit; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + /** * {@link FileInputFormat} that finds the Accumulo tablet files on the HDFS * disk, and uses that as the input for MapReduce jobs. @@ -68,8 +67,8 @@ public List getSplits(JobContext jobContext) throws IOException { String user = MRUtils.AccumuloProps.getUsername(jobContext); AuthenticationToken password = MRUtils.AccumuloProps.getPassword(jobContext); String table = MRUtils.AccumuloProps.getTablename(jobContext); - ArgumentChecker.notNull(instance); - ArgumentChecker.notNull(table); + Preconditions.checkNotNull(instance); + Preconditions.checkNotNull(table); //find the files necessary try { @@ -113,8 +112,11 @@ public void initialize(InputSplit inputSplit, TaskAttemptContext taskAttemptCont FileSystem fs = file.getFileSystem(job); Instance instance = MRUtils.AccumuloProps.getInstance(taskAttemptContext); - fileSKVIterator = RFileOperations.getInstance().openReader(file.toString(), ALLRANGE, - new HashSet(), false, fs, job, instance.getConfiguration()); + fileSKVIterator = RFileOperations.getInstance().newScanReaderBuilder() + .forFile(file.toString(), fs, job) + .withTableConfiguration(instance.getConfiguration()) + .overRange(ALLRANGE, new HashSet<>(), false) + .build(); } @Override diff --git a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaInputFormat.java b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaInputFormat.java index 2fc272805..521d23f65 100644 --- a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaInputFormat.java +++ b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaInputFormat.java @@ -19,21 +19,18 @@ * under the License. */ -import java.io.IOException; -import java.util.Map.Entry; - +import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.client.mapreduce.AbstractInputFormat; import org.apache.accumulo.core.client.mapreduce.RangeInputSplit; +import org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.InputSplit; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.RecordReader; import org.apache.hadoop.mapreduce.TaskAttemptContext; - import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; import org.apache.rya.api.domain.RyaStatement; @@ -41,6 +38,10 @@ import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolverException; +import java.io.IOException; +import java.util.List; +import java.util.Map.Entry; + /** * Subclass of {@link AbstractInputFormat} for reading * {@link RyaStatementWritable}s directly from a running Rya instance. @@ -76,6 +77,20 @@ public class RyaStatementRecordReader extends AbstractRecordReader contextIterators(TaskAttemptContext context, String tableName) { + return InputConfigurator.getIterators(CLASS, context.getConfiguration()); + } + @Override protected void setupIterators(TaskAttemptContext context, Scanner scanner, String tableName, RangeInputSplit split) { diff --git a/pig/accumulo.pig/src/main/java/org/apache/rya/accumulo/pig/AccumuloStorage.java b/pig/accumulo.pig/src/main/java/org/apache/rya/accumulo/pig/AccumuloStorage.java index d0185a122..591d6eb25 100644 --- a/pig/accumulo.pig/src/main/java/org/apache/rya/accumulo/pig/AccumuloStorage.java +++ b/pig/accumulo.pig/src/main/java/org/apache/rya/accumulo/pig/AccumuloStorage.java @@ -19,21 +19,6 @@ * under the License. */ - - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriterConfig; import org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat; @@ -69,6 +54,18 @@ import org.apache.pig.data.Tuple; import org.apache.pig.data.TupleFactory; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.TimeUnit; + /** * A LoadStoreFunc for retrieving data from and storing data to Accumulo *

@@ -377,6 +374,10 @@ private static byte[] objToBytes(final Object o) { public void cleanupOnFailure(final String failure, final Job job) { } + @Override + public void cleanupOnSuccess(String s, Job job) throws IOException { + } + @Override public WritableComparable getSplitComparable(final InputSplit inputSplit) throws IOException { //cannot get access to the range directly diff --git a/pom.xml b/pom.xml index 3e68ee5c1..37d4ac0bc 100644 --- a/pom.xml +++ b/pom.xml @@ -69,38 +69,38 @@ under the License. web - 2.3.1 + 3.2.2 - 1.6.4 - 2.5.0 + 1.9.3 + 2.9.2 - 3.4.6 + 3.4.14 - 0.9.2 + 0.15.0 - 5.2.1 - 2.1 + 5.3.1 + 2.9.1 3.10.2 2.2.0 - 3.2.2 + 3.2.2 - 2.6 - 1.10 - 1.6 + 2.6 + 1.10 + 1.6 2.5 - 1.3 + 1.5 - 14.0.1 + 18.0 2.8.1 - 4.5.2 - 4.4.4 + 4.5.10 + 4.4.12 2.2.11 - 1.2.0 + 1.4.0 3.4 1.7.2 1.3 @@ -110,11 +110,12 @@ under the License. 1.0.2.RELEASE 1.1.0.RELEASE - 4.12 - 1.10.19 - 1.1.0 - 1.7.25 - 1.6.1 + 4.12 + 1.1.0 + 1.7.26 + 1.10.19 + 2.28.2 + 2.0.2 UTF-8 UTF-8 @@ -122,16 +123,18 @@ under the License. 3.0.4 - 1.0.0-incubating + 1.2.0 3.0.8 - 0.9.1 + 0.9.3 1.2 1.60 4.0.1 1.13 + 0.14.0 + 1.3.9-1 1.0-1 0.10.0.1 @@ -227,7 +230,7 @@ under the License. LocationTech - SNAPSHOT - https://repo.locationtech.org/content/repositories/snapshots/ + https://repo.eclipse.org/content/repositories/snapshots/ false @@ -237,7 +240,7 @@ under the License. LocationTech - RELEASE - https://repo.locationtech.org/content/repositories/releases/ + https://repo.eclipse.org/content/repositories/releases/ true @@ -247,7 +250,7 @@ under the License. LocationTech - Third Party - https://repo.locationtech.org/content/repositories/thirdparty/ + https://repo.eclipse.org/content/repositories/thirdparty/ true @@ -366,6 +369,20 @@ under the License. + + + + + oss.sonatype.org-snapshot + http://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + @@ -569,7 +586,7 @@ under the License. org.apache.rya rya.kafka.connect.mongo ${project.version} - + org.apache.accumulo accumulo-core @@ -582,8 +599,10 @@ under the License. org.eclipse.rdf4j - rdf4j-runtime + rdf4j-bom ${org.eclipse.rdf4j.version} + pom + import org.eclipse.rdf4j @@ -615,7 +634,6 @@ under the License. rdf4j-queryresultio-text ${org.eclipse.rdf4j.version} - org.eclipse.rdf4j rdf4j-rio-api @@ -661,6 +679,12 @@ under the License. rdf4j-queryrender ${org.eclipse.rdf4j.version} + + org.eclipse.rdf4j + rdf4j-runtime + ${org.eclipse.rdf4j.version} + pom + org.eclipse.rdf4j rdf4j-runtime-osgi @@ -1012,7 +1036,13 @@ under the License. org.mockito mockito-all - ${mockito.version} + ${mockito.all.version} + test + + + org.mockito + mockito-core + ${mockito.core.version} test @@ -1028,19 +1058,53 @@ under the License. test + + org.powermock + powermock-core + + + org.powermock + powermock-all + org.powermock powermock-module-junit4 + + org.powermock + powermock-api-mockito + + + org.powermock + powermock-api-mockito2 + + + org.powermock + powermock-core + ${powermock.version} + test + + + org.powermock + powermock-all + ${powermock.version} + test + org.powermock powermock-module-junit4 ${powermock.version} test - + + org.powermock + powermock-api-mockito2 + ${powermock.version} + test + + org.openjdk.jmh @@ -1142,11 +1206,11 @@ under the License. - + org.codehaus.mojo animal-sniffer-maven-plugin - 1.15 + 1.16 org.codehaus.mojo.signature @@ -1500,4 +1564,4 @@ under the License. HEAD https://git-wip-us.apache.org/repos/asf?p=incubator-rya.git - \ No newline at end of file + diff --git a/sail/pom.xml b/sail/pom.xml index d222e4193..b2508423c 100644 --- a/sail/pom.xml +++ b/sail/pom.xml @@ -67,6 +67,7 @@ under the License. org.eclipse.rdf4j rdf4j-runtime + pom diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java index ae97fd8ab..56394883a 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java @@ -103,18 +103,21 @@ import org.eclipse.rdf4j.query.impl.EmptyBindingSet; import org.eclipse.rdf4j.sail.SailException; import org.eclipse.rdf4j.sail.helpers.AbstractSailConnection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RdfCloudTripleStoreConnection extends AbstractSailConnection { + + private static final Logger logger = LoggerFactory.getLogger(RdfCloudTripleStoreConnection.class); + private final RdfCloudTripleStore store; + private final C conf; private RdfEvalStatsDAO rdfEvalStatsDAO; private SelectivityEvalDAO selectEvalDAO; private RyaDAO ryaDAO; private InferenceEngine inferenceEngine; private NamespaceManager namespaceManager; - private final C conf; - - private ProvenanceCollector provenanceCollector; public RdfCloudTripleStoreConnection(final RdfCloudTripleStore sailBase, final C conf, final ValueFactory vf) From 77e47923998dcb70812859c17d8eae6d175ba088 Mon Sep 17 00:00:00 2001 From: Brad Rushworth <67445484+brushworth@users.noreply.github.com> Date: Tue, 14 Jul 2020 17:16:59 +1000 Subject: [PATCH 2/3] Replacing the old @Immutable annotation with @Contract(threading = ThreadingBehavior.IMMUTABLE) per the advice at https://dev-aux.com/java/org-apache-http-annotation-threadsafe-class-not-found --- extras/indexing/pom.xml | 2 +- .../java/org/apache/rya/indexing/entity/model/Entity.java | 5 +++-- .../java/org/apache/rya/indexing/entity/model/Property.java | 5 +++-- .../main/java/org/apache/rya/indexing/entity/model/Type.java | 5 +++-- .../org/apache/rya/indexing/entity/model/TypedEntity.java | 5 +++-- .../rya/export/api/conf/AccumuloMergeConfiguration.java | 5 +++-- .../org/apache/rya/export/api/conf/MergeConfiguration.java | 5 +++-- pom.xml | 2 +- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/extras/indexing/pom.xml b/extras/indexing/pom.xml index c9efd0672..aba2d99e8 100644 --- a/extras/indexing/pom.xml +++ b/extras/indexing/pom.xml @@ -70,7 +70,6 @@ httpclient - org.apache.rya @@ -84,6 +83,7 @@ org.apache.rya rya.periodic.notification.api + org.eclipse.rdf4j diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java index 5f0497820..e1afec64e 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java @@ -24,7 +24,8 @@ import edu.umd.cs.findbugs.annotations.DefaultAnnotation; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.http.annotation.Contract; +import org.apache.http.annotation.ThreadingBehavior; import org.apache.log4j.Logger; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.indexing.entity.storage.EntityStorage; @@ -72,7 +73,7 @@ * the {@link Type}, but nothing has explicitly indicated it is of that Type. * Once something has done so, it is an explicitly typed Entity. */ -@Immutable +@Contract(threading = ThreadingBehavior.IMMUTABLE) @DefaultAnnotation(NonNull.class) public class Entity { private static final Logger log = Logger.getLogger(Entity.class); diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java index 0b9b77d58..cda44bb7a 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java @@ -20,7 +20,8 @@ import edu.umd.cs.findbugs.annotations.DefaultAnnotation; import edu.umd.cs.findbugs.annotations.NonNull; -import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.http.annotation.Contract; +import org.apache.http.annotation.ThreadingBehavior; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaType; @@ -31,7 +32,7 @@ /** * A value that has been set for an {@link TypedEntity}. */ -@Immutable +@Contract(threading = ThreadingBehavior.IMMUTABLE) @DefaultAnnotation(NonNull.class) public class Property { diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java index 1a61812bf..23c3dbd54 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java @@ -21,7 +21,8 @@ import com.google.common.collect.ImmutableSet; import edu.umd.cs.findbugs.annotations.DefaultAnnotation; import edu.umd.cs.findbugs.annotations.NonNull; -import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.http.annotation.Contract; +import org.apache.http.annotation.ThreadingBehavior; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.indexing.entity.storage.TypeStorage; @@ -42,7 +43,7 @@ * <urn:nutritionalInformation> * */ -@Immutable +@Contract(threading = ThreadingBehavior.IMMUTABLE) @DefaultAnnotation(NonNull.class) public class Type { diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java index fdce30dc2..ad0f0dd62 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java @@ -23,7 +23,8 @@ import edu.umd.cs.findbugs.annotations.DefaultAnnotation; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.http.annotation.Contract; +import org.apache.http.annotation.ThreadingBehavior; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaType; @@ -38,7 +39,7 @@ * A {@link TypedEntity} is a view of an {@link Entity} that has had a specific * {@link Type} applied to it. */ -@Immutable +@Contract(threading = ThreadingBehavior.IMMUTABLE) @DefaultAnnotation(NonNull.class) public class TypedEntity { diff --git a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java index 1a351147f..9f01b4a2f 100644 --- a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java +++ b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java @@ -18,14 +18,15 @@ */ package org.apache.rya.export.api.conf; -import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.http.annotation.Contract; +import org.apache.http.annotation.ThreadingBehavior; import org.apache.rya.export.InstanceType; /** * Immutable configuration object to allow the MergeTool to connect to the parent and child * databases for data merging. */ -@Immutable +@Contract(threading = ThreadingBehavior.IMMUTABLE) public class AccumuloMergeConfiguration extends MergeConfigurationDecorator { /** * Information needed to connect to the parent database diff --git a/extras/rya.export/export.api/src/main/java/org/apache/rya/export/api/conf/MergeConfiguration.java b/extras/rya.export/export.api/src/main/java/org/apache/rya/export/api/conf/MergeConfiguration.java index 329589bd4..757ce63ec 100644 --- a/extras/rya.export/export.api/src/main/java/org/apache/rya/export/api/conf/MergeConfiguration.java +++ b/extras/rya.export/export.api/src/main/java/org/apache/rya/export/api/conf/MergeConfiguration.java @@ -18,7 +18,8 @@ */ package org.apache.rya.export.api.conf; -import jdk.nashorn.internal.ir.annotations.Immutable; +import org.apache.http.annotation.Contract; +import org.apache.http.annotation.ThreadingBehavior; import org.apache.rya.export.DBType; import org.apache.rya.export.MergePolicy; @@ -28,7 +29,7 @@ * Immutable configuration object to allow the MergeTool to connect to the parent and child * databases for data merging. */ -@Immutable +@Contract(threading = ThreadingBehavior.IMMUTABLE) public class MergeConfiguration { /** * Information needed to connect to the parent database diff --git a/pom.xml b/pom.xml index 37d4ac0bc..f4729a542 100644 --- a/pom.xml +++ b/pom.xml @@ -250,7 +250,7 @@ under the License. LocationTech - Third Party - https://repo.eclipse.org/content/repositories/thirdparty/ + https://repo.eclipse.org/content/repositories/locationtech-thirdparty/ true From 94dbd1627fa1215aa7eaffd828f7519e5753123d Mon Sep 17 00:00:00 2001 From: Brad Rushworth <67445484+brushworth@users.noreply.github.com> Date: Fri, 26 Jun 2020 16:52:59 +1000 Subject: [PATCH 3/3] RYA-532 Assign specific interface types for Subject, Predicate, Object and Context and just generally clean up the code. --- .../rya/api/RdfCloudTripleStoreStatement.java | 74 -- .../rya/api/client/ExecuteSparqlQuery.java | 10 +- .../org/apache/rya/api/domain/RangeIRI.java | 10 +- .../org/apache/rya/api/domain/RyaIRI.java | 18 +- .../apache/rya/api/domain/RyaIRIRange.java | 20 +- .../org/apache/rya/api/domain/RyaRange.java | 4 +- .../apache/rya/api/domain/RyaResource.java | 25 + .../apache/rya/api/domain/RyaStatement.java | 116 +++- .../org/apache/rya/api/domain/RyaType.java | 53 +- .../apache/rya/api/domain/RyaTypeRange.java | 14 +- .../org/apache/rya/api/domain/RyaValue.java | 42 ++ .../rya/api/domain/StatementMetadata.java | 42 +- .../apache/rya/api/instance/RyaDetails.java | 29 +- .../org/apache/rya/api/persist/RyaDAO.java | 9 +- .../rya/api/persist/RyaDAOException.java | 3 +- .../rya/api/persist/query/BatchRyaQuery.java | 44 +- .../rya/api/persist/query/RyaQuery.java | 40 +- .../rya/api/persist/query/join/HashJoin.java | 51 +- .../api/persist/query/join/IterativeJoin.java | 64 +- .../rya/api/persist/query/join/Join.java | 17 +- .../rya/api/persist/query/join/MergeJoin.java | 70 +- .../rya/api/persist/utils/RyaDAOHelper.java | 227 +++++-- .../api/persist/utils/RyaDaoQueryWrapper.java | 30 +- .../rya/api/query/strategy/ByteRange.java | 6 + .../query/strategy/TriplePatternStrategy.java | 10 +- .../AbstractHashedTriplePatternStrategy.java | 15 +- ...HashedPoWholeRowTriplePatternStrategy.java | 42 +- ...ashedSpoWholeRowTriplePatternStrategy.java | 41 +- .../NullRowTriplePatternStrategy.java | 29 +- .../OspWholeRowTriplePatternStrategy.java | 30 +- .../PoWholeRowTriplePatternStrategy.java | 32 +- .../SpoWholeRowTriplePatternStrategy.java | 32 +- .../rya/api/resolver/RdfToRyaConversions.java | 64 +- .../apache/rya/api/resolver/RyaContext.java | 13 +- .../rya/api/resolver/RyaToRdfConversions.java | 81 ++- .../rya/api/resolver/RyaTripleContext.java | 5 +- .../rya/api/resolver/RyaTypeResolver.java | 5 +- .../resolver/impl/CustomDatatypeResolver.java | 16 +- .../resolver/impl/RyaTypeResolverImpl.java | 16 +- .../resolver/triple/TripleRowResolver.java | 7 +- .../impl/WholeRowHashedTripleResolver.java | 44 +- .../triple/impl/WholeRowTripleResolver.java | 32 +- .../rya/api/utils/NullableStatementImpl.java | 103 --- .../rya/api/utils/WildcardStatement.java | 137 ++++ .../apache/rya/api/domain/RyaTypeTest.java | 4 + .../rya/api/persist/query/RyaQueryTest.java | 5 +- ...edPoWholeRowTriplePatternStrategyTest.java | 61 +- ...dSpoWholeRowTriplePatternStrategyTest.java | 109 ++- .../NullRowTriplePatternStrategyTest.java | 28 +- .../api/resolver/RdfToRyaConversionsTest.java | 254 ++++++- .../api/resolver/RyaToRdfConversionsTest.java | 124 +++- .../HashedWholeRowTripleResolverTest.java | 24 +- .../impl/WholeRowTripleResolverTest.java | 23 +- .../AccumuloRdfConfigurationBuilder.java | 18 +- .../rya/accumulo/AccumuloRdfEvalStatsDAO.java | 30 +- .../apache/rya/accumulo/AccumuloRdfUtils.java | 5 +- .../apache/rya/accumulo/AccumuloRyaDAO.java | 73 +- .../rya/accumulo/RyaTableKeyValues.java | 31 +- .../accumulo/RyaTableMutationsFactory.java | 65 +- .../query/AccumuloRyaQueryEngine.java | 33 +- .../query/RangeBindingSetEntries.java | 21 +- .../query/RyaStatementKeyValueIterator.java | 7 +- .../query/ScannerBaseCloseableIterable.java | 7 +- .../rya/accumulo/AccumuloRyaDAOTest.java | 637 +++++++++++++----- .../AccumuloRyaDetailsRepositoryIT.java | 15 +- .../query/RangeBindingSetEntriesTest.java | 129 ++++ dao/accumulo.rya/src/test/resources/log4j.xml | 40 ++ .../org/apache/rya/mongodb/MongoDBRyaDAO.java | 29 +- .../AggregationPipelineQueryNode.java | 76 +-- .../dao/SimpleMongoDBStorageStrategy.java | 36 +- .../RyaStatementBindingSetCursorIterator.java | 31 +- .../rya/mongodb/MongoDBQueryEngineIT.java | 16 +- .../apache/rya/mongodb/MongoDBRyaDAOIT.java | 29 +- .../SimpleMongoDBStorageStrategyTest.java | 13 +- .../instance/MongoRyaDetailsRepositoryIT.java | 17 +- .../client/accumulo/AccumuloCreatePCJ.java | 16 +- .../accumulo/AccumuloCreatePeriodicPCJ.java | 11 +- .../apache/rya/indexing/TemporalInterval.java | 5 +- .../AccumuloIndexingConfiguration.java | 27 +- .../accumulo/entity/EntityCentricIndex.java | 45 +- .../indexing/accumulo/entity/StarQuery.java | 25 +- .../rya/indexing/entity/model/Entity.java | 13 +- .../rya/indexing/entity/model/Property.java | 9 +- .../indexing/entity/model/TypedEntity.java | 17 +- .../entity/query/EntityQueryNode.java | 40 +- .../entity/storage/EntityStorage.java | 15 +- .../mongo/EntityDocumentConverter.java | 16 +- .../storage/mongo/MongoEntityStorage.java | 55 +- .../mongo/RyaTypeDocumentConverter.java | 12 +- .../entity/update/BaseEntityIndexer.java | 47 +- .../indexing/entity/update/EntityUpdater.java | 17 +- .../AbstractExternalSetOptimizer.java | 11 +- .../external/matching/BasicRater.java | 12 +- .../rya/indexing/mongodb/MongoDbSmartUri.java | 23 +- .../mongodb/update/MongoDocumentUpdater.java | 11 +- .../mongodb/update/RyaObjectStorage.java | 26 +- .../indexing/smarturi/SmartUriAdapter.java | 53 +- .../indexing/smarturi/SmartUriStorage.java | 9 +- .../duplication/DuplicateDataDetector.java | 37 +- .../matching/StatementMetadataNode.java | 47 +- .../rya/sail/config/RyaSailFactory.java | 21 +- ...DocumentIndexIntersectingIteratorTest.java | 16 +- .../accumulo/entity/StarQueryTest.java | 15 +- .../mongo/RyaTypeDocumentConverterTest.java | 9 +- .../tupleSet/AccumuloIndexSetTest.java | 21 +- .../accumulo/AccumuloRyaStatementStore.java | 24 +- .../accumulo/util/AccumuloInstanceDriver.java | 29 +- .../accumulo/util/AccumuloRyaUtils.java | 32 +- .../apache/rya/export/accumulo/TestUtils.java | 9 +- .../strategy/MongoPipelineStrategy.java | 21 +- .../strategy/RoundRobinStrategy.java | 17 +- .../strategy/SailExecutionStrategy.java | 12 +- .../accumulo/AccumuloPcjSerializer.java | 32 +- .../accumulo/BindingSetStringConverter.java | 20 +- .../pcj/storage/accumulo/PcjTables.java | 36 +- .../pcj/storage/accumulo/VariableOrder.java | 18 +- .../pcj/storage/mongo/MongoPcjDocuments.java | 45 +- .../pcj/storage/mongo/MongoPcjStorageIT.java | 26 +- .../mongo/PcjDocumentsIntegrationTest.java | 21 +- .../mr/merge/mappers/FileCopyToolMapper.java | 9 +- .../mr/merge/util/AccumuloQueryRuleset.java | 24 +- .../mr/merge/util/AccumuloRyaUtils.java | 36 +- .../rya/accumulo/mr/merge/CopyToolTest.java | 31 +- .../rya/accumulo/mr/merge/MergeToolTest.java | 29 +- .../rya/accumulo/mr/merge/util/TestUtils.java | 15 +- .../indexing/pcj/fluo/api/CreateFluoPcj.java | 45 +- .../pcj/fluo/app/ConstructProjection.java | 20 +- .../pcj/fluo/app/FluoStringConverter.java | 22 +- .../KryoVisibilityBindingSetSerializer.java | 19 +- .../app/util/BindingHashShardingFunction.java | 19 +- .../pcj/fluo/app/ConstructGraphTest.java | 30 +- .../pcj/fluo/app/ConstructGraphTestUtils.java | 15 +- .../fluo/demo/FluoAndHistoricPcjsDemo.java | 18 +- .../pcj/fluo/ConstructGraphTestUtils.java | 17 +- .../prospector/domain/TripleValueType.java | 6 +- .../apache/rya/prospector/mr/Prospector.java | 30 +- .../rya/prospector/mr/ProspectorMapper.java | 9 +- .../rya/prospector/plans/IndexWorkPlan.java | 17 +- .../rya/prospector/plans/impl/CountPlan.java | 35 +- .../prospector/service/ProspectorService.java | 22 +- .../mr/JoinSelectStatisticsTest.java | 88 ++- .../rya/prospector/mr/ProspectorTest.java | 20 +- .../ProspectorServiceEvalStatsDAOTest.java | 21 +- .../mr/DuplicateEliminationTest.java | 8 +- .../accumulo/mr/GraphXEdgeInputFormat.java | 20 +- .../rya/accumulo/mr/RyaOutputFormat.java | 25 +- .../rya/accumulo/mr/RyaTypeWritable.java | 16 +- .../mr/tools/AccumuloRdfCountTool.java | 19 +- .../mr/GraphXEdgeInputFormatTest.java | 18 +- .../rya/accumulo/mr/RyaInputFormatTest.java | 9 +- .../rya/accumulo/mr/RyaOutputFormatTest.java | 15 +- .../org/apache/rya/accumulo/mr/TestUtils.java | 34 +- .../accumulo/pig/StatementPatternStorage.java | 33 +- .../RdfCloudTripleStoreConnection.java | 41 +- .../ParallelEvaluationStrategyImpl.java | 6 +- .../inference/AllValuesFromVisitor.java | 14 +- .../inference/DomainRangeVisitor.java | 12 +- .../inference/HasValueVisitor.java | 14 +- .../inference/InferenceEngine.java | 184 +++-- .../inference/SameAsVisitor.java | 14 +- .../inference/SomeValuesFromVisitor.java | 14 +- .../inference/SubClassOfVisitor.java | 10 +- .../inference/SubPropertyOfVisitor.java | 10 +- .../java/org/apache/rya/HashJoinTest.java | 182 ++--- .../org/apache/rya/IterativeJoinTest.java | 191 +++--- .../java/org/apache/rya/MergeJoinTest.java | 57 +- .../evaluation/StatementPatternEvalTest.java | 127 +++- .../inference/AllValuesFromVisitorTest.java | 25 +- .../inference/HasValueVisitorTest.java | 33 +- .../inference/InferenceEngineTest.java | 23 +- .../rdftriplestore/inference/InferenceIT.java | 24 +- .../inference/PropertyChainTest.java | 8 +- .../inference/SomeValuesFromVisitorTest.java | 26 +- sail/src/test/resources/log4j.xml | 40 ++ .../test/accumulo/RyaTestInstanceRule.java | 8 +- .../cloud/rdf/web/sail/RdfControllerTest.java | 22 +- 176 files changed, 3915 insertions(+), 2749 deletions(-) delete mode 100644 common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreStatement.java create mode 100644 common/rya.api/src/main/java/org/apache/rya/api/domain/RyaResource.java create mode 100644 common/rya.api/src/main/java/org/apache/rya/api/domain/RyaValue.java delete mode 100644 common/rya.api/src/main/java/org/apache/rya/api/utils/NullableStatementImpl.java create mode 100644 common/rya.api/src/main/java/org/apache/rya/api/utils/WildcardStatement.java create mode 100644 dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/query/RangeBindingSetEntriesTest.java create mode 100644 dao/accumulo.rya/src/test/resources/log4j.xml create mode 100644 sail/src/test/resources/log4j.xml diff --git a/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreStatement.java b/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreStatement.java deleted file mode 100644 index 662d16856..000000000 --- a/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreStatement.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.apache.rya.api; - -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.Resource; -import org.eclipse.rdf4j.model.Statement; -import org.eclipse.rdf4j.model.Value; -import org.eclipse.rdf4j.model.ValueFactory; -import org.eclipse.rdf4j.model.impl.SimpleStatement; -import org.eclipse.rdf4j.model.impl.SimpleValueFactory; - -public class RdfCloudTripleStoreStatement extends SimpleStatement { - private static final long serialVersionUID = 1L; - - private static final ValueFactory VF = SimpleValueFactory.getInstance(); - - private Resource[] contexts; //TODO: no blank nodes - - public RdfCloudTripleStoreStatement(Resource subject, IRI predicate, Value object) { - super(subject, predicate, object); - } - - public RdfCloudTripleStoreStatement(Resource subject, IRI predicate, Value object, - Resource... contexts) { - super(subject, predicate, object); - this.contexts = contexts; - } - - public Resource[] getContexts() { - return contexts; - } - - public Collection getStatements() { - Collection statements = new ArrayList(); - - if (getContexts() != null && getContexts().length > 1) { - for (Resource contxt : getContexts()) { - statements.add(VF.createStatement(getSubject(), - getPredicate(), getObject(), contxt)); - } - } else - statements.add(this); - - return statements; - } - - @Override - public Resource getContext() { - if (contexts == null || contexts.length == 0) - return null; - else return contexts[0]; - } -} diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/ExecuteSparqlQuery.java b/common/rya.api/src/main/java/org/apache/rya/api/client/ExecuteSparqlQuery.java index 212399a41..723b9bdf1 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/client/ExecuteSparqlQuery.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/ExecuteSparqlQuery.java @@ -18,13 +18,12 @@ */ package org.apache.rya.api.client; -import java.io.Closeable; - +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.eclipse.rdf4j.query.BindingSet; import org.eclipse.rdf4j.query.TupleQueryResult; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import java.io.Closeable; /** * Loads a SPARQL Query and executes the query against an instance of Rya. @@ -41,5 +40,6 @@ public interface ExecuteSparqlQuery extends Closeable { * @throws InstanceDoesNotExistException No instance of Rya exists for the provided name. * @throws RyaClientException Something caused the command to fail. */ - public TupleQueryResult executeSparqlQuery(String ryaInstanceName, String sparqlQuery) throws InstanceDoesNotExistException, RyaClientException; + TupleQueryResult executeSparqlQuery(String ryaInstanceName, String sparqlQuery) throws InstanceDoesNotExistException, RyaClientException; + } \ No newline at end of file diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeIRI.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeIRI.java index 84b38d1e1..34ee3a40f 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeIRI.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeIRI.java @@ -20,8 +20,8 @@ */ - import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; /** * Created by IntelliJ IDEA. @@ -29,14 +29,14 @@ * Time: 1:03 PM * To change this template use File | Settings | File Templates. */ -public class RangeIRI extends RangeValue implements IRI { +public class RangeIRI extends RangeValue implements IRI { - public RangeIRI(IRI start, IRI end) { + public RangeIRI(Resource start, Resource end) { super(start, end); } - public RangeIRI(RangeValue rangeValue) { - super((IRI) rangeValue.getStart(), (IRI) rangeValue.getEnd()); + public RangeIRI(RangeValue rangeValue) { + super(rangeValue.getStart(), rangeValue.getEnd()); } @Override diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaIRI.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaIRI.java index 8909b056f..b46e73209 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaIRI.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaIRI.java @@ -19,6 +19,7 @@ * under the License. */ +import org.apache.rya.api.resolver.RyaToRdfConversions; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.util.URIUtil; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; @@ -28,7 +29,7 @@ * Date: 7/16/12 * Time: 11:56 AM */ -public class RyaIRI extends RyaType { +public class RyaIRI extends RyaType implements RyaResource, IRI { public RyaIRI() { setDataType(XMLSchema.ANYURI); @@ -58,4 +59,19 @@ protected void validate(String data) { URIUtil.getLocalNameIndex(data); } + @Override + public String getNamespace() { + return RyaToRdfConversions.convertIRI(this).getNamespace(); + } + + @Override + public String getLocalName() { + return RyaToRdfConversions.convertIRI(this).getLocalName(); + } + + @Override + public String stringValue() { + return RyaToRdfConversions.convertIRI(this).stringValue(); + } + } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaIRIRange.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaIRIRange.java index 177048eb5..7243c677a 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaIRIRange.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaIRIRange.java @@ -20,6 +20,8 @@ */ +import org.apache.rya.api.resolver.RdfToRyaConversions; +import org.eclipse.rdf4j.model.Resource; /** * Date: 7/17/12 @@ -28,31 +30,35 @@ public class RyaIRIRange extends RyaIRI implements RyaRange { public static final RyaIRI LAST_IRI = new RyaIRI(((char) 255) + ":#" + ((char) 255)); - private RyaIRI start; - private RyaIRI stop; + private RyaResource start; + private RyaResource stop; public RyaIRIRange() { super(); } - public RyaIRIRange(RyaIRI start, RyaIRI stop) { + public RyaIRIRange(Resource start, Resource stop) { + this(RdfToRyaConversions.convertResource(start), RdfToRyaConversions.convertResource(stop)); + } + + public RyaIRIRange(RyaResource start, RyaResource stop) { this.start = start; this.stop = stop; } - public RyaIRI getStart() { + public RyaResource getStart() { return start; } - public void setStart(RyaIRI start) { + public void setStart(RyaResource start) { this.start = start; } - public RyaIRI getStop() { + public RyaResource getStop() { return stop; } - public void setStop(RyaIRI stop) { + public void setStop(RyaResource stop) { this.stop = stop; } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaRange.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaRange.java index 15d57161d..553e9dbb5 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaRange.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaRange.java @@ -26,7 +26,7 @@ * Time: 10:02 AM */ public interface RyaRange { - public RyaType getStart(); + RyaValue getStart(); - public RyaType getStop(); + RyaValue getStop(); } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaResource.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaResource.java new file mode 100644 index 000000000..c831dea3c --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaResource.java @@ -0,0 +1,25 @@ +/* + * 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.rya.api.domain; + +import org.eclipse.rdf4j.model.Resource; + +public interface RyaResource extends RyaValue, Resource { + // Empty place holder as common supertype of IRI and BNode +} diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaStatement.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaStatement.java index 4d870a829..ea5a013a0 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaStatement.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaStatement.java @@ -18,6 +18,14 @@ */ package org.apache.rya.api.domain; +import org.apache.log4j.Logger; +import org.apache.rya.api.resolver.RdfToRyaConversions; +import org.apache.rya.api.resolver.RyaToRdfConversions; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; + import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -26,61 +34,95 @@ * Time: 7:20 AM */ public class RyaStatement { - private RyaIRI subject; + + private static final Logger logger = Logger.getLogger(RyaStatement.class); + + private RyaResource subject; private RyaIRI predicate; - private RyaType object; - private RyaIRI context; + private RyaValue object; + private RyaResource context; private String qualifer; private byte[] columnVisibility; private byte[] value; private Long timestamp; public RyaStatement() { + this(null, null, null); } - public RyaStatement(final RyaIRI subject, final RyaIRI predicate, final RyaType object) { + public RyaStatement(Resource subject, IRI predicate, Value object) { this(subject, predicate, object, null); } - public RyaStatement(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context) { - this(subject, predicate, object, context, null); + public RyaStatement(Resource subject, IRI predicate, Value object, Resource context) { + this(RdfToRyaConversions.convertResource(subject), RdfToRyaConversions.convertIRI(predicate), RdfToRyaConversions.convertValue(object), RdfToRyaConversions.convertResource(context)); + } + + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object) { + this(subject, predicate, object, null, null, new StatementMetadata()); + } + + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final Long timestamp) { + this(subject, predicate, object, null, timestamp); + } + + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context) { + this(subject, predicate, object, context, null, new StatementMetadata()); } + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context, final Long timestamp) { + this(subject, predicate, object, context, null, "".getBytes(StandardCharsets.UTF_8), (byte[]) null, timestamp); + } - public RyaStatement(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context, final String qualifier) { + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context, final String qualifier) { this(subject, predicate, object, context, qualifier, new StatementMetadata()); } - public RyaStatement(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context, final String qualifier, final StatementMetadata metadata) { - this(subject, predicate, object, context, qualifier, metadata, null); + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context, final String qualifier, final StatementMetadata metadata) { + this(subject, predicate, object, context, qualifier, metadata, "".getBytes(StandardCharsets.UTF_8)); } - public RyaStatement(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context, final String qualifier, final StatementMetadata metadata, final byte[] columnVisibility) { - this(subject, predicate, object, context, qualifier, columnVisibility, metadata.toBytes()); + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context, final String qualifier, final StatementMetadata metadata, final byte[] columnVisibility) { + this(subject, predicate, object, context, qualifier, metadata, columnVisibility, null); } - @Deprecated - public RyaStatement(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context, final String qualifier, final byte[] columnVisibility, final byte[] value) { + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context, final String qualifier, final StatementMetadata metadata, final byte[] columnVisibility, final Long timestamp) { + this(subject, predicate, object, context, qualifier, columnVisibility, metadata, timestamp); + } + + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context, final String qualifier, final byte[] columnVisibility, final byte[] value) { this(subject, predicate, object, context, qualifier, columnVisibility, value, null); } - @Deprecated - public RyaStatement(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context, final String qualifier, final byte[] columnVisibility, final byte[] value, final Long timestamp) { + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context, final String qualifier, final byte[] columnVisibility, final StatementMetadata value, final Long timestamp) { + this(subject, predicate, object, context, qualifier, columnVisibility, value != null ? value.toBytes() : null, timestamp); + } + + public RyaStatement(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context, final String qualifier, final byte[] columnVisibility, final byte[] value, final Long timestamp) { this.subject = subject; this.predicate = predicate; this.object = object; this.context = context; this.qualifer = qualifier; this.columnVisibility = columnVisibility; - this.value = value; + { + // Do not serialise and deserialise the value from JSON because this significantly slows down queries (~35%) + if (value != null) { + this.value = value; + } + // Never allow value to be null, because Accumulo can't tell the difference between null and new byte[0] + if (this.value == null) { + this.value = "".getBytes(StandardCharsets.UTF_8); + } + } this.timestamp = timestamp != null ? timestamp : System.currentTimeMillis(); } - public RyaIRI getSubject() { + public RyaResource getSubject() { return subject; } - public void setSubject(final RyaIRI subject) { + public void setSubject(final RyaResource subject) { this.subject = subject; } @@ -92,19 +134,19 @@ public void setPredicate(final RyaIRI predicate) { this.predicate = predicate; } - public RyaType getObject() { + public RyaValue getObject() { return object; } - public void setObject(final RyaType object) { + public void setObject(final RyaValue object) { this.object = object; } - public RyaIRI getContext() { + public RyaResource getContext() { return context; } - public void setContext(final RyaIRI context) { + public void setContext(final RyaResource context) { this.context = context; } @@ -121,14 +163,18 @@ public StatementMetadata getMetadata() { // no explicit metadata try { return new StatementMetadata(value); - } - catch (final Exception ex){ - return null; + } catch (final Exception ex) { + logger.error("Error converting value to StatementMetadata: ", ex); + return new StatementMetadata(); } } public void setStatementMetadata(final StatementMetadata metadata){ - this.value = metadata.toBytes(); + if (metadata == null) { + this.value = new byte[0]; + } else { + this.value = metadata.toBytes(); + } } @Deprecated @@ -233,7 +279,6 @@ public static RyaStatementBuilder builder(final RyaStatement ryaStatement) { return new RyaStatementBuilder(ryaStatement); } - //builder public static class RyaStatementBuilder { @@ -259,7 +304,11 @@ public RyaStatementBuilder setValue(final byte[] value) { } public RyaStatementBuilder setMetadata(final StatementMetadata metadata) { - ryaStatement.setValue(metadata.toBytes()); + if (metadata == null) { + ryaStatement.setValue(new byte[0]); + } else { + ryaStatement.setValue(metadata.toBytes()); + } return this; } @@ -273,12 +322,12 @@ public RyaStatementBuilder setQualifier(final String str) { return this; } - public RyaStatementBuilder setContext(final RyaIRI ryaIRI) { + public RyaStatementBuilder setContext(final RyaResource ryaIRI) { ryaStatement.setContext(ryaIRI); return this; } - public RyaStatementBuilder setSubject(final RyaIRI ryaIRI) { + public RyaStatementBuilder setSubject(final RyaResource ryaIRI) { ryaStatement.setSubject(ryaIRI); return this; } @@ -288,7 +337,7 @@ public RyaStatementBuilder setPredicate(final RyaIRI ryaIRI) { return this; } - public RyaStatementBuilder setObject(final RyaType ryaType) { + public RyaStatementBuilder setObject(final RyaValue ryaType) { ryaStatement.setObject(ryaType); return this; } @@ -297,4 +346,9 @@ public RyaStatement build() { return ryaStatement; } } + + public Statement toStatement() { + return RyaToRdfConversions.convertStatement(this); + } + } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaType.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaType.java index e40c8d62d..e35ba98b0 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaType.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaType.java @@ -18,23 +18,26 @@ */ package org.apache.rya.api.domain; -import java.util.Objects; - import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.rya.api.resolver.RyaToRdfConversions; import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; +import java.util.Objects; + /** * Base Rya Type * Date: 7/16/12 * Time: 11:45 AM */ -public class RyaType implements Comparable { +public class RyaType implements Comparable, RyaValue { - private IRI dataType; - private String data; - private String language; + protected IRI dataType; + protected String data; + protected String language; /** * Creates a new instance of {@link RyaType}. @@ -111,38 +114,34 @@ public void setLanguage(final String language) { @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("RyaType"); - sb.append("{dataType=").append(dataType); - sb.append(", data='").append(data).append('\''); - if (language != null) { - sb.append(", language='").append(language).append('\''); - } - sb.append('}'); - return sb.toString(); + return stringValue(); } /** * Determine equality based on string representations of data, datatype, and - * language. + * language. Fallback to standard RDF equals if the compared object is not a RyaType. * @param o The object to compare with * @return {@code true} if the other object is also a RyaType and the data, - * datatype, and language all match. + * datatype, and language all match. Also return true if {@param o} is a {@link Resource} with the same value. */ @Override public boolean equals(final Object o) { if (this == o) { return true; } - if (o == null || !(o instanceof RyaType)) { + if (!(o instanceof Value)) { return false; } - final RyaType other = (RyaType) o; - final EqualsBuilder builder = new EqualsBuilder() - .append(getData(), other.getData()) - .append(getDataType(), other.getDataType()) - .append(getLanguage(), other.getLanguage()); - return builder.isEquals(); + if (o instanceof RyaType) { + final RyaType other = (RyaType) o; + final EqualsBuilder builder = new EqualsBuilder() + .append(getData(), other.getData()) + .append(getDataType(), other.getDataType()) + .append(getLanguage(), other.getLanguage()); + return builder.isEquals(); + } + // Fall back to the equals method of the Value class. + return (((Value) o).stringValue()).equals(this.stringValue()); } /** @@ -176,4 +175,10 @@ public int compareTo(final RyaType o) { .append(getLanguage(), o.getLanguage()); return builder.toComparison(); } + + @Override + public String stringValue() { + return RyaToRdfConversions.convertLiteral(this).stringValue(); + } + } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaTypeRange.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaTypeRange.java index 38d57f5fe..c0e9a41d8 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaTypeRange.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaTypeRange.java @@ -28,30 +28,30 @@ * Time: 9:53 AM */ public class RyaTypeRange extends RyaType implements RyaRange { - private RyaType start; - private RyaType stop; + private RyaValue start; + private RyaValue stop; public RyaTypeRange() { } - public RyaTypeRange(RyaType start, RyaType stop) { + public RyaTypeRange(RyaValue start, RyaValue stop) { this.start = start; this.stop = stop; } - public RyaType getStart() { + public RyaValue getStart() { return start; } - public void setStart(RyaType start) { + public void setStart(RyaValue start) { this.start = start; } - public RyaType getStop() { + public RyaValue getStop() { return stop; } - public void setStop(RyaType stop) { + public void setStop(RyaValue stop) { this.stop = stop; } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaValue.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaValue.java new file mode 100644 index 000000000..1de594c09 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaValue.java @@ -0,0 +1,42 @@ +/* + * 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.rya.api.domain; + +import org.eclipse.rdf4j.model.BNode; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.Value; + +import java.io.Serializable; + +public interface RyaValue extends Serializable, Value { + + /** + * Returns the String-value of a Value object. This returns either a {@link Literal}'s label, a + * {@link IRI}'s URI or a {@link BNode}'s ID. + */ + String stringValue(); + + String getData(); + + IRI getDataType(); + + String getLanguage(); + +} diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/StatementMetadata.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/StatementMetadata.java index 13e656aec..62a61fb07 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/domain/StatementMetadata.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/StatementMetadata.java @@ -18,14 +18,6 @@ */ package org.apache.rya.api.domain; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.rya.api.persist.RdfDAOException; -import org.eclipse.rdf4j.model.impl.SimpleValueFactory; - import com.google.common.base.Preconditions; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; @@ -38,16 +30,24 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import org.apache.rya.api.persist.RdfDAOException; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; + +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; public class StatementMetadata { - private static Gson gson = new GsonBuilder().enableComplexMapKeySerialization() + private final static Gson gson = new GsonBuilder().enableComplexMapKeySerialization() .registerTypeHierarchyAdapter(RyaType.class, new RyaTypeAdapter()).create(); public static StatementMetadata EMPTY_METADATA = new StatementMetadata(); - private Map metadataMap = new HashMap<>(); + private Map metadataMap = new HashMap<>(); @SuppressWarnings("serial") - private Type type = new TypeToken>(){}.getType(); + private final Type type = new TypeToken>(){}.getType(); public StatementMetadata() {} @@ -77,11 +77,11 @@ public StatementMetadata(String statementMetadata) { } } - public void addMetadata(RyaIRI key, RyaType value) { + public void addMetadata(RyaIRI key, RyaValue value) { metadataMap.put(key, value); } - public Map getMetadata() { + public Map getMetadata() { return metadataMap; } @@ -92,19 +92,15 @@ public String toString() { public byte[] toBytes() { // convert the map to a json string if (metadataMap.isEmpty()) { - return null; + return new byte[0]; } // TODO may want to cache this for performance reasons - try { - return toString().getBytes("UTF8"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + return toString().getBytes(StandardCharsets.UTF_8); } - public static class RyaTypeAdapter implements JsonSerializer, JsonDeserializer { + public static class RyaTypeAdapter implements JsonSerializer, JsonDeserializer { @Override - public JsonElement serialize(RyaType src, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(RyaValue src, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.add("type", new JsonPrimitive(src.getClass().getName())); @@ -116,7 +112,7 @@ public JsonElement serialize(RyaType src, Type typeOfSrc, JsonSerializationConte } @Override - public RyaType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + public RyaValue deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String type = jsonObject.get("type").getAsString(); @@ -127,7 +123,7 @@ public RyaType deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo if(type.equals(RyaIRI.class.getName())){ return new RyaIRI(array[0]); } else if(type.equals(RyaType.class.getName())){ - RyaType ryaType = new RyaType(SimpleValueFactory.getInstance().createIRI(array[1]), array[0]); + RyaValue ryaType = new RyaType(SimpleValueFactory.getInstance().createIRI(array[1]), array[0]); return ryaType; } else { throw new IllegalArgumentException("Unparseable RyaType."); diff --git a/common/rya.api/src/main/java/org/apache/rya/api/instance/RyaDetails.java b/common/rya.api/src/main/java/org/apache/rya/api/instance/RyaDetails.java index bda739038..645796774 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/instance/RyaDetails.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/instance/RyaDetails.java @@ -18,7 +18,13 @@ */ package org.apache.rya.api.instance; -import static java.util.Objects.requireNonNull; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; +import net.jcip.annotations.Immutable; import java.io.Serializable; import java.util.ArrayList; @@ -29,14 +35,7 @@ import java.util.Map.Entry; import java.util.Objects; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; -import net.jcip.annotations.Immutable; +import static java.util.Objects.requireNonNull; /** * Details about how a Rya instance's state. @@ -221,7 +220,7 @@ public static Builder builder() { } /** - * @param detials - The builder will be initialized with this object's values. (not null) + * @param details - The builder will be initialized with this object's values. (not null) * @return An instance of {@link Builder} that is initialized with a {@link RyaDetails}'s values. */ public static Builder builder(final RyaDetails details) { @@ -262,7 +261,7 @@ public Builder() { } * Constructs an instance of {@link Builder} that is initialized with * a {@link RyaDetails}'s values. * - * @param detials - The builder will be initialized with this object's values. (not null) + * @param details - The builder will be initialized with this object's values. (not null) */ public Builder(final RyaDetails details) { requireNonNull(details); @@ -355,7 +354,7 @@ public Builder setFreeTextDetails(@Nullable final FreeTextIndexDetails freeTextD } /** - * @param pcjDetails - Information about the instance's Precomputed Join Index. + * @param pcjDetailsBuilder - Information about the instance's Precomputed Join Index. * @return This {@link Builder} so that method invocations may be chained. */ public Builder setPCJIndexDetails(@Nullable final PCJIndexDetails.Builder pcjDetailsBuilder) { @@ -676,7 +675,7 @@ public static Builder builder() { } /** - * @param detials - The builder will be initialized with this object's values. (not null) + * @param pcjIndexDetails - The builder will be initialized with this object's values. (not null) * @return An instance of {@link Builder} that is initialized with a {@link PCJIndexDetails}'s values. */ public static Builder builder(final PCJIndexDetails pcjIndexDetails) { @@ -735,7 +734,7 @@ public Builder setFluoDetails(@Nullable final FluoDetails fluoDetails) { } /** - * @param pcjDetails - Details about the PCJs that have been created for this Rya instance. + * @param pcjDetailsBuilder - Details about the PCJs that have been created for this Rya instance. * @return This {@link Builder} so that method invocations may be chained. */ public Builder addPCJDetails(@Nullable final PCJDetails.Builder pcjDetailsBuilder) { @@ -896,7 +895,7 @@ public static Builder builder() { } /** - * @param detials - The builder will be initialized with this object's values. (not null) + * @param details - The builder will be initialized with this object's values. (not null) * @return An instance of {@link Builder} that is initialized with a {@link PCJDetails}' values. */ public static Builder builder(final PCJDetails details) { diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/RyaDAO.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/RyaDAO.java index 2820beb98..5aab03235 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/RyaDAO.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/RyaDAO.java @@ -20,14 +20,13 @@ */ - -import java.util.Iterator; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.persist.query.RyaQueryEngine; +import java.util.Iterator; + /** * Provides the access layer to the Rya triple store. * @@ -89,7 +88,7 @@ public interface RyaDAO extends RyaC * @param conf * @throws RyaDAOException */ - public void dropGraph(C conf, RyaIRI... graphs) throws RyaDAOException; + public void dropGraph(C conf, RyaResource... graphs) throws RyaDAOException; /** * Delete a collection of RyaStatements. diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/RyaDAOException.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/RyaDAOException.java index c8dedc142..3b44a1c65 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/RyaDAOException.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/RyaDAOException.java @@ -20,12 +20,13 @@ */ +import org.eclipse.rdf4j.query.QueryEvaluationException; /** * Date: 7/17/12 * Time: 8:20 AM */ -public class RyaDAOException extends Exception { +public class RyaDAOException extends QueryEvaluationException { public RyaDAOException() { } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/BatchRyaQuery.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/BatchRyaQuery.java index 56302892e..434dc594f 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/BatchRyaQuery.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/BatchRyaQuery.java @@ -19,32 +19,44 @@ * under the License. */ - - -import com.google.common.base.Preconditions; import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import org.apache.rya.api.domain.RyaStatement; +import java.util.Objects; + /** * Query domain object contains the query to run as a {@link org.apache.rya.api.domain.RyaStatement} and options for running the query */ -public class BatchRyaQuery extends RyaQueryOptions { +@Deprecated +public class BatchRyaQuery extends RyaQuery { - //queries - private Iterable queries; - - //maximum number of ranges before we use a batchScanner - private int maxRanges = 2; + // Maximum number of ranges before we use a batchScanner + private int maxRanges = 2; // TODO: What purpose does this provide? public BatchRyaQuery(Iterable queries) { - Preconditions.checkNotNull(queries, "RyaStatement queries cannot be null"); - this.queries = queries; + super(queries); } public static RyaBatchQueryBuilder builder(Iterable queries) { return new RyaBatchQueryBuilder(queries); } + public static BatchRyaQuery fromRyaQuery(RyaQuery ryaQuery) { + return BatchRyaQuery.builder(Lists.newArrayList(ryaQuery.getQueries())) + .setAuths(ryaQuery.getAuths()) + .setBatchSize(ryaQuery.getBatchSize()) + .setCurrentTime(ryaQuery.getCurrentTime()) + .setMaxRanges(1) + .setMaxResults(ryaQuery.getMaxResults()) + .setNumQueryThreads(ryaQuery.getNumQueryThreads()) + .setRegexObject(ryaQuery.getRegexObject()) + .setRegexPredicate(ryaQuery.getRegexPredicate()) + .setRegexSubject(ryaQuery.getRegexSubject()) + .setTtl(ryaQuery.getTtl()) + .build(); + } + public static class RyaBatchQueryBuilder extends RyaOptionsBuilder { private BatchRyaQuery ryaQuery; @@ -67,14 +79,6 @@ public BatchRyaQuery build() { } } - public Iterable getQueries() { - return queries; - } - - public void setQueries(Iterable queries) { - this.queries = queries; - } - public int getMaxRanges() { return maxRanges; } @@ -91,7 +95,7 @@ public boolean equals(Object o) { BatchRyaQuery that = (BatchRyaQuery) o; - return queries != null ? queries.equals(that.queries) : that.queries == null; + return Objects.equals(queries, that.queries); } @Override diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/RyaQuery.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/RyaQuery.java index c56b5e99d..ff3ec478a 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/RyaQuery.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/RyaQuery.java @@ -19,22 +19,30 @@ * under the License. */ - - import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; import org.apache.rya.api.domain.RyaStatement; +import java.util.Collections; +import java.util.Objects; + /** * Query domain object contains the query to run as a {@link RyaStatement} and options for running the query */ +@Deprecated public class RyaQuery extends RyaQueryOptions { - //query - private RyaStatement query; + protected Iterable queries; public RyaQuery(RyaStatement query) { - Preconditions.checkNotNull(query, "RyaStatement query cannot be null"); - this.query = query; + Preconditions.checkNotNull(query, "Statement query cannot be null"); + this.queries = Collections.singleton(query); + } + + protected RyaQuery(Iterable queries) { + Preconditions.checkNotNull(queries, "Statement queries cannot be null"); + Preconditions.checkState(queries.iterator().hasNext(), "Statement queries cannot be empty"); + this.queries = queries; } public static RyaQueryBuilder builder(RyaStatement query) { @@ -59,11 +67,15 @@ public RyaQuery build() { } public RyaStatement getQuery() { - return query; + return queries.iterator().next(); + } + + public Iterable getQueries() { + return queries; } - public void setQuery(RyaStatement query) { - this.query = query; + public void setQueries(Iterable queries) { + this.queries = queries; } @Override @@ -72,24 +84,22 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - RyaQuery ryaQuery = (RyaQuery) o; - - if (query != null ? !query.equals(ryaQuery.query) : ryaQuery.query != null) return false; + BatchRyaQuery that = (BatchRyaQuery) o; - return true; + return Objects.equals(queries, that.queries); } @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + (query != null ? query.hashCode() : 0); + result = 31 * result + (queries != null ? queries.hashCode() : 0); return result; } @Override public String toString() { return "RyaQuery{" + - "query=" + query + + "query=" + Iterables.toString(queries) + "options={" + super.toString() + '}' + '}'; diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/HashJoin.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/HashJoin.java index 209e9d84a..a092f2f2e 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/HashJoin.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/HashJoin.java @@ -19,20 +19,23 @@ * under the License. */ -import java.util.Enumeration; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.query.RyaQueryEngine; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.utils.EnumerationWrapper; import org.eclipse.rdf4j.common.iteration.CloseableIteration; +import org.eclipse.rdf4j.query.QueryEvaluationException; + +import java.util.Enumeration; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Use HashTable to do a HashJoin. @@ -44,30 +47,30 @@ public class HashJoin implements Join { private RyaContext ryaContext = RyaContext.getInstance(); - private RyaQueryEngine ryaQueryEngine; + private RyaQueryEngine ryaQueryEngine; public HashJoin() { } - public HashJoin(RyaQueryEngine ryaQueryEngine) { + public HashJoin(RyaQueryEngine ryaQueryEngine) { this.ryaQueryEngine = ryaQueryEngine; } @Override public CloseableIteration join(C conf, RyaIRI... preds) throws RyaDAOException { - ConcurrentHashMap, Integer> ht = new ConcurrentHashMap, Integer>(); + ConcurrentHashMap, Integer> ht = new ConcurrentHashMap<>(); int count = 0; boolean first = true; for (RyaIRI pred : preds) { count++; //query - CloseableIteration results = ryaQueryEngine.query(new RyaStatement(null, pred, null), null); + CloseableIteration results = RyaDAOHelper.query(ryaQueryEngine, new RyaStatement(null, pred, null), conf); //add to hashtable while (results.hasNext()) { RyaStatement next = results.next(); - RyaIRI subject = next.getSubject(); - RyaType object = next.getObject(); - Map.Entry entry = new RdfCloudTripleStoreUtils.CustomEntry(subject, object); + RyaResource subject = next.getSubject(); + RyaValue object = next.getObject(); + Map.Entry entry = new RdfCloudTripleStoreUtils.CustomEntry<>(subject, object); if (!first) { if (!ht.containsKey(entry)) { continue; //not in join @@ -79,14 +82,14 @@ public CloseableIteration join(C conf, RyaIRI... if (first) { first = false; } else { - for (Map.Entry, Integer> entry : ht.entrySet()) { + for (Map.Entry, Integer> entry : ht.entrySet()) { if (entry.getValue() < count) { ht.remove(entry.getKey()); } } } } - final Enumeration> keys = ht.keys(); + final Enumeration> keys = ht.keys(); return new CloseableIteration() { @Override public void close() throws RyaDAOException { @@ -100,7 +103,7 @@ public boolean hasNext() throws RyaDAOException { @Override public RyaStatement next() throws RyaDAOException { - Map.Entry subjObj = keys.nextElement(); + Map.Entry subjObj = keys.nextElement(); return new RyaStatement(subjObj.getKey(), null, subjObj.getValue()); } @@ -112,19 +115,19 @@ public void remove() throws RyaDAOException { } @Override - public CloseableIteration join(C conf, Map.Entry... predObjs) throws RyaDAOException { - ConcurrentHashMap ht = new ConcurrentHashMap(); + public CloseableIteration join(C conf, Map.Entry... predObjs) throws QueryEvaluationException { + ConcurrentHashMap ht = new ConcurrentHashMap<>(); int count = 0; boolean first = true; - for (Map.Entry predObj : predObjs) { + for (Map.Entry predObj : predObjs) { count++; RyaIRI pred = predObj.getKey(); - RyaType obj = predObj.getValue(); + RyaValue obj = predObj.getValue(); //query - CloseableIteration results = ryaQueryEngine.query(new RyaStatement(null, pred, obj), null); + CloseableIteration results = RyaDAOHelper.query(ryaQueryEngine, new RyaStatement(null, pred, obj), conf); //add to hashtable while (results.hasNext()) { - RyaIRI subject = results.next().getSubject(); + RyaResource subject = results.next().getSubject(); if (!first) { if (!ht.containsKey(subject)) { continue; //not in join @@ -136,14 +139,14 @@ public CloseableIteration join(C conf, Map.Entry entry : ht.entrySet()) { + for (Map.Entry entry : ht.entrySet()) { if (entry.getValue() < count) { ht.remove(entry.getKey()); } } } } - return new EnumerationWrapper(ht.keys()); + return new EnumerationWrapper<>(ht.keys()); } public RyaQueryEngine getRyaQueryEngine() { diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/IterativeJoin.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/IterativeJoin.java index 3c1d65938..f15b964be 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/IterativeJoin.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/IterativeJoin.java @@ -19,23 +19,24 @@ * under the License. */ -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; - +import com.google.common.base.Preconditions; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.query.RyaQueryEngine; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RyaContext; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.common.iteration.ConvertingIteration; import org.eclipse.rdf4j.query.BindingSet; -import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; /** * Date: 7/24/12 @@ -54,7 +55,7 @@ public IterativeJoin(RyaQueryEngine ryaQueryEngine) { } /** - * Return all statements that have input predicates. Predicates must not be null or ranges + * Return all statements that have input predicates. Predicates must not be null or ranges. * * @param preds * @return @@ -64,12 +65,12 @@ public CloseableIteration join(C conf, RyaIRI... throws RyaDAOException { Preconditions.checkNotNull(preds); Preconditions.checkArgument(preds.length > 1, "Must join 2 or more"); - //TODO: Reorder predObjs based on statistics + // TODO: Reorder predObjs based on statistics CloseableIteration iter = null; for (RyaIRI pred : preds) { if (iter == null) { - iter = ryaQueryEngine.query(new RyaStatement(null, pred, null), null); + iter = RyaDAOHelper.query(ryaQueryEngine, new RyaStatement(null, pred, null), conf); } else { iter = join(iter, pred); } @@ -79,8 +80,7 @@ public CloseableIteration join(C conf, RyaIRI... } /** - * Return all subjects that have the predicate objects associated. Predicate and objects must be not null or ranges - * to ensure sorting + * Return all subjects that have the predicate and object associated. * * @param predObjs * @return @@ -88,24 +88,25 @@ public CloseableIteration join(C conf, RyaIRI... * */ @Override - public CloseableIteration join(C conf, Map.Entry... predObjs) + public CloseableIteration join(C conf, Map.Entry... predObjs) throws RyaDAOException { Preconditions.checkNotNull(predObjs); Preconditions.checkArgument(predObjs.length > 1, "Must join 2 or more"); - //TODO: Reorder predObjs based on statistics + // TODO: Reorder predObjs based on statistics CloseableIteration first = null; - CloseableIteration iter = null; - for (Map.Entry entry : predObjs) { + CloseableIteration iter = null; + for (Map.Entry entry : predObjs) { if (first == null) { - first = ryaQueryEngine.query(new RyaStatement(null, entry.getKey(), entry.getValue()), null); + first = RyaDAOHelper.query(ryaQueryEngine, new RyaStatement(null, entry.getKey(), entry.getValue()), conf); } else if (iter == null) { - iter = join(new ConvertingIteration(first) { + iter = join(new ConvertingIteration(first) { @Override - protected RyaIRI convert(RyaStatement statement) throws RyaDAOException { + protected RyaResource convert(RyaStatement statement) throws RyaDAOException { return statement.getSubject(); } + }, entry); } else { iter = join(iter, entry); @@ -115,12 +116,12 @@ protected RyaIRI convert(RyaStatement statement) throws RyaDAOException { return iter; } - protected CloseableIteration join(final CloseableIteration iteration, - final Map.Entry predObj) { - //TODO: configure batch - //TODO: batch = 1, does not work + protected CloseableIteration join(final CloseableIteration iteration, + final Map.Entry predObj) { + // TODO: configure batch + // TODO: batch = 1, does not work final int batch = 100; - return new CloseableIteration() { + return new CloseableIteration() { private CloseableIteration, RyaDAOException> query; @@ -138,7 +139,7 @@ public boolean hasNext() throws RyaDAOException { } @Override - public RyaIRI next() throws RyaDAOException { + public RyaResource next() throws RyaDAOException { if (query == null || !query.hasNext()) { if (!batchNext()) return null; } @@ -153,9 +154,9 @@ private boolean batchNext() throws RyaDAOException { if (!iteration.hasNext()) { return false; } - Collection> batchedResults = new ArrayList>(); + Collection> batchedResults = new ArrayList<>(); for (int i = 0; i < batch && iteration.hasNext(); i++) { - batchedResults.add(new RdfCloudTripleStoreUtils.CustomEntry( + batchedResults.add(new RdfCloudTripleStoreUtils.CustomEntry<>( new RyaStatement(iteration.next(), predObj.getKey(), predObj.getValue()), null)); } query = ryaQueryEngine.queryWithBindingSet(batchedResults, null); @@ -171,8 +172,8 @@ public void remove() throws RyaDAOException { protected CloseableIteration join( final CloseableIteration iteration, final RyaIRI pred) { - //TODO: configure batch - //TODO: batch = 1, does not work + // TODO: configure batch + // TODO: batch = 1, does not work final int batch = 100; return new CloseableIteration() { @@ -207,10 +208,10 @@ private boolean batchNext() throws RyaDAOException { if (!iteration.hasNext()) { return false; } - Collection> batchedResults = new ArrayList>(); + Collection> batchedResults = new ArrayList<>(); for (int i = 0; i < batch && iteration.hasNext(); i++) { RyaStatement next = iteration.next(); - batchedResults.add(new RdfCloudTripleStoreUtils.CustomEntry( + batchedResults.add(new RdfCloudTripleStoreUtils.CustomEntry<>( new RyaStatement(next.getSubject(), pred, next.getObject()), null)); } query = ryaQueryEngine.queryWithBindingSet(batchedResults, null); @@ -231,4 +232,5 @@ public RyaQueryEngine getRyaQueryEngine() { public void setRyaQueryEngine(RyaQueryEngine ryaQueryEngine) { this.ryaQueryEngine = ryaQueryEngine; } + } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/Join.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/Join.java index 21ce1a267..07a9e05bc 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/Join.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/Join.java @@ -19,24 +19,31 @@ * under the License. */ -import java.util.Map; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.eclipse.rdf4j.common.iteration.CloseableIteration; +import java.util.Map; + /** * Date: 7/24/12 * Time: 4:28 PM */ public interface Join { + /** + * Returns the {@link RyaStatement}s matching a predicate. + */ public CloseableIteration join(C conf, RyaIRI... preds) throws RyaDAOException; - public CloseableIteration join(C conf, Map.Entry... predObjs) + /** + * Returns the subject given a predicate and object. + */ + public CloseableIteration join(C conf, Map.Entry... predObjs) throws RyaDAOException; } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/MergeJoin.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/MergeJoin.java index 327ff39c2..f21289107 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/MergeJoin.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/query/join/MergeJoin.java @@ -19,24 +19,25 @@ * under the License. */ -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - +import com.google.common.base.Preconditions; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.domain.RyaRange; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaIRIRange; +import org.apache.rya.api.domain.RyaRange; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.query.RyaQueryEngine; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.utils.PeekingCloseableIteration; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.common.iteration.EmptyIteration; -import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * Date: 7/24/12 @@ -65,12 +66,13 @@ public CloseableIteration join(C conf, RyaIRI... throws RyaDAOException { Preconditions.checkNotNull(preds); Preconditions.checkArgument(preds.length > 1, "Must join 2 or more"); - //TODO: Reorder predObjs based on statistics - final List> iters = new ArrayList>(); + // TODO: Reorder predObjs based on statistics + final List> iters = new ArrayList<>(); for (RyaIRI predicate : preds) { Preconditions.checkArgument(predicate != null && !(predicate instanceof RyaRange)); - CloseableIteration iter = ryaQueryEngine.query(new RyaStatement(null, predicate, null), conf); + CloseableIteration iter = RyaDAOHelper.query(ryaQueryEngine, + new RyaStatement(null, predicate, null), conf); iters.add(iter); } Preconditions.checkArgument(iters.size() > 1, "Must join 2 or more"); @@ -82,7 +84,7 @@ public CloseableIteration join(C conf, RyaIRI... return new CloseableIteration() { private RyaStatement first_stmt; - private RyaType first_obj; + private RyaValue first_obj; @Override public void close() throws RyaDAOException { @@ -122,12 +124,12 @@ protected boolean check() throws RyaDAOException { first_obj = first_stmt.getObject(); for (CloseableIteration iter : iters) { if (!iter.hasNext()) return false; //no more left to join - RyaType iter_obj = iter.next().getObject(); - while (first_obj.compareTo(iter_obj) < 0) { + RyaValue iter_obj = iter.next().getObject(); + while (first_obj.stringValue().compareTo(iter_obj.stringValue()) < 0) { if (!first.hasNext()) return false; first_obj = first.next().getObject(); } - while (first_obj.compareTo(iter_obj) > 0) { + while (first_obj.stringValue().compareTo(iter_obj.stringValue()) > 0) { if (!iter.hasNext()) return false; iter_obj = iter.next().getObject(); } @@ -146,30 +148,30 @@ protected boolean check() throws RyaDAOException { * @throws RyaDAOException */ @Override - public CloseableIteration join(C conf, Map.Entry... predObjs) + public CloseableIteration join(C conf, Map.Entry... predObjs) throws RyaDAOException { Preconditions.checkNotNull(predObjs); Preconditions.checkArgument(predObjs.length > 1, "Must join 2 or more"); - //TODO: Reorder predObjs based on statistics - final List> iters = new ArrayList>(); - RyaIRI earliest_subject = null; - for (Map.Entry predObj : predObjs) { + // TODO: Reorder predObjs based on statistics + final List> iters = new ArrayList<>(); + RyaResource earliest_subject = null; + for (Map.Entry predObj : predObjs) { RyaIRI predicate = predObj.getKey(); - RyaType object = predObj.getValue(); + RyaValue object = predObj.getValue(); Preconditions.checkArgument(predicate != null && !(predicate instanceof RyaRange)); Preconditions.checkArgument(object != null && !(object instanceof RyaRange)); PeekingCloseableIteration iter = null; if (earliest_subject == null) { - iter = new PeekingCloseableIteration( - ryaQueryEngine.query(new RyaStatement(null, predicate, object), conf)); + iter = new PeekingCloseableIteration<>( + RyaDAOHelper.query(ryaQueryEngine, new RyaStatement(null, predicate, object), conf)); } else { - iter = new PeekingCloseableIteration( - ryaQueryEngine.query(new RyaStatement(new RyaIRIRange(earliest_subject, RyaIRIRange.LAST_IRI), predicate, object), conf)); + iter = new PeekingCloseableIteration<>( + RyaDAOHelper.query(ryaQueryEngine, new RyaStatement(new RyaIRIRange(earliest_subject, RyaIRIRange.LAST_IRI), predicate, object), conf)); } if (!iter.hasNext()) { - return new EmptyIteration(); + return new EmptyIteration<>(); } //setting up range to make performant query earliest_subject = iter.peek().getSubject(); @@ -181,9 +183,9 @@ public CloseableIteration join(C conf, Map.Entry() { + return new CloseableIteration() { - private RyaIRI first_subj; + private RyaResource first_subj; @Override public void close() throws RyaDAOException { @@ -198,14 +200,14 @@ public boolean hasNext() throws RyaDAOException { } @Override - public RyaIRI next() throws RyaDAOException { + public RyaResource next() throws RyaDAOException { if (first_subj != null) { - RyaIRI temp = first_subj; + RyaResource temp = first_subj; first_subj = null; return temp; } if (check()) { - RyaIRI temp = first_subj; + RyaResource temp = first_subj; first_subj = null; return temp; } @@ -222,12 +224,12 @@ protected boolean check() throws RyaDAOException { first_subj = first.next().getSubject(); for (CloseableIteration iter : iters) { if (!iter.hasNext()) return false; //no more left to join - RyaIRI iter_subj = iter.next().getSubject(); - while (first_subj.compareTo(iter_subj) < 0) { + RyaResource iter_subj = iter.next().getSubject(); + while (first_subj.stringValue().compareTo(iter_subj.stringValue()) < 0) { if (!first.hasNext()) return false; first_subj = first.next().getSubject(); } - while (first_subj.compareTo(iter_subj) > 0) { + while (first_subj.stringValue().compareTo(iter_subj.stringValue()) > 0) { if (!iter.hasNext()) return false; iter_subj = iter.next().getSubject(); } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDAOHelper.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDAOHelper.java index 5b5978af6..56521af81 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDAOHelper.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDAOHelper.java @@ -19,19 +19,17 @@ * under the License. */ -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.NoSuchElementException; - +import com.google.common.base.Preconditions; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreUtils; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.persist.RyaDAO; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; +import org.apache.rya.api.persist.query.RyaQueryEngine; import org.apache.rya.api.resolver.RdfToRyaConversions; -import org.apache.rya.api.resolver.RyaToRdfConversions; -import org.apache.rya.api.utils.NullableStatementImpl; +import org.apache.rya.api.utils.WildcardStatement; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; @@ -40,135 +38,254 @@ import org.eclipse.rdf4j.query.BindingSet; import org.eclipse.rdf4j.query.QueryEvaluationException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; + /** - * Date: 7/20/12 - * Time: 10:36 AM + * TODO: Check there are sufficient unit tests in the DAOs to cover these methods... */ public class RyaDAOHelper { - public static CloseableIteration query(RyaDAO ryaDAO, Resource subject, IRI predicate, Value object, RdfCloudTripleStoreConfiguration conf, Resource... contexts) throws QueryEvaluationException { - return query(ryaDAO, new NullableStatementImpl(subject, predicate, object, contexts), conf); + /** + * This is a method used by {@link org.eclipse.rdf4j.query.algebra.evaluation.TripleSource}. + * @param queryEngine + * @param subject + * @param predicate + * @param object + * @param conf + * @param contexts + * @return + * @throws RyaDAOException + */ + public static CloseableIteration queryRdf4j(RyaQueryEngine queryEngine, Resource subject, IRI predicate, Value object, RdfCloudTripleStoreConfiguration conf, Resource... contexts) throws RyaDAOException { + Preconditions.checkState(!(subject instanceof RyaResource), "Defensive coding. This method shouldn't be used with Rya types."); + Preconditions.checkState(!(predicate instanceof RyaIRI), "Defensive coding. This method shouldn't be used with Rya types."); + Preconditions.checkState(!(object instanceof RyaValue), "Defensive coding. This method shouldn't be used with Rya types."); + Preconditions.checkState(!(contexts instanceof RyaResource[]), "Defensive coding. This method shouldn't be used with Rya types."); + Collection> statements = new ArrayList<>(1); + if (contexts != null && contexts.length > 0) { + for (Resource context : contexts) { + statements.add(new RdfCloudTripleStoreUtils.CustomEntry<>( + new WildcardStatement(subject, predicate, object, context), null)); + } + } else { + statements.add(new RdfCloudTripleStoreUtils.CustomEntry<>( + new WildcardStatement(subject, predicate, object), null)); + } + CloseableIteration, QueryEvaluationException> query = queryRdf4j(queryEngine, statements, conf); + // This translates from , QueryEvaluationException> to + return new CloseableIteration() { + + private boolean isClosed = false; + + @Override + public void close() throws RyaDAOException { + try { + isClosed = true; + query.close(); + } catch (RyaDAOException e) { + throw new RyaDAOException(e); + } + } + + @Override + public boolean hasNext() throws RyaDAOException { + try { + return query.hasNext(); + } catch (RyaDAOException e) { + throw new RyaDAOException(e); + } + } + + @Override + public Statement next() throws RyaDAOException { + if (!hasNext() || isClosed) { + throw new NoSuchElementException(); + } + + try { + Map.Entry next = query.next(); + if (next == null || next.getKey() == null) { + return null; + } + return next.getKey(); + } catch (RyaDAOException e) { + throw new RyaDAOException(e); + } + } + + @Override + public void remove() throws RyaDAOException { + try { + query.remove(); + } catch (RyaDAOException e) { + throw new RyaDAOException(e); + } + } + }; } - public static CloseableIteration query(RyaDAO ryaDAO, Statement stmt, RdfCloudTripleStoreConfiguration conf) throws QueryEvaluationException { - final CloseableIteration query; - try { - query = ryaDAO.getQueryEngine().query(RdfToRyaConversions.convertStatement(stmt), - conf); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + /** + * This is a method used by {@link org.eclipse.rdf4j.query.algebra.evaluation.TripleSource}. + * @param queryEngine + * @param statements + * @param conf + * @return + * @throws RyaDAOException + */ + public static CloseableIteration, QueryEvaluationException> queryRdf4j(RyaQueryEngine queryEngine, Collection> statements, RdfCloudTripleStoreConfiguration conf) throws RyaDAOException { + Preconditions.checkNotNull(conf, "Defensive coding. You should pass the configuration."); + Collection> ryaStatements = new ArrayList<>(statements.size()); + for (Map.Entry entry : statements) { + Statement statement = entry.getKey(); + BindingSet bindingSet = entry.getValue(); + ryaStatements.add(new RdfCloudTripleStoreUtils.CustomEntry<>(RdfToRyaConversions.convertStatement(statement), bindingSet)); } - //TODO: only support one context for now - return new CloseableIteration() { //TODO: Create a new class struct for this + CloseableIteration, RyaDAOException> query = queryEngine.queryWithBindingSet(ryaStatements, conf); + // This translates from , RyaDAOException> to , QueryEvaluationException> + return new CloseableIteration, QueryEvaluationException>() { private boolean isClosed = false; + @Override - public void close() throws QueryEvaluationException { + public void close() throws RyaDAOException { try { isClosed = true; query.close(); } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + throw new RyaDAOException(e); } } @Override - public boolean hasNext() throws QueryEvaluationException { + public boolean hasNext() throws RyaDAOException { try { return query.hasNext(); } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + throw new RyaDAOException(e); } } @Override - public Statement next() throws QueryEvaluationException { + public Map.Entry next() throws RyaDAOException { if (!hasNext() || isClosed) { throw new NoSuchElementException(); } try { - RyaStatement next = query.next(); - if (next == null) { + Map.Entry next = query.next(); + if (next == null || next.getKey() == null) { return null; } - return RyaToRdfConversions.convertStatement(next); + Statement statement = next.getKey().toStatement(); + BindingSet bindingSet = next.getValue(); + return new RdfCloudTripleStoreUtils.CustomEntry<>(statement, bindingSet); } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + throw new RyaDAOException(e); } } @Override - public void remove() throws QueryEvaluationException { + public void remove() throws RyaDAOException { try { query.remove(); } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + throw new RyaDAOException(e); } } }; } - public static CloseableIteration, QueryEvaluationException> query(RyaDAO ryaDAO, Collection> statements, RdfCloudTripleStoreConfiguration conf) throws QueryEvaluationException { - Collection> ryaStatements = new ArrayList>(statements.size()); - for (Map.Entry entry : statements) { - ryaStatements.add(new RdfCloudTripleStoreUtils.CustomEntry - (RdfToRyaConversions.convertStatement(entry.getKey()), entry.getValue())); + public static CloseableIteration query(RyaQueryEngine queryEngine, RyaResource subject, RyaIRI predicate, RyaValue object, RdfCloudTripleStoreConfiguration conf, RyaResource... contexts) throws RyaDAOException { + List statements = new ArrayList<>(); + if (contexts != null && contexts.length > 0) { + for (Resource context : contexts) { + statements.add(new RyaStatement(subject, predicate, object, context)); + } + } else { + statements.add(new RyaStatement(subject, predicate, object)); } - final CloseableIteration, RyaDAOException> query; - try { - query = ryaDAO.getQueryEngine().queryWithBindingSet(ryaStatements, conf); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + return query(queryEngine, statements, conf); + } + + public static CloseableIteration query(RyaQueryEngine queryEngine, RyaResource subject, RyaIRI predicate, RyaValue object, RdfCloudTripleStoreConfiguration conf) throws RyaDAOException { + return query(queryEngine, new RyaStatement(subject, predicate, object), conf); + } + + public static CloseableIteration query(RyaQueryEngine queryEngine, RyaStatement stmt, RdfCloudTripleStoreConfiguration conf) throws RyaDAOException { + return query(queryEngine, Collections.singletonList(stmt), conf); + } + + public static CloseableIteration query(RyaQueryEngine queryEngine, Iterable stmts, RdfCloudTripleStoreConfiguration conf) throws RyaDAOException { + final Map statements = new HashMap<>(); + for (RyaStatement stmt : stmts) { + statements.put(stmt, null); } - return new CloseableIteration, QueryEvaluationException>() { //TODO: Create a new class struct for this + CloseableIteration, RyaDAOException> query = query(queryEngine, statements.entrySet(), conf); + // This translates from , RyaDAOException> to + return new CloseableIteration() { + private boolean isClosed = false; @Override - public void close() throws QueryEvaluationException { - isClosed = true; + public void close() throws RyaDAOException { try { + isClosed = true; query.close(); } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + throw new RyaDAOException(e); } } @Override - public boolean hasNext() throws QueryEvaluationException { + public boolean hasNext() throws RyaDAOException { try { return query.hasNext(); } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + throw new RyaDAOException(e); } } @Override - public Map.Entry next() throws QueryEvaluationException { + public RyaStatement next() throws RyaDAOException { if (!hasNext() || isClosed) { throw new NoSuchElementException(); } - try { + try { Map.Entry next = query.next(); - if (next == null) { + if (next == null || next.getKey() == null) { return null; } - return new RdfCloudTripleStoreUtils.CustomEntry(RyaToRdfConversions.convertStatement(next.getKey()), next.getValue()); + return next.getKey(); } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + throw new RyaDAOException(e); } } @Override - public void remove() throws QueryEvaluationException { + public void remove() throws RyaDAOException { try { query.remove(); } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); + throw new RyaDAOException(e); } } }; } + public static CloseableIteration, RyaDAOException> query(RyaQueryEngine queryEngine, Collection> statements, RdfCloudTripleStoreConfiguration conf) throws RyaDAOException { + Preconditions.checkNotNull(conf, "Defensive coding. You should pass the configuration."); + Collection> ryaStatements = new ArrayList<>(statements.size()); + for (Map.Entry entry : statements) { + ryaStatements.add(new RdfCloudTripleStoreUtils.CustomEntry<>(entry.getKey(), entry.getValue())); + } + return queryEngine.queryWithBindingSet(ryaStatements, conf); + } + } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDaoQueryWrapper.java b/common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDaoQueryWrapper.java index 2122f536f..a70607317 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDaoQueryWrapper.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDaoQueryWrapper.java @@ -18,8 +18,6 @@ */ package org.apache.rya.api.persist.utils; -import static com.google.common.base.Preconditions.checkNotNull; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.persist.RyaDAO; @@ -32,6 +30,8 @@ import org.eclipse.rdf4j.query.QueryEvaluationException; import org.eclipse.rdf4j.rio.RDFHandler; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Wraps Rya DAO queries into a simpler interface that just passes in the * statement to query for and a handler for dealing with each statement in the @@ -40,7 +40,7 @@ * for multiple queries. */ public class RyaDaoQueryWrapper { - private final RyaDAO ryaDao; + private final RyaDAO ryaDao; private final RdfCloudTripleStoreConfiguration conf; /** @@ -49,7 +49,7 @@ public class RyaDaoQueryWrapper { * @param conf the {@link RdfCloudTripleStoreConfiguration}. * (not {@code null}) */ - public RyaDaoQueryWrapper(final RyaDAO ryaDao, final RdfCloudTripleStoreConfiguration conf) { + public RyaDaoQueryWrapper(final RyaDAO ryaDao, final RdfCloudTripleStoreConfiguration conf) { this.ryaDao = checkNotNull(ryaDao); this.conf = checkNotNull(conf); } @@ -58,7 +58,7 @@ public RyaDaoQueryWrapper(final RyaDAO ryaDao, final RdfCloudTripleStoreConfi * Creates a new instance of {@link RyaDaoQueryWrapper}. * @param ryaDao the {@link RyaDAO}. (not {@code null}) */ - public RyaDaoQueryWrapper(final RyaDAO ryaDao) { + public RyaDaoQueryWrapper(final RyaDAO ryaDao) { this(checkNotNull(ryaDao), ryaDao.getConf()); } @@ -69,12 +69,12 @@ public RyaDaoQueryWrapper(final RyaDAO ryaDao) { * @param object the object {@link Value} to query for. * @param rdfStatementHandler the {@link RDFHandler} to use for handling * each statement returned. (not {@code null}) - * @param contexts the context {@link Resource}s to query for. + * @param context the context {@link Resource}s to query for. * @throws QueryEvaluationException */ - public void queryAll(final Resource subject, final IRI predicate, final Value object, final RDFHandler rdfStatementHandler, final Resource... contexts) throws QueryEvaluationException { + public void queryAll(final Resource subject, final IRI predicate, final Value object, final RDFHandler rdfStatementHandler, final Resource... context) throws QueryEvaluationException { checkNotNull(rdfStatementHandler); - final CloseableIteration iter = RyaDAOHelper.query(ryaDao, subject, predicate, object, conf, contexts); + final CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDao.getQueryEngine(), subject, predicate, object, conf, context); try { while (iter.hasNext()) { final Statement statement = iter.next(); @@ -91,6 +91,10 @@ public void queryAll(final Resource subject, final IRI predicate, final Value ob } } + public void queryAll(final Resource subject, final IRI predicate, final Value object, final RDFHandler rdfStatementHandler) throws QueryEvaluationException { + queryAll(subject, predicate, object, rdfStatementHandler, null); + } + /** * Handles all results of a query. Closes the query iterator when done. * @param statement the {@link Statement} to query for. (not {@code null}) @@ -128,12 +132,12 @@ public void queryAll(final RyaStatement ryaStatement, final RDFHandler rdfStatem * @param object the object {@link Value} to query for. * @param rdfStatementHandler the {@link RDFHandler} to use for handling the * first statement returned. (not {@code null}) - * @param contexts the context {@link Resource}s to query for. + * @param context the context {@link Resource}s to query for. * @throws QueryEvaluationException */ - public void queryFirst(final Resource subject, final IRI predicate, final Value object, final RDFHandler rdfStatementHandler, final Resource... contexts) throws QueryEvaluationException { + public void queryFirst(final Resource subject, final IRI predicate, final Value object, final RDFHandler rdfStatementHandler, final Resource... context) throws QueryEvaluationException { checkNotNull(rdfStatementHandler); - final CloseableIteration iter = RyaDAOHelper.query(ryaDao, subject, predicate, object, conf, contexts); + final CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDao.getQueryEngine(), subject, predicate, object, conf, context); try { if (iter.hasNext()) { final Statement statement = iter.next(); @@ -150,6 +154,10 @@ public void queryFirst(final Resource subject, final IRI predicate, final Value } } + public void queryFirst(final Resource subject, final IRI predicate, final Value object, final RDFHandler rdfStatementHandler) throws QueryEvaluationException { + queryFirst(subject, predicate, object, rdfStatementHandler, null); + } + /** * Handles only the first result of a query. Closes the query iterator when * done. diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/ByteRange.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/ByteRange.java index adfce0cb8..ace4b768e 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/ByteRange.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/ByteRange.java @@ -20,6 +20,7 @@ */ +import java.nio.charset.StandardCharsets; /** * Date: 1/10/13 @@ -42,4 +43,9 @@ public byte[] getStart() { public byte[] getEnd() { return end; } + + public String toString() { + return "start(" + (start == null ? null : new String(start, StandardCharsets.UTF_8)) + ") end(" + (end == null ? null : new String(end, StandardCharsets.UTF_8)) + ")"; + } + } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/TriplePatternStrategy.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/TriplePatternStrategy.java index d8c8226c5..5773e1425 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/TriplePatternStrategy.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/TriplePatternStrategy.java @@ -24,8 +24,10 @@ import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.triple.TripleRowRegex; /** @@ -34,13 +36,13 @@ */ public interface TriplePatternStrategy { - public Map.Entry defineRange(RyaIRI subject, RyaIRI predicate, RyaType object, RyaIRI context, + ByteRange defineRange(RyaResource subject, RyaIRI predicate, RyaValue object, RyaResource context, RdfCloudTripleStoreConfiguration conf) throws IOException; - public TABLE_LAYOUT getLayout(); + TABLE_LAYOUT getLayout(); - public boolean handles(RyaIRI subject, RyaIRI predicate, RyaType object, RyaIRI context); + boolean handles(RyaResource subject, RyaIRI predicate, RyaValue object, RyaResource context); - public TripleRowRegex buildRegex(String subject, String predicate, String object, String context, byte[] objectTypeInfo); + TripleRowRegex buildRegex(String subject, String predicate, String object, String context, byte[] objectTypeInfo); } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/AbstractHashedTriplePatternStrategy.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/AbstractHashedTriplePatternStrategy.java index 140a30181..970b98983 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/AbstractHashedTriplePatternStrategy.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/AbstractHashedTriplePatternStrategy.java @@ -18,24 +18,20 @@ */ package org.apache.rya.api.query.strategy.wholerow; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM; - -import java.nio.charset.StandardCharsets; - +import com.google.common.base.Preconditions; import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.query.strategy.AbstractTriplePatternStrategy; import org.apache.rya.api.query.strategy.TriplePatternStrategy; import org.apache.rya.api.resolver.triple.TripleRowRegex; -import com.google.common.base.Preconditions; +import java.nio.charset.StandardCharsets; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM; public abstract class AbstractHashedTriplePatternStrategy extends AbstractTriplePatternStrategy implements TriplePatternStrategy { public static final String HASHED_ALL_REGEX = "([0-9a-f]{32})\u0000"; - @Override - public abstract RdfCloudTripleStoreConstants.TABLE_LAYOUT getLayout(); - @Override public TripleRowRegex buildRegex(final String subject, final String predicate, final String object, final String context, final byte[] objectTypeInfo) { final RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout = getLayout(); @@ -91,4 +87,5 @@ public TripleRowRegex buildRegex(final String subject, final String predicate, f return new TripleRowRegex(sb.toString(), (context != null) ? (context + ALL_REGEX) : null, null); } + } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java index 1b69721a0..125cec789 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java @@ -18,28 +18,26 @@ */ package org.apache.rya.api.query.strategy.wholerow; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - +import com.google.common.primitives.Bytes; import org.apache.commons.codec.binary.Hex; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaRange; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaRange; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; -import com.google.common.primitives.Bytes; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; /** * Date: 7/14/12 @@ -53,9 +51,8 @@ public RdfCloudTripleStoreConstants.TABLE_LAYOUT getLayout() { } @Override - public Map.Entry defineRange(final RyaIRI subject, final RyaIRI predicate, final RyaType object, - final RyaIRI context, final RdfCloudTripleStoreConfiguration conf) throws IOException { + public ByteRange defineRange(final RyaResource subject, final RyaIRI predicate, final RyaValue object, + final RyaResource context, final RdfCloudTripleStoreConfiguration conf) throws IOException { try { //po(ng) //po_r(s)(ng) @@ -112,17 +109,14 @@ ByteRange> defineRange(final RyaIRI subject, final RyaIRI predicate, final RyaTy start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES); stop = Bytes.concat(start, LAST_BYTES); } - return new RdfCloudTripleStoreUtils.CustomEntry(table_layout, new ByteRange(start, stop)); - } catch (final RyaTypeResolverException e) { + return new ByteRange(start, stop); + } catch (final RyaTypeResolverException | NoSuchAlgorithmException e) { throw new IOException(e); - } catch (final NoSuchAlgorithmException e) { - throw new IOException(e); - } + } } @Override - public boolean handles(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context) { + public boolean handles(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context) { //po(ng) //p_r(o)(ng) //po_r(s)(ng) diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java index 42fd9d264..a47113a75 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java @@ -18,29 +18,27 @@ */ package org.apache.rya.api.query.strategy.wholerow; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - +import com.google.common.primitives.Bytes; import org.apache.commons.codec.binary.Hex; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaRange; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaIRIRange; +import org.apache.rya.api.domain.RyaRange; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; -import com.google.common.primitives.Bytes; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; /** * Date: 7/14/12 @@ -55,8 +53,8 @@ public TABLE_LAYOUT getLayout() { } @Override - public Map.Entry defineRange(final RyaIRI subject, final RyaIRI predicate, final RyaType object, - final RyaIRI context, final RdfCloudTripleStoreConfiguration conf) throws IOException { + public ByteRange defineRange(final RyaResource subject, final RyaIRI predicate, final RyaValue object, + final RyaResource context, final RdfCloudTripleStoreConfiguration conf) throws IOException { try { //spo(ng) //sp(ng) @@ -124,17 +122,14 @@ public Map.Entry defineRange(final RyaIRI subject, fina start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES); stop = Bytes.concat(start, LAST_BYTES); } - return new RdfCloudTripleStoreUtils.CustomEntry(table_layout, - new ByteRange(start, stop)); - } catch (final RyaTypeResolverException e) { + return new ByteRange(start, stop); + } catch (final RyaTypeResolverException | NoSuchAlgorithmException e) { throw new IOException(e); - } catch (final NoSuchAlgorithmException e) { - throw new IOException(e); - } + } } @Override - public boolean handles(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context) { + public boolean handles(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context) { //if subject is not null and not a range (if predicate is null then object must be null) return (subject != null && !(subject instanceof RyaIRIRange)) && !((predicate == null || predicate instanceof RyaIRIRange) && (object != null)); } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/NullRowTriplePatternStrategy.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/NullRowTriplePatternStrategy.java index afc3af215..fbdbe0d44 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/NullRowTriplePatternStrategy.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/NullRowTriplePatternStrategy.java @@ -8,9 +8,9 @@ * 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 @@ -19,19 +19,18 @@ * under the License. */ -import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; - -import java.io.IOException; -import java.util.Map; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.query.strategy.AbstractTriplePatternStrategy; import org.apache.rya.api.query.strategy.ByteRange; +import java.io.IOException; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; + public class NullRowTriplePatternStrategy extends AbstractTriplePatternStrategy { @Override @@ -40,15 +39,15 @@ public TABLE_LAYOUT getLayout() { } @Override - public Map.Entry defineRange(RyaIRI subject, RyaIRI predicate, RyaType object, - RyaIRI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - byte[] start = new byte[]{ /* empty array */ }; // Scan from the beginning of the Accumulo Table - byte[] stop = LAST_BYTES; // Scan to the end, up through things beginning with 0xff. - return new RdfCloudTripleStoreUtils.CustomEntry<>(TABLE_LAYOUT.SPO, new ByteRange(start, stop)); + public ByteRange defineRange(final RyaResource subject, final RyaIRI predicate, final RyaValue object, + final RyaResource context, RdfCloudTripleStoreConfiguration conf) throws IOException { + byte[] start = new byte[]{ /* empty array */}; // Scan from the beginning of the Accumulo Table + byte[] stop = LAST_BYTES; // Scan to the end, up through things beginning with 0xff. + return new ByteRange(start, stop); } @Override - public boolean handles(RyaIRI subject, RyaIRI predicate, RyaType object, RyaIRI context) { + public boolean handles(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context) { return subject == null && predicate == null && object == null; } } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java index a9706dc13..f1b323bc8 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java @@ -18,25 +18,23 @@ */ package org.apache.rya.api.query.strategy.wholerow; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Map; - +import com.google.common.primitives.Bytes; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaRange; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaRange; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.query.strategy.AbstractTriplePatternStrategy; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; -import com.google.common.primitives.Bytes; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; /** * Date: 7/14/12 @@ -50,9 +48,8 @@ public TABLE_LAYOUT getLayout() { } @Override - public Map.Entry defineRange(final RyaIRI subject, final RyaIRI predicate, final RyaType object, - final RyaIRI context, final RdfCloudTripleStoreConfiguration conf) throws IOException { + public ByteRange defineRange(final RyaResource subject, final RyaIRI predicate, final RyaValue object, + final RyaResource context, final RdfCloudTripleStoreConfiguration conf) throws IOException { try { //os(ng) //o_r(s)(ng) @@ -95,15 +92,14 @@ ByteRange> defineRange(final RyaIRI subject, final RyaIRI predicate, final RyaTy stop = Bytes.concat(start, LAST_BYTES); } } - return new RdfCloudTripleStoreUtils.CustomEntry(table_layout, new ByteRange(start, stop)); + return new ByteRange(start, stop); } catch (final RyaTypeResolverException e) { throw new IOException(e); } } @Override - public boolean handles(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context) { + public boolean handles(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context) { //os(ng) //o_r(s)(ng) //o(ng) diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategy.java index dbf80232f..f2dc3bed7 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategy.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategy.java @@ -18,26 +18,24 @@ */ package org.apache.rya.api.query.strategy.wholerow; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Map; - +import com.google.common.primitives.Bytes; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaRange; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaRange; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.query.strategy.AbstractTriplePatternStrategy; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; -import com.google.common.primitives.Bytes; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; /** * Date: 7/14/12 @@ -51,9 +49,8 @@ public RdfCloudTripleStoreConstants.TABLE_LAYOUT getLayout() { } @Override - public Map.Entry defineRange(final RyaIRI subject, final RyaIRI predicate, final RyaType object, - final RyaIRI context, final RdfCloudTripleStoreConfiguration conf) throws IOException { + public ByteRange defineRange(final RyaResource subject, final RyaIRI predicate, final RyaValue object, + final RyaResource context, final RdfCloudTripleStoreConfiguration conf) throws IOException { try { //po(ng) //po_r(s)(ng) @@ -108,15 +105,14 @@ ByteRange> defineRange(final RyaIRI subject, final RyaIRI predicate, final RyaTy start = Bytes.concat(predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES); stop = Bytes.concat(start, LAST_BYTES); } - return new RdfCloudTripleStoreUtils.CustomEntry(table_layout, new ByteRange(start, stop)); + return new ByteRange(start, stop); } catch (final RyaTypeResolverException e) { throw new IOException(e); } } @Override - public boolean handles(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context) { + public boolean handles(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context) { //po(ng) //p_r(o)(ng) //po_r(s)(ng) diff --git a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategy.java index eed3ab05b..d0dbeea88 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategy.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategy.java @@ -18,27 +18,25 @@ */ package org.apache.rya.api.query.strategy.wholerow; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Map; - +import com.google.common.primitives.Bytes; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaRange; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaIRIRange; +import org.apache.rya.api.domain.RyaRange; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.query.strategy.AbstractTriplePatternStrategy; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; -import com.google.common.primitives.Bytes; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; /** * Date: 7/14/12 @@ -52,8 +50,8 @@ public TABLE_LAYOUT getLayout() { } @Override - public Map.Entry defineRange(final RyaIRI subject, final RyaIRI predicate, final RyaType object, - final RyaIRI context, final RdfCloudTripleStoreConfiguration conf) throws IOException { + public ByteRange defineRange(final RyaResource subject, final RyaIRI predicate, final RyaValue object, + final RyaResource context, final RdfCloudTripleStoreConfiguration conf) throws IOException { try { //spo(ng) //sp(ng) @@ -66,7 +64,6 @@ public Map.Entry defineRange(final RyaIRI subject, fina final RyaContext ryaContext = RyaContext.getInstance(); - final TABLE_LAYOUT table_layout = TABLE_LAYOUT.SPO; byte[] start; byte[] stop; if (predicate != null) { @@ -119,15 +116,14 @@ public Map.Entry defineRange(final RyaIRI subject, fina start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES); stop = Bytes.concat(start, LAST_BYTES); } - return new RdfCloudTripleStoreUtils.CustomEntry(table_layout, - new ByteRange(start, stop)); + return new ByteRange(start, stop); } catch (final RyaTypeResolverException e) { throw new IOException(e); } } @Override - public boolean handles(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context) { + public boolean handles(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context) { //if subject is not null and (if predicate is null then object must be null) return (subject != null && !(subject instanceof RyaIRIRange && predicate != null)) && !((predicate == null || predicate instanceof RyaIRIRange) && (object != null)); } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RdfToRyaConversions.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RdfToRyaConversions.java index 8554e7763..6c2448569 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RdfToRyaConversions.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RdfToRyaConversions.java @@ -18,17 +18,17 @@ */ package org.apache.rya.api.resolver; -import static org.apache.rya.api.utils.LiteralLanguageUtils.UNDETERMINED_LANGUAGE; - import org.apache.log4j.Logger; import org.apache.rya.api.domain.RangeIRI; import org.apache.rya.api.domain.RangeValue; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaIRIRange; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaSchema; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaTypeRange; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.log.LogUtils; import org.eclipse.rdf4j.model.BNode; import org.eclipse.rdf4j.model.IRI; @@ -38,6 +38,8 @@ import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.util.Literals; +import static org.apache.rya.api.utils.LiteralLanguageUtils.UNDETERMINED_LANGUAGE; + /** * Methods for converting values from their RDF4J object representations into * their Rya object equivalents. @@ -55,23 +57,29 @@ public static RyaIRI convertIRI(final IRI iri) { if (iri == null) { return null; } + if (iri instanceof RyaIRI) { + return (RyaIRI) iri; + } if (iri instanceof RangeIRI) { final RangeIRI riri = (RangeIRI) iri; - return new RyaIRIRange(convertIRI(riri.getStart()), convertIRI(riri.getEnd())); + return new RyaIRIRange(convertResource(riri.getStart()), convertResource(riri.getEnd())); } return new RyaIRI(iri.stringValue()); } /** - * Converts a {@link Literal} into a {@link RyaType} representation of the + * Converts a {@link Literal} into a {@link RyaValue} representation of the * {@code literal}. * @param literal the {@link Literal} to convert. - * @return the {@link RyaType} representation of the {@code literal}. + * @return the {@link RyaValue} representation of the {@code literal}. */ - public static RyaType convertLiteral(final Literal literal) { + public static RyaValue convertLiteral(final Literal literal) { if (literal == null) { return null; } + if (literal instanceof RyaType) { + return (RyaType) literal; + } if (literal.getDatatype() != null) { if (Literals.isLanguageLiteral(literal)) { final String language = literal.getLanguage().get(); @@ -89,15 +97,18 @@ public static RyaType convertLiteral(final Literal literal) { } /** - * Converts a {@link Value} into a {@link RyaType} representation of the + * Converts a {@link Value} into a {@link RyaValue} representation of the * {@code value}. * @param value the {@link Value} to convert. - * @return the {@link RyaType} representation of the {@code value}. + * @return the {@link RyaValue} representation of the {@code value}. */ - public static RyaType convertValue(final Value value) { + public static RyaValue convertValue(final Value value) { if (value == null) { return null; } + if (value instanceof RyaValue) { + return (RyaValue) value; + } //assuming either IRI or Literal here if (value instanceof Resource) { return convertResource((Resource) value); @@ -118,20 +129,44 @@ public static RyaType convertValue(final Value value) { } /** - * Converts a {@link Resource} into a {@link RyaIRI} representation of the + * Converts a {@link Resource} into a {@link RyaResource} representation of the * {@code resource}. * @param resource the {@link Resource} to convert. Generally this will be * the subject. - * @return the {@link RyaIRI} representation of the {@code resource}. + * @return the {@link RyaResource} representation of the {@code resource}. */ - public static RyaIRI convertResource(final Resource resource) { + public static RyaResource convertResource(final Resource resource) { if (resource == null) { return null; } + if (resource instanceof RyaIRI) { + return (RyaIRI) resource; + } if (resource instanceof BNode) { return new RyaIRI(RyaSchema.BNODE_NAMESPACE + ((BNode) resource).getID()); } - return convertIRI((IRI) resource); + if (resource instanceof IRI) { + return convertIRI((IRI) resource); + } + return (RyaResource) convertValue(resource); + } + + /** + * Converts a {@link Resource[]} into a {@link RyaResource[]} representation of the + * {@code resource}. + * @param resources the {@link Resource} to convert. Generally this will be + * the subject. + * @return the {@link RyaResource} representation of the {@code resources}. + */ + public static RyaResource[] convertResource(final Resource... resources) { + if (resources == null || resources.length == 0) { + return null; + } + RyaResource[] ryaResources = new RyaResource[resources.length]; + for (int i = 0; i < resources.length; i++) { + ryaResources[i] = convertResource(resources[i]); + } + return ryaResources; } /** @@ -144,6 +179,9 @@ public static RyaStatement convertStatement(final Statement statement) { if (statement == null) { return null; } + if (statement instanceof RyaStatement) { + return (RyaStatement) statement; + } final Resource subject = statement.getSubject(); final IRI predicate = statement.getPredicate(); final Value object = statement.getObject(); diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaContext.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaContext.java index bc0c6df2e..937f3b502 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaContext.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaContext.java @@ -19,12 +19,9 @@ * under the License. */ -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.apache.rya.api.domain.RyaRange; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.impl.BooleanRyaTypeResolver; import org.apache.rya.api.resolver.impl.ByteRyaTypeResolver; import org.apache.rya.api.resolver.impl.CustomDatatypeResolver; @@ -33,8 +30,8 @@ import org.apache.rya.api.resolver.impl.FloatRyaTypeResolver; import org.apache.rya.api.resolver.impl.IntegerRyaTypeResolver; import org.apache.rya.api.resolver.impl.LongRyaTypeResolver; -import org.apache.rya.api.resolver.impl.RyaTypeResolverImpl; import org.apache.rya.api.resolver.impl.RyaIRIResolver; +import org.apache.rya.api.resolver.impl.RyaTypeResolverImpl; import org.apache.rya.api.resolver.impl.ServiceBackedRyaTypeResolverMappings; import org.apache.rya.api.resolver.impl.ShortRyaTypeResolver; import org.eclipse.rdf4j.model.IRI; @@ -42,6 +39,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * Date: 7/16/12 * Time: 12:04 PM @@ -116,7 +117,7 @@ public byte[] serialize(final RyaType ryaType) throws RyaTypeResolverException { return null; } - public byte[][] serializeType(final RyaType ryaType) throws RyaTypeResolverException { + public byte[][] serializeType(final RyaValue ryaType) throws RyaTypeResolverException { final RyaTypeResolver ryaTypeResolver = retrieveResolver(ryaType.getDataType()); if (ryaTypeResolver != null) { return ryaTypeResolver.serializeType(ryaType); diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaToRdfConversions.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaToRdfConversions.java index 27d329a16..48e70b143 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaToRdfConversions.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaToRdfConversions.java @@ -19,11 +19,14 @@ package org.apache.rya.api.resolver; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.utils.LiteralLanguageUtils; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.ValueFactory; @@ -50,22 +53,44 @@ public static IRI convertIRI(final RyaIRI ryaIri) { } /** - * Converts a {@link RyaType} into a {@link IRI} representation of the - * {@code ryaType}. - * @param ryaType the {@link RyaType} to convert. - * @return the {@link IRI} representation of the {@code ryaType}. + * Converts a {@link RyaValue} into a {@link Resource} representation of the + * {@code ryaValue}. + * @param ryaValue the {@link RyaValue} to convert. + * @return the {@link Resource} representation of the {@code ryaValue}. */ - private static IRI convertIRI(final RyaType ryaType) { - return VF.createIRI(ryaType.getData()); + public static Resource convertResource(final RyaValue ryaValue) { + return VF.createIRI(ryaValue.getData()); } /** - * Converts a {@link RyaType} into a {@link Literal} representation of the - * {@code ryaType}. - * @param ryaType the {@link RyaType} to convert. - * @return the {@link Literal} representation of the {@code ryaType}. + * Converts a {@link RyaValue[]} into a {@link Resource[]} representation of the + * {@code resource}. + * @param ryaValues the {@link RyaResource} to convert. Generally this will be + * the subject. + * @return the {@link Resource} representation of the {@code ryaValues}. */ - public static Literal convertLiteral(final RyaType ryaType) { + public static Resource[] convertResource(final RyaValue... ryaValues) { + if (ryaValues == null || ryaValues.length == 0) { + return null; + } + Resource[] resources = new Resource[ryaValues.length]; + for (int i = 0; i < ryaValues.length; i++) { + resources[i] = convertResource(ryaValues[i]); + } + return resources; + } + + /** + * Converts a {@link RyaValue} into a {@link Literal} representation of the + * {@code ryaValue}. + * @param ryaValue the {@link RyaValue} to convert. + * @return the {@link Literal} representation of the {@code ryaValue}. + */ + public static Literal convertLiteral(final RyaValue ryaValue) { + if (ryaValue == null) { + return null; + } + RyaType ryaType = (RyaType) ryaValue; if (XMLSchema.STRING.equals(ryaType.getDataType())) { return VF.createLiteral(ryaType.getData()); } else if (RDF.LANGSTRING.equals(ryaType.getDataType())) { @@ -81,14 +106,20 @@ public static Literal convertLiteral(final RyaType ryaType) { } /** - * Converts a {@link RyaType} into a {@link Value} representation of the - * {@code ryaType}. - * @param ryaType the {@link RyaType} to convert. + * Converts a {@link RyaValue} into a {@link Value} representation of the + * {@code ryaValue}. + * @param ryaValue the {@link RyaValue} to convert. * @return the {@link Value} representation of the {@code ryaType}. */ - public static Value convertValue(final RyaType ryaType) { - //assuming either IRI or Literal here - return (ryaType instanceof RyaIRI || ryaType.getDataType().equals(XMLSchema.ANYURI)) ? convertIRI(ryaType) : convertLiteral(ryaType); + public static Value convertValue(final RyaValue ryaValue) { + if (ryaValue == null) { + return null; + } + // We need to ensure IRIs stay as IRIs. The data type check here is just defensive programming and shouldn't be relied on. + if (ryaValue instanceof RyaResource || XMLSchema.ANYURI.equals(ryaValue.getDataType())) { + return convertResource(ryaValue); + } + return convertLiteral(ryaValue); } /** @@ -99,15 +130,11 @@ public static Value convertValue(final RyaType ryaType) { */ public static Statement convertStatement(final RyaStatement ryaStatement) { assert ryaStatement != null; - if (ryaStatement.getContext() != null) { - return VF.createStatement(convertIRI(ryaStatement.getSubject()), - convertIRI(ryaStatement.getPredicate()), - convertValue(ryaStatement.getObject()), - convertIRI(ryaStatement.getContext())); - } else { - return VF.createStatement(convertIRI(ryaStatement.getSubject()), - convertIRI(ryaStatement.getPredicate()), - convertValue(ryaStatement.getObject())); - } + return VF.createStatement( + convertResource(ryaStatement.getSubject()), + convertIRI(ryaStatement.getPredicate()), + convertValue(ryaStatement.getObject()), + ryaStatement.getContext() != null ? convertResource(ryaStatement.getContext()) : null + ); } } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaTripleContext.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaTripleContext.java index dc4a42ec6..aaf93f1b0 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaTripleContext.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaTripleContext.java @@ -28,9 +28,10 @@ import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.query.strategy.TriplePatternStrategy; import org.apache.rya.api.query.strategy.wholerow.HashedPoWholeRowTriplePatternStrategy; import org.apache.rya.api.query.strategy.wholerow.HashedSpoWholeRowTriplePatternStrategy; @@ -101,7 +102,7 @@ protected void addDefaultTriplePatternStrategies(final boolean addPrefixHash) { } //retrieve triple pattern strategy - public TriplePatternStrategy retrieveStrategy(final RyaIRI subject, final RyaIRI predicate, final RyaType object, final RyaIRI context) { + public TriplePatternStrategy retrieveStrategy(final RyaResource subject, final RyaIRI predicate, final RyaValue object, final RyaResource context) { for (final TriplePatternStrategy strategy : triplePatternStrategyList) { if (strategy.handles(subject, predicate, object, context)) { return strategy; diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaTypeResolver.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaTypeResolver.java index 4e061ea10..0b2b61add 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaTypeResolver.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/RyaTypeResolver.java @@ -23,6 +23,7 @@ import org.apache.rya.api.domain.RyaRange; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.eclipse.rdf4j.model.IRI; /** @@ -30,8 +31,8 @@ * Time: 12:08 PM */ public interface RyaTypeResolver { - public byte[] serialize(RyaType ryaType) throws RyaTypeResolverException; - public byte[][] serializeType(RyaType ryaType) throws RyaTypeResolverException; + public byte[] serialize(RyaValue ryaValue) throws RyaTypeResolverException; + public byte[][] serializeType(RyaValue ryaValue) throws RyaTypeResolverException; public RyaType deserialize(byte[] bytes) throws RyaTypeResolverException; diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/impl/CustomDatatypeResolver.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/impl/CustomDatatypeResolver.java index da38a8cd1..c835e1c1a 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/impl/CustomDatatypeResolver.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/impl/CustomDatatypeResolver.java @@ -18,19 +18,19 @@ */ package org.apache.rya.api.resolver.impl; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.nio.charset.StandardCharsets; - +import com.google.common.primitives.Bytes; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RyaTypeResolverException; import org.apache.rya.api.utils.LiteralLanguageUtils; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.util.Literals; import org.eclipse.rdf4j.model.vocabulary.RDF; -import com.google.common.primitives.Bytes; +import java.nio.charset.StandardCharsets; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; /** * Date: 7/16/12 @@ -44,7 +44,7 @@ public CustomDatatypeResolver() { } @Override - public byte[][] serializeType(final RyaType ryaType) throws RyaTypeResolverException { + public byte[][] serializeType(final RyaValue ryaType) throws RyaTypeResolverException { final StringBuilder dataBuilder = new StringBuilder(); dataBuilder.append(ryaType.getData()); final String validatedLanguage = LiteralLanguageUtils.validateLanguage(ryaType.getLanguage(), ryaType.getDataType()); @@ -58,7 +58,7 @@ public byte[][] serializeType(final RyaType ryaType) throws RyaTypeResolverExcep } @Override - public byte[] serialize(final RyaType ryaType) throws RyaTypeResolverException { + public byte[] serialize(final RyaValue ryaType) throws RyaTypeResolverException { final byte[][] bytes = serializeType(ryaType); return Bytes.concat(bytes[0], bytes[1]); } diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/impl/RyaTypeResolverImpl.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/impl/RyaTypeResolverImpl.java index 8b4522112..bb3e43d38 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/impl/RyaTypeResolverImpl.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/impl/RyaTypeResolverImpl.java @@ -18,13 +18,10 @@ */ package org.apache.rya.api.resolver.impl; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.nio.charset.StandardCharsets; - +import com.google.common.primitives.Bytes; import org.apache.rya.api.domain.RyaRange; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RyaTypeResolver; import org.apache.rya.api.resolver.RyaTypeResolverException; import org.apache.rya.api.utils.LiteralLanguageUtils; @@ -35,7 +32,10 @@ import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; -import com.google.common.primitives.Bytes; +import java.nio.charset.StandardCharsets; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; /** * Date: 7/16/12 @@ -75,13 +75,13 @@ public RyaRange transformRange(final RyaRange ryaRange) throws RyaTypeResolverEx } @Override - public byte[] serialize(final RyaType ryaType) throws RyaTypeResolverException { + public byte[] serialize(final RyaValue ryaType) throws RyaTypeResolverException { final byte[][] bytes = serializeType(ryaType); return Bytes.concat(bytes[0], bytes[1]); } @Override - public byte[][] serializeType(final RyaType ryaType) throws RyaTypeResolverException { + public byte[][] serializeType(final RyaValue ryaType) throws RyaTypeResolverException { final StringBuilder dataBuilder = new StringBuilder(); dataBuilder.append(ryaType.getData()); final String validatedLanguage = LiteralLanguageUtils.validateLanguage(ryaType.getLanguage(), dataType); diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/TripleRowResolver.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/TripleRowResolver.java index fd9175169..5e1b814e4 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/TripleRowResolver.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/TripleRowResolver.java @@ -19,18 +19,17 @@ * under the License. */ - - import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; import java.util.Map; import static org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; /** + * This interface represents classes like {@link org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver} and + * {@link org.apache.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver}. + * It transforms between {@link RyaStatement}s and Accumulo entries, which are represented as {@link TripleRow}. * Date: 7/17/12 * Time: 7:33 AM */ diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java index 701ff02d1..132b7e41e 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java @@ -18,30 +18,31 @@ */ package org.apache.rya.api.resolver.triple.impl; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; - -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - +import com.google.common.primitives.Bytes; import org.apache.commons.codec.binary.Hex; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; +import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolver; import org.apache.rya.api.resolver.triple.TripleRowResolverException; -import com.google.common.primitives.Bytes; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; /** * Will store triple in spo, po, osp. Storing everything in the whole row. @@ -53,10 +54,10 @@ public class WholeRowHashedTripleResolver implements TripleRowResolver { @Override public Map serialize(final RyaStatement stmt) throws TripleRowResolverException { try { - final RyaIRI subject = stmt.getSubject(); + final RyaResource subject = stmt.getSubject(); final RyaIRI predicate = stmt.getPredicate(); - final RyaType object = stmt.getObject(); - final RyaIRI context = stmt.getContext(); + final RyaValue object = stmt.getObject(); + final RyaResource context = stmt.getContext(); final Long timestamp = stmt.getTimestamp(); final byte[] columnVisibility = stmt.getColumnVisibility(); final String qualifer = stmt.getQualifer(); @@ -121,6 +122,7 @@ public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow final Long timestamp = tripleRow.getTimestamp(); final byte[] columnVisibility = tripleRow.getColumnVisibility(); final byte[] value = tripleRow.getValue(); + final StatementMetadata metadata = new StatementMetadata(value); switch (table_layout) { case SPO: { @@ -129,7 +131,7 @@ public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow new RyaIRI(new String(first, StandardCharsets.UTF_8)), new RyaIRI(new String(second, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), - context, qualifier, columnVisibility, value, timestamp); + context, qualifier, columnVisibility, metadata, timestamp); } case PO: { final byte[] obj = Bytes.concat(second, type); @@ -137,7 +139,7 @@ public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow new RyaIRI(new String(third, StandardCharsets.UTF_8)), new RyaIRI(new String(first, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), - context, qualifier, columnVisibility, value, timestamp); + context, qualifier, columnVisibility, metadata, timestamp); } case OSP: { final byte[] obj = Bytes.concat(first, type); @@ -145,7 +147,7 @@ public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow new RyaIRI(new String(second, StandardCharsets.UTF_8)), new RyaIRI(new String(third, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), - context, qualifier, columnVisibility, value, timestamp); + context, qualifier, columnVisibility, metadata, timestamp); } } } catch (final RyaTypeResolverException e) { diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java index 994347fad..29d3c0dcb 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java @@ -18,27 +18,27 @@ */ package org.apache.rya.api.resolver.triple.impl; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; - -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - +import com.google.common.primitives.Bytes; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolver; import org.apache.rya.api.resolver.triple.TripleRowResolverException; -import com.google.common.primitives.Bytes; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; /** * Will store triple in spo, po, osp. Storing everything in the whole row. @@ -50,10 +50,10 @@ public class WholeRowTripleResolver implements TripleRowResolver { @Override public Map serialize(final RyaStatement stmt) throws TripleRowResolverException { try { - final RyaIRI subject = stmt.getSubject(); + final RyaResource subject = stmt.getSubject(); final RyaIRI predicate = stmt.getPredicate(); - final RyaType object = stmt.getObject(); - final RyaIRI context = stmt.getContext(); + final RyaValue object = stmt.getObject(); + final RyaResource context = stmt.getContext(); final Long timestamp = stmt.getTimestamp(); final byte[] columnVisibility = stmt.getColumnVisibility(); final String qualifer = stmt.getQualifer(); diff --git a/common/rya.api/src/main/java/org/apache/rya/api/utils/NullableStatementImpl.java b/common/rya.api/src/main/java/org/apache/rya/api/utils/NullableStatementImpl.java deleted file mode 100644 index 9ac9705f3..000000000 --- a/common/rya.api/src/main/java/org/apache/rya/api/utils/NullableStatementImpl.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.apache.rya.api.utils; - -/* - * 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. - */ - -import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.Resource; -import org.eclipse.rdf4j.model.Statement; -import org.eclipse.rdf4j.model.Value; - -/** - * Class NullableStatementImpl - * Date: Feb 23, 2011 - * Time: 10:37:34 AM - */ -public class NullableStatementImpl implements Statement { - - private Resource subject; - private IRI predicate; - private Value object; - private Resource[] contexts; - - public NullableStatementImpl(Resource subject, IRI predicate, Value object, Resource... contexts) { - this.subject = subject; - this.predicate = predicate; - this.object = object; - this.contexts = contexts; - } - - @Override - public int hashCode() { - return 961 * ((this.getSubject() == null) ? (0) : (this.getSubject().hashCode())) + - 31 * ((this.getPredicate() == null) ? (0) : (this.getPredicate().hashCode())) + - ((this.getObject() == null) ? (0) : (this.getObject().hashCode())); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(256); - sb.append("("); - sb.append(getSubject()); - sb.append(", "); - sb.append(getPredicate()); - sb.append(", "); - sb.append(getObject()); - sb.append(")"); - return sb.toString(); - } - - @Override - public boolean equals(Object other) { - if (this == other) - return true; - if (other instanceof Statement) { - Statement otherSt = (Statement) other; - return this.hashCode() == otherSt.hashCode(); - } else { - return false; - } - } - - public Value getObject() { - return object; - } - - public IRI getPredicate() { - return predicate; - } - - public Resource getSubject() { - return subject; - } - - public Resource getContext() { - if (contexts == null || contexts.length == 0) - return null; - else return contexts[0]; - } - - public Resource[] getContexts() { - return contexts; - } - - public void setContexts(Resource[] contexts) { - this.contexts = contexts; - } -} diff --git a/common/rya.api/src/main/java/org/apache/rya/api/utils/WildcardStatement.java b/common/rya.api/src/main/java/org/apache/rya/api/utils/WildcardStatement.java new file mode 100644 index 000000000..8b1f5c0e8 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/utils/WildcardStatement.java @@ -0,0 +1,137 @@ +package org.apache.rya.api.utils; + +/* + * 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. + */ + +import org.apache.rya.api.domain.RyaStatement; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; + +/** + * Class WildStatement + * + * Date: Feb 23, 2011 + * Time: 10:37:34 AM + */ +public class WildcardStatement implements Statement { + + private final Resource subject; + private final IRI predicate; + private final Value object; + private final Resource context; + + /** + * Creates a new Statement with the supplied subject, predicate and object. + * + * @param subject + * The statement's subject, may be null. + * @param predicate + * The statement's predicate, may be null. + * @param object + * The statement's object, may be null. + */ + public WildcardStatement(Resource subject, IRI predicate, Value object) { + this(subject, predicate, object, null); + } + + /** + * Creates a new Statement with the supplied subject, predicate and object for the specified + * associated context. + * + * @param subject + * The statement's subject, may be null. + * @param predicate + * The statement's predicate, may be null. + * @param object + * The statement's object, may be null. + * @param context + * The statement's context, null to indicate no context is associated. + */ + public WildcardStatement(Resource subject, IRI predicate, Value object, Resource context) { + this.subject = subject; + this.predicate = predicate; + this.object = object; + this.context = context; + } + + public WildcardStatement(RyaStatement statement) { + this(statement.getSubject(), statement.getPredicate(), statement.getObject(), statement.getContext()); + } + + @Override + public int hashCode() { + int result = subject != null ? subject.hashCode() : 0; + result = 31 * result + (predicate != null ? predicate.hashCode() : 0); + result = 31 * result + (object != null ? object.hashCode() : 0); + result = 31 * result + (context != null ? context.hashCode() : 0); + //result = 31 * result + (contexts.length > 0 ? Arrays.hashCode(contexts) : 0); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(256); + + sb.append("("); + sb.append(getSubject()); + sb.append(", "); + sb.append(getPredicate()); + sb.append(", "); + sb.append(getObject()); + sb.append(")"); + sb.append(" [").append(getContext()).append("]"); + + return sb.toString(); + } + + @Override + public boolean equals(Object other) { + if (this == other) + return true; + if (other instanceof WildcardStatement) { + WildcardStatement otherSt = (WildcardStatement) other; + return this.hashCode() == otherSt.hashCode(); + } else { + return false; + } + } + + // Implements Statement.getSubject() + public Resource getSubject() { + return subject; + } + + // Implements Statement.getPredicate() + public IRI getPredicate() { + return predicate; + } + + // Implements Statement.getObject() + public Value getObject() { + return object; + } + + @Override + public Resource getContext() { + return context; + } + +} diff --git a/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaTypeTest.java b/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaTypeTest.java index 53d02cd97..1d81898de 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaTypeTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaTypeTest.java @@ -18,6 +18,8 @@ */ package org.apache.rya.api.domain; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; import org.junit.Assert; @@ -37,6 +39,7 @@ public class RyaTypeTest { RyaType nullLang = new RyaType(RDF.LANGSTRING, "http://www.example.com/Alice", null); RyaType nullBoth = new RyaType(null, null); RyaType same = new RyaType(XMLSchema.STRING, "http://www.example.com/Alice"); + IRI iri = SimpleValueFactory.getInstance().createIRI("http://www.example.com/Alice"); @Test public void testCompareTo() throws Exception { @@ -90,6 +93,7 @@ public void testEquals() throws Exception { Assert.assertTrue("Same data and datatype should be equal.", a.equals(same)); Assert.assertFalse("Same data, different datatype should be unequal.", a.equals(aIri)); Assert.assertFalse("Same datatype, different data should be unequal.", a.equals(b)); + Assert.assertTrue("Same data and datatype should be equal.", a.equals(iri)); } @Test diff --git a/common/rya.api/src/test/java/org/apache/rya/api/persist/query/RyaQueryTest.java b/common/rya.api/src/test/java/org/apache/rya/api/persist/query/RyaQueryTest.java index b2c535dc4..278ce7969 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/persist/query/RyaQueryTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/persist/query/RyaQueryTest.java @@ -20,9 +20,8 @@ */ - -import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaStatement; import org.junit.Test; import java.util.Arrays; @@ -49,7 +48,7 @@ public void testBuildQueryWithOptions() { .build(); assertNotNull(ryaQuery); - assertEquals(ryaStatement, ryaQuery.getQuery()); + assertEquals(ryaStatement, ryaQuery.getQueries().iterator().next()); assertEquals(4, (int) ryaQuery.getNumQueryThreads()); assertEquals("regexObj", ryaQuery.getRegexObject()); assertEquals("regexPred", ryaQuery.getRegexPredicate()); diff --git a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategyTest.java index fe2c20ca4..13452ca0c 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategyTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategyTest.java @@ -18,17 +18,14 @@ */ package org.apache.rya.api.query.strategy.wholerow; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - +import junit.framework.TestCase; import org.apache.hadoop.io.Text; import org.apache.rya.api.RdfCloudTripleStoreConstants; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaIRIRange; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaTypeRange; -import org.apache.rya.api.domain.RyaIRI; -import org.apache.rya.api.domain.RyaIRIRange; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.query.strategy.TriplePatternStrategy; import org.apache.rya.api.resolver.RyaContext; @@ -40,7 +37,9 @@ import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.junit.Before; -import junit.framework.TestCase; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Date: 7/14/12 @@ -132,14 +131,14 @@ public void testRegex() throws Exception { public void testPoRange() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); - Map.Entry entry = strategy.defineRange(null, uri, rangeIRI, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(null, uri, rangeIRI, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(null, uri, rangeIRI2, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } private void assertContains(ByteRange value, byte[] row) { @@ -158,63 +157,63 @@ private void assertContainsFalse(ByteRange value, byte[] row) { public void testPoRangeCustomType() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, customType1, null)); + new RyaStatement(uri, uri, customType1)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); - Map.Entry entry = strategy.defineRange(null, uri, customTypeRange1, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(null, uri, customTypeRange1, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(null, uri, customTypeRange2, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testPo() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); - Map.Entry entry = strategy.defineRange(null, uri, uri, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(null, uri, uri, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(null, uri, uri2, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testPoCustomType() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, customType1, null)); + new RyaStatement(uri, uri, customType1)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); - Map.Entry entry = strategy.defineRange(null, uri, customType1, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(null, uri, customType1, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(null, uri, customType2, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testPosRange() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); - Map.Entry entry = strategy.defineRange(rangeIRI, uri, uri, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(rangeIRI, uri, uri, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(rangeIRI2, uri, uri, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testPRange() throws Exception { - Map.Entry entry = strategy.defineRange(null, rangeIRI, null, null, null); + ByteRange entry = strategy.defineRange(null, rangeIRI, null, null, null); assertNull(entry); } public void testP() throws Exception { - Map.Entry entry = strategy.defineRange(null, uri, null, null, null); + ByteRange entry = strategy.defineRange(null, uri, null, null, null); Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); - assertContains(entry.getValue(), tripleRow.getRow()); + assertContains(entry, tripleRow.getRow()); } public void testHandles() throws Exception { diff --git a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategyTest.java index 763c0d185..e0f790665 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategyTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategyTest.java @@ -8,9 +8,9 @@ * 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 @@ -19,15 +19,14 @@ * under the License. */ -import java.util.Map; - +import junit.framework.TestCase; import org.apache.hadoop.io.Text; import org.apache.rya.api.RdfCloudTripleStoreConstants; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaIRIRange; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaTypeRange; -import org.apache.rya.api.domain.RyaIRI; -import org.apache.rya.api.domain.RyaIRIRange; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTripleContext; @@ -36,7 +35,7 @@ import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.junit.Before; -import junit.framework.TestCase; +import java.util.Map; /** * Date: 7/14/12 @@ -61,111 +60,111 @@ public class HashedSpoWholeRowTriplePatternStrategyTest extends TestCase { @Before public void setUp() { - MockRdfConfiguration config = new MockRdfConfiguration(); - config.set(MockRdfConfiguration.CONF_PREFIX_ROW_WITH_HASH, Boolean.TRUE.toString()); - ryaTripleContext = RyaTripleContext.getInstance(config); + MockRdfConfiguration config = new MockRdfConfiguration(); + config.set(MockRdfConfiguration.CONF_PREFIX_ROW_WITH_HASH, Boolean.TRUE.toString()); + ryaTripleContext = RyaTripleContext.getInstance(config); } - + public void testSpo() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); - Map.Entry entry = strategy.defineRange(uri, uri, uri, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); - + ByteRange entry = strategy.defineRange(uri, uri, uri, null, null); + assertContains(entry, tripleRow.getRow()); + entry = strategy.defineRange(uri, uri, uri2, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } - private void assertContains(ByteRange value, byte[] row) { - Text rowText = new Text(row); - Text startText = new Text(value.getStart()); - Text endText = new Text(value.getEnd()); - assertTrue((startText.compareTo(rowText) <= 0) &&(endText.compareTo(rowText) >= 0)) ; - } + private void assertContains(ByteRange value, byte[] row) { + Text rowText = new Text(row); + Text startText = new Text(value.getStart()); + Text endText = new Text(value.getEnd()); + assertTrue((startText.compareTo(rowText) <= 0) && (endText.compareTo(rowText) >= 0)); + } - private void assertContainsFalse(ByteRange value, byte[] row) { - Text rowText = new Text(row); - Text startText = new Text(value.getStart()); - Text endText = new Text(value.getEnd()); - assertFalse((startText.compareTo(rowText) <= 0) &&(endText.compareTo(rowText) >= 0)) ; - } + private void assertContainsFalse(ByteRange value, byte[] row) { + Text rowText = new Text(row); + Text startText = new Text(value.getStart()); + Text endText = new Text(value.getEnd()); + assertFalse((startText.compareTo(rowText) <= 0) && (endText.compareTo(rowText) >= 0)); + } public void testSpoCustomType() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, customType1, null)); + new RyaStatement(uri, uri, customType1)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); - Map.Entry entry = strategy.defineRange(uri, uri, customType1, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(uri, uri, customType1, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(uri, uri, customType2, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testSpoRange() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); - Map.Entry entry = strategy.defineRange(uri, uri, rangeIRI, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(uri, uri, rangeIRI, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(uri, uri, rangeIRI2, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testSpoRangeCustomType() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, customType1, null)); + new RyaStatement(uri, uri, customType1)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); - Map.Entry entry = strategy.defineRange(uri, uri, customTypeRange1, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(uri, uri, customTypeRange1, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(uri, uri, customTypeRange2, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testSp() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); - Map.Entry entry = strategy.defineRange(uri, uri, null, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(uri, uri, null, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(uri, uri2, null, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testSpRange() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); - Map.Entry entry = strategy.defineRange(uri, rangeIRI, null, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + ByteRange entry = strategy.defineRange(uri, rangeIRI, null, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(uri, rangeIRI2, null, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testS() throws Exception { Map serialize = ryaTripleContext.serializeTriple( - new RyaStatement(uri, uri, uri, null)); + new RyaStatement(uri, uri, uri)); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); - - Map.Entry entry = strategy.defineRange(uri, null, null, null, null); - assertContains(entry.getValue(), tripleRow.getRow()); + + ByteRange entry = strategy.defineRange(uri, null, null, null, null); + assertContains(entry, tripleRow.getRow()); entry = strategy.defineRange(uri2, null, null, null, null); - assertContainsFalse(entry.getValue(), tripleRow.getRow()); + assertContainsFalse(entry, tripleRow.getRow()); } public void testSRange() throws Exception { - - Map.Entry entry = strategy.defineRange(rangeIRI, null, null, null, null); + + ByteRange entry = strategy.defineRange(rangeIRI, null, null, null, null); assertNull(entry); } diff --git a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/NullRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/NullRowTriplePatternStrategyTest.java index be607a817..0cc3e28ae 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/NullRowTriplePatternStrategyTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/NullRowTriplePatternStrategyTest.java @@ -18,19 +18,10 @@ */ package org.apache.rya.api.query.strategy.wholerow; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.Map; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.query.strategy.ByteRange; import org.junit.After; import org.junit.AfterClass; @@ -38,6 +29,13 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.util.Arrays; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + public class NullRowTriplePatternStrategyTest { public class MockRdfConfiguration extends RdfCloudTripleStoreConfiguration { @@ -91,11 +89,11 @@ public void testDefineRange() throws Exception { RyaIRI context = null; RdfCloudTripleStoreConfiguration conf = new MockRdfConfiguration(); NullRowTriplePatternStrategy instance = new NullRowTriplePatternStrategy(); - Map.Entry expResult = new RdfCloudTripleStoreUtils.CustomEntry<>(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new ByteRange(new byte[]{}, LAST_BYTES)); - Map.Entry result = instance.defineRange(subject, predicate, object, context, conf); - assertEquals(expResult.getKey(), result.getKey()); - assertTrue(Arrays.equals(expResult.getValue().getStart(), result.getValue().getStart())); - assertTrue(Arrays.equals(expResult.getValue().getEnd(), result.getValue().getEnd())); + ByteRange expResult = new ByteRange(new byte[]{}, LAST_BYTES); + ByteRange result = instance.defineRange(subject, predicate, object, context, conf); + assertEquals(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, instance.getLayout()); + assertTrue(Arrays.equals(expResult.getStart(), result.getStart())); + assertTrue(Arrays.equals(expResult.getEnd(), result.getEnd())); } /** diff --git a/common/rya.api/src/test/java/org/apache/rya/api/resolver/RdfToRyaConversionsTest.java b/common/rya.api/src/test/java/org/apache/rya/api/resolver/RdfToRyaConversionsTest.java index 5c835374a..17fb4743a 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/resolver/RdfToRyaConversionsTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/resolver/RdfToRyaConversionsTest.java @@ -18,19 +18,22 @@ */ package org.apache.rya.api.resolver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.List; -import java.util.Set; - +import com.google.common.collect.Lists; +import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl; +import org.apache.rya.api.domain.RangeIRI; +import org.apache.rya.api.domain.RangeValue; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaRange; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.utils.LiteralLanguageUtils; +import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleLiteral; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; @@ -39,7 +42,15 @@ import org.eclipse.rdf4j.model.vocabulary.XMLSchema; import org.junit.Test; -import com.google.common.collect.Lists; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Tests the methods of {@link RdfToRyaConversions}. @@ -51,8 +62,7 @@ public class RdfToRyaConversionsTest { @Test public void testConvertLiteral_null() { - final RyaType ryaType = RdfToRyaConversions.convertLiteral(null); - assertNull(ryaType); + assertNull(RdfToRyaConversions.convertLiteral(null)); } @Test @@ -63,8 +73,8 @@ public void testConvertLiteral_nullDataType() { when(literal.stringValue()).thenReturn(expectedData); // Don't think this is possible but test anyways. Need to mock to force this null value. when(literal.getDatatype()).thenReturn(null); - final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal); - final RyaType expected = new RyaType(XMLSchema.STRING, expectedData); + final RyaValue ryaType = RdfToRyaConversions.convertLiteral(literal); + final RyaValue expected = new RyaType(XMLSchema.STRING, expectedData); assertEquals(expected, ryaType); assertNull(ryaType.getLanguage()); } @@ -76,11 +86,11 @@ public void testConvertLiteral_validLanguage() { // This only checks the validity of the format. Not that the language tag actually exists. assertTrue(Literals.isValidLanguageTag(language)); final Literal literal = VF.createLiteral(expectedData, language); - final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal); + final RyaValue ryaType = RdfToRyaConversions.convertLiteral(literal); assertEquals(RDF.LANGSTRING, ryaType.getDataType()); assertEquals(expectedData, ryaType.getData()); assertEquals(language, ryaType.getLanguage()); - final RyaType expectedRyaType = new RyaType(RDF.LANGSTRING, expectedData, language); + final RyaValue expectedRyaType = new RyaType(RDF.LANGSTRING, expectedData, language); assertEquals(expectedRyaType, ryaType); } } @@ -91,10 +101,10 @@ public void testConvertLiteral_undeterminedLanguage() { final String language = LiteralLanguageUtils.UNDETERMINED_LANGUAGE; assertTrue(Literals.isValidLanguageTag(language)); final Literal literal = VF.createLiteral(expectedData, language); - final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal); + final RyaValue ryaType = RdfToRyaConversions.convertLiteral(literal); assertEquals(RDF.LANGSTRING, ryaType.getDataType()); assertEquals(expectedData, ryaType.getData()); - final RyaType expectedRyaType = new RyaType(RDF.LANGSTRING, expectedData, language); + final RyaValue expectedRyaType = new RyaType(RDF.LANGSTRING, expectedData, language); assertEquals(expectedRyaType, ryaType); assertEquals(LiteralLanguageUtils.UNDETERMINED_LANGUAGE, ryaType.getLanguage()); } @@ -111,7 +121,7 @@ public void testConvertLiteral_invalidLanguage() { // This only checks the validity of the format. Not that the language tag actually exists. assertFalse(Literals.isValidLanguageTag(badLanguage)); final Literal literal = VF.createLiteral(expectedData, badLanguage); - final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal); + final RyaValue ryaType = RdfToRyaConversions.convertLiteral(literal); assertEquals(RDF.LANGSTRING, ryaType.getDataType()); assertEquals(expectedData, ryaType.getData()); // Check that the invalid language is replaced with "und" @@ -123,11 +133,211 @@ public void testConvertLiteral_invalidLanguage() { public void testConvertLiteral_normalString() { final String expectedData = "Hello"; final Literal literal = VF.createLiteral(expectedData); - final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal); + final RyaValue ryaType = RdfToRyaConversions.convertLiteral(literal); assertEquals(XMLSchema.STRING, ryaType.getDataType()); assertEquals(expectedData, ryaType.getData()); - final RyaType expectedRyaType = new RyaType(XMLSchema.STRING, expectedData); + final RyaValue expectedRyaType = new RyaType(XMLSchema.STRING, expectedData); assertEquals(expectedRyaType, ryaType); assertNull(ryaType.getLanguage()); } + + @Test + public void testConvertValue() { + final String expectedData = "urn:the/test"; + final IRI iri = VF.createIRI(expectedData); + final RyaValue ryaType = RdfToRyaConversions.convertValue(iri); + assertEquals(XMLSchema.ANYURI, ryaType.getDataType()); + assertEquals(expectedData, ryaType.getData()); + final RyaValue expectedRyaType = new RyaType(XMLSchema.ANYURI, expectedData); + assertEquals(expectedRyaType, ryaType); + assertNull(ryaType.getLanguage()); + } + + @Test + public void testConvertLiteralValue() { + final String expectedData = "Value"; + final Literal value = VF.createLiteral(expectedData); + final RyaValue ryaType = RdfToRyaConversions.convertValue(value); + assertEquals(XMLSchema.STRING, ryaType.getDataType()); + assertEquals(expectedData, ryaType.getData()); + final RyaValue expectedRyaType = new RyaType(XMLSchema.STRING, expectedData); + assertEquals(expectedRyaType, ryaType); + assertNull(ryaType.getLanguage()); + } + + @Test + public void testConvertRyaValue() { + final String expectedData = "urn:the/test"; + final RyaValue value = new RyaType(expectedData); + final RyaValue ryaType = RdfToRyaConversions.convertValue(value); + assertEquals(XMLSchema.STRING, ryaType.getDataType()); + assertEquals(expectedData, ryaType.getData()); + final RyaValue expectedRyaType = new RyaType(XMLSchema.STRING, expectedData); + assertEquals(expectedRyaType, ryaType); + assertNull(ryaType.getLanguage()); + } + + @Test + public void testConvertRangeValueIRI() { + final RangeValue rangeValue = new RangeValue<>(VF.createIRI("urn:abc"), VF.createIRI("urn:xyz")); + final Value range = new RangeIRI(rangeValue); + final RyaRange ryaType = (RyaRange) RdfToRyaConversions.convertValue(range); + assertEquals(XMLSchema.ANYURI, ryaType.getStart().getDataType()); + assertEquals("urn:abc", ryaType.getStart().getData()); + assertNull(ryaType.getStart().getLanguage()); + assertEquals(XMLSchema.ANYURI, ryaType.getStop().getDataType()); + assertEquals("urn:xyz", ryaType.getStop().getData()); + assertNull(ryaType.getStop().getLanguage()); + } + + @Test + public void testConvertIRI() { + final String expectedData = "urn:the/test"; + final IRI iri = VF.createIRI(expectedData); + final RyaIRI ryaType = RdfToRyaConversions.convertIRI(iri); + assertEquals(XMLSchema.ANYURI, ryaType.getDataType()); + assertEquals(expectedData, ryaType.getData()); + final RyaValue expectedRyaType = new RyaType(XMLSchema.ANYURI, expectedData); + assertEquals(expectedRyaType, ryaType); + assertNull(ryaType.getLanguage()); + } + + @Test + public void testConvertRyaIRI() { + final String expectedData = "urn:the/test"; + final IRI iri = new RyaIRI(expectedData); + final RyaIRI ryaType = RdfToRyaConversions.convertIRI(iri); + assertEquals(XMLSchema.ANYURI, ryaType.getDataType()); + assertEquals(expectedData, ryaType.getData()); + final RyaValue expectedRyaType = new RyaType(XMLSchema.ANYURI, expectedData); + assertEquals(expectedRyaType, ryaType); + assertNull(ryaType.getLanguage()); + } + + @Test + public void testConvertRangeIRI() { + final RangeValue rangeValue = new RangeValue<>(VF.createIRI("urn:abc"), VF.createIRI("urn:xyz")); + final IRI rangeIRI = new RangeIRI(rangeValue); + final RyaRange ryaType = (RyaRange) RdfToRyaConversions.convertIRI(rangeIRI); + assertEquals(XMLSchema.ANYURI, ryaType.getStart().getDataType()); + assertEquals("urn:abc", ryaType.getStart().getData()); + assertNull(ryaType.getStart().getLanguage()); + assertEquals(XMLSchema.ANYURI, ryaType.getStop().getDataType()); + assertEquals("urn:xyz", ryaType.getStop().getData()); + assertNull(ryaType.getStop().getLanguage()); + } + + @Test + public void testConvertResource() { + final String expectedData = "urn:the/test"; + final IRI iri = VF.createIRI(expectedData); + final RyaResource ryaType = RdfToRyaConversions.convertResource(iri); + assertEquals(XMLSchema.ANYURI, ryaType.getDataType()); + assertEquals(expectedData, ryaType.getData()); + final RyaValue expectedRyaType = new RyaType(XMLSchema.ANYURI, expectedData); + assertEquals(expectedRyaType, ryaType); + assertNull(ryaType.getLanguage()); + } + + @Test + public void testConvertResourceRyaIRI() { + final String expectedData = "urn:the/test"; + final IRI iri = new RyaIRI(expectedData); + final RyaResource ryaType = RdfToRyaConversions.convertResource(iri); + assertEquals(XMLSchema.ANYURI, ryaType.getDataType()); + assertEquals(expectedData, ryaType.getData()); + final RyaValue expectedRyaType = new RyaType(XMLSchema.ANYURI, expectedData); + assertEquals(expectedRyaType, ryaType); + assertNull(ryaType.getLanguage()); + } + + @Test + public void testConvertResources() { + final String expectedData1 = "urn:the/test1"; + final String expectedData2 = "urn:the/test2"; + final IRI[] iri = {VF.createIRI(expectedData1), VF.createIRI(expectedData2)}; + final RyaResource[] ryaType = RdfToRyaConversions.convertResource(iri); + assertEquals(2, ryaType.length); + + assertEquals(XMLSchema.ANYURI, ryaType[0].getDataType()); + assertEquals(expectedData1, ryaType[0].getData()); + final RyaValue expectedRyaType1 = new RyaType(XMLSchema.ANYURI, expectedData1); + assertEquals(expectedRyaType1, ryaType[0]); + assertNull(ryaType[0].getLanguage()); + + assertEquals(XMLSchema.ANYURI, ryaType[1].getDataType()); + assertEquals(expectedData2, ryaType[1].getData()); + final RyaValue expectedRyaType2 = new RyaType(XMLSchema.ANYURI, expectedData2); + assertEquals(expectedRyaType2, ryaType[1]); + assertNull(ryaType[1].getLanguage()); + } + + @Test + public void testConvertStatement() { + final Resource subject = VF.createIRI("urn:subject"); + final IRI predicate = VF.createIRI("urn:predicate"); + final Value object = VF.createIRI("urn:object"); + final Resource context = VF.createIRI("urn:context"); + final Statement statement = VF.createStatement(subject, predicate, object, context); + final RyaStatement ryaType = RdfToRyaConversions.convertStatement(statement); + assertEquals(subject.stringValue(), ryaType.getSubject().stringValue()); + assertEquals(predicate.stringValue(), ryaType.getPredicate().stringValue()); + assertEquals(object.stringValue(), ryaType.getObject().stringValue()); + assertEquals("urn:", ((IRI)statement.getObject()).getNamespace()); + assertEquals("object", ((IRI)statement.getObject()).getLocalName()); + assertEquals(context.stringValue(), ryaType.getContext().stringValue()); + //assertSame(ryaType, RdfToRyaConversions.convertStatement((Statement) ryaType)); + } + + @Test + public void testConvertStatementLiteral() { + final Resource subject = VF.createIRI("urn:subject"); + final IRI predicate = VF.createIRI("urn:predicate"); + final Value object = VF.createLiteral("Some String"); + final Resource context = VF.createIRI("urn:context"); + final Statement statement = VF.createStatement(subject, predicate, object, context); + final RyaStatement ryaStatement = RdfToRyaConversions.convertStatement(statement); + assertEquals(subject.stringValue(), ryaStatement.getSubject().stringValue()); + assertEquals(predicate.stringValue(), ryaStatement.getPredicate().stringValue()); + assertEquals(object.stringValue(), ryaStatement.getObject().stringValue()); + assertEquals("Some String", ryaStatement.getObject().getData()); + assertEquals(XMLSchema.STRING, ryaStatement.getObject().getDataType()); + assertNull(ryaStatement.getObject().getLanguage()); + assertEquals(context.stringValue(), ryaStatement.getContext().stringValue()); + } + + @Test + public void testConvertStatementLiteralDouble() { + final Resource subject = VF.createIRI("urn:subject"); + final IRI predicate = VF.createIRI("urn:predicate"); + final Value object = VF.createLiteral(12.345); + final Resource context = VF.createIRI("urn:context"); + final Statement statement = VF.createStatement(subject, predicate, object, context); + final RyaStatement ryaStatement = RdfToRyaConversions.convertStatement(statement); + assertEquals(subject.stringValue(), ryaStatement.getSubject().stringValue()); + assertEquals(predicate.stringValue(), ryaStatement.getPredicate().stringValue()); + assertEquals(object.stringValue(), ryaStatement.getObject().stringValue()); + assertEquals("12.345", ryaStatement.getObject().getData()); + assertEquals(XMLSchema.DOUBLE, ryaStatement.getObject().getDataType()); + assertNull(ryaStatement.getObject().getLanguage()); + assertEquals(context.stringValue(), ryaStatement.getContext().stringValue()); + } + + @Test + public void testConvertStatementLiteralDate() { + final Resource subject = VF.createIRI("urn:subject"); + final IRI predicate = VF.createIRI("urn:predicate"); + final Value object = VF.createLiteral(XMLGregorianCalendarImpl.createDate(2020, 05, 07, 5 * 60)); + final Resource context = VF.createIRI("urn:context"); + final Statement statement = VF.createStatement(subject, predicate, object, context); + final RyaStatement ryaStatement = RdfToRyaConversions.convertStatement(statement); + assertEquals(subject.stringValue(), ryaStatement.getSubject().stringValue()); + assertEquals(predicate.stringValue(), ryaStatement.getPredicate().stringValue()); + assertEquals(object.stringValue(), ryaStatement.getObject().stringValue()); + assertEquals("2020-05-07+05:00", ryaStatement.getObject().getData()); + assertEquals(XMLSchema.DATE, ryaStatement.getObject().getDataType()); + assertNull(ryaStatement.getObject().getLanguage()); + assertEquals(context.stringValue(), ryaStatement.getContext().stringValue()); + } + } \ No newline at end of file diff --git a/common/rya.api/src/test/java/org/apache/rya/api/resolver/RyaToRdfConversionsTest.java b/common/rya.api/src/test/java/org/apache/rya/api/resolver/RyaToRdfConversionsTest.java index 242221f05..c02624589 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/resolver/RyaToRdfConversionsTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/resolver/RyaToRdfConversionsTest.java @@ -18,24 +18,33 @@ */ package org.apache.rya.api.resolver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.Set; - +import com.google.common.collect.Lists; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.utils.LiteralLanguageUtils; +import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleLiteral; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.util.Literals; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; import org.junit.Test; -import com.google.common.collect.Lists; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * Tests the methods of {@link RyaToRdfConversionsTest}. @@ -45,9 +54,9 @@ public class RyaToRdfConversionsTest { private static final Set LANGUAGE_CODES = LanguageCodesTestHelper.getInstance().getLanguageCodes(); - @Test (expected=NullPointerException.class) + @Test public void testConvertLiteral_null() { - RyaToRdfConversions.convertLiteral(null); + assertNull(RyaToRdfConversions.convertLiteral(null)); } @Test @@ -124,4 +133,99 @@ public void testConvertLiteral_normalString() { final Literal expectedLiteral = VF.createLiteral(expectedData); assertEquals(expectedLiteral, literal); } + + @Test + public void testConvertValue() { + final String expectedData = "urn:the/test"; + final RyaValue ryaValue = new RyaIRI(expectedData); + final Value value = RyaToRdfConversions.convertValue(ryaValue); + assertEquals(expectedData, value.stringValue()); + assertTrue(value.getClass().getName(), value instanceof IRI); + } + + @Test + public void testConvertLiteralValue() { + final String expectedData = "Value"; + final RyaValue ryaValue = new RyaType(expectedData); + final Value value = RyaToRdfConversions.convertValue(ryaValue); + assertEquals(expectedData, value.stringValue()); + assertTrue(value.getClass().getName(), value instanceof Literal); + } + + @Test + public void testConvertIRIValueByDataType() { + final String expectedData = "urn:the/test"; + final RyaValue ryaValue = new RyaType(XMLSchema.ANYURI, expectedData); + final Value value = RyaToRdfConversions.convertValue(ryaValue); + assertEquals(expectedData, value.stringValue()); + assertTrue(value.getClass().getName(), value instanceof IRI); + } + + @Test + public void testConvertIRI() { + final String expectedData = "urn:the/test"; + final RyaResource ryaResource = new RyaIRI(expectedData); + final Resource resource = RyaToRdfConversions.convertResource(ryaResource); + assertEquals(expectedData, resource.stringValue()); + assertTrue(resource.getClass().getName(), resource instanceof IRI); + } + + @Test + public void testConvertResource() { + final String expectedData = "urn:the/test"; + final RyaIRI ryaIRI = new RyaIRI(expectedData); + final IRI iri = RyaToRdfConversions.convertIRI(ryaIRI); + assertEquals(expectedData, iri.toString()); + assertEquals("test", iri.getLocalName()); + assertEquals("urn:the/", iri.getNamespace()); + } + + @Test + public void testConvertResources() { + final String expectedData1 = "urn:the/test1"; + final String expectedData2 = "urn:the/test2"; + final RyaResource[] ryaResources = {new RyaIRI(expectedData1), new RyaIRI(expectedData2)}; + final Resource[] resources = RyaToRdfConversions.convertResource(ryaResources); + assertEquals(2, resources.length); + + assertEquals(expectedData1, ((IRI)resources[0]).toString()); + assertEquals("test1", ((IRI)resources[0]).getLocalName()); + assertEquals("urn:the/", ((IRI)resources[0]).getNamespace()); + + assertEquals(expectedData2, ((IRI)resources[1]).toString()); + assertEquals("test2", ((IRI)resources[1]).getLocalName()); + assertEquals("urn:the/", ((IRI)resources[1]).getNamespace()); + } + + @Test + public void testConvertStatement() { + final RyaResource subject = new RyaIRI("urn:subject"); + final RyaIRI predicate = new RyaIRI("urn:predicate"); + final RyaValue object = new RyaIRI("urn:object"); + final RyaResource context = new RyaIRI("urn:context"); + final RyaStatement ryaStatement = new RyaStatement(subject, predicate, object, context); + final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); + assertEquals(subject.stringValue(), statement.getSubject().stringValue()); + assertEquals(predicate.stringValue(), statement.getPredicate().stringValue()); + assertEquals(object.stringValue(), statement.getObject().stringValue()); + assertEquals(context.stringValue(), statement.getContext().stringValue()); + } + + @Test + public void testConvertStatementLiteral() { + final RyaResource subject = new RyaIRI("urn:subject"); + final RyaIRI predicate = new RyaIRI("urn:predicate"); + final RyaValue object = new RyaType(XMLSchema.DOUBLE, "12.345"); + final RyaResource context = new RyaIRI("urn:context"); + final RyaStatement ryaStatement = new RyaStatement(subject, predicate, object, context); + final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); + assertEquals(subject.stringValue(), statement.getSubject().stringValue()); + assertEquals(predicate.stringValue(), statement.getPredicate().stringValue()); + assertEquals(object.stringValue(), statement.getObject().stringValue()); + assertEquals(12.345, ((SimpleLiteral)statement.getObject()).doubleValue(), 0.0001); + assertFalse(((SimpleLiteral)statement.getObject()).getLanguage().isPresent()); + assertEquals(XMLSchema.DOUBLE, ((SimpleLiteral)statement.getObject()).getDatatype()); + assertEquals(context.stringValue(), statement.getContext().stringValue()); + } + } \ No newline at end of file diff --git a/common/rya.api/src/test/java/org/apache/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java b/common/rya.api/src/test/java/org/apache/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java index 2dcb362ff..d81fc33e0 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java @@ -20,15 +20,15 @@ */ - -import java.util.Map; - import junit.framework.TestCase; import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.resolver.triple.TripleRow; +import java.util.Map; + /** * Date: 7/25/12 * Time: 10:52 AM @@ -43,8 +43,8 @@ public void testSerialize() throws Exception { RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaIRI cntxt = new RyaIRI("urn:test#cntxt"); - final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); - final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, (StatementMetadata) null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, (StatementMetadata) null, null, 100l); Map serialize = tripleResolver.serialize(stmt); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); @@ -65,8 +65,8 @@ public void testSerializePO() throws Exception { RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaIRI cntxt = new RyaIRI("urn:test#cntxt"); - final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); - final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, (StatementMetadata) null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, (StatementMetadata) null, null, 100l); Map serialize = tripleResolver.serialize(stmt); TripleRow tripleRow = serialize.get(po); RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); @@ -86,8 +86,8 @@ public void testSerializeOSP() throws Exception { RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaIRI cntxt = new RyaIRI("urn:test#cntxt"); - final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); - final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, (StatementMetadata) null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, (StatementMetadata) null, null, 100l); Map serialize = tripleResolver.serialize(stmt); TripleRow tripleRow = serialize.get(po); RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); @@ -107,8 +107,8 @@ public void testSerializeOSPCustomType() throws Exception { RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaIRI cntxt = new RyaIRI("urn:test#cntxt"); - final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); - final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, (StatementMetadata) null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, (StatementMetadata) null, null, 100l); Map serialize = tripleResolver.serialize(stmt); TripleRow tripleRow = serialize.get(po); RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); diff --git a/common/rya.api/src/test/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java b/common/rya.api/src/test/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java index a8120680f..026accbe0 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java @@ -20,17 +20,14 @@ */ - import junit.framework.TestCase; import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.resolver.triple.TripleRow; -import org.apache.rya.api.resolver.triple.TripleRowRegex; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * Date: 7/25/12 @@ -46,8 +43,8 @@ public void testSerialize() throws Exception { RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaIRI cntxt = new RyaIRI("urn:test#cntxt"); - final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); - final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, (StatementMetadata) null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, (StatementMetadata) null, null, 100l); Map serialize = tripleResolver.serialize(stmt); TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); @@ -68,8 +65,8 @@ public void testSerializePO() throws Exception { RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaIRI cntxt = new RyaIRI("urn:test#cntxt"); - final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); - final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, (StatementMetadata) null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, (StatementMetadata) null, null, 100l); Map serialize = tripleResolver.serialize(stmt); TripleRow tripleRow = serialize.get(po); RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); @@ -89,8 +86,8 @@ public void testSerializeOSP() throws Exception { RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaIRI cntxt = new RyaIRI("urn:test#cntxt"); - final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); - final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, (StatementMetadata) null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, (StatementMetadata) null, null, 100l); Map serialize = tripleResolver.serialize(stmt); TripleRow tripleRow = serialize.get(po); RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); @@ -110,8 +107,8 @@ public void testSerializeOSPCustomType() throws Exception { RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaIRI cntxt = new RyaIRI("urn:test#cntxt"); - final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); - final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, (StatementMetadata) null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, (StatementMetadata) null, null, 100l); Map serialize = tripleResolver.serialize(stmt); TripleRow tripleRow = serialize.get(po); RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfigurationBuilder.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfigurationBuilder.java index 0640f6531..44fe733d4 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfigurationBuilder.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfigurationBuilder.java @@ -73,22 +73,16 @@ public static AccumuloRdfConfigurationBuilder fromProperties(Properties props) { .setAuths(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.ACCUMULO_AUTHS, "")) // .setRyaPrefix(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.ACCUMULO_RYA_PREFIX, "rya_"))// .setVisibilities(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.ACCUMULO_VISIBILITIES, "")) - .setUseInference( - getBoolean(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_INFERENCE, "false")))// - .setDisplayQueryPlan(getBoolean( - props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_DISPLAY_QUERY_PLAN, "true")))// + .setUseInference(getBoolean(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_INFERENCE, "false")))// + .setDisplayQueryPlan(getBoolean(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_DISPLAY_QUERY_PLAN, "true")))// .setAccumuloUser(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.ACCUMULO_USER)) // .setAccumuloInstance(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.ACCUMULO_INSTANCE))// .setAccumuloZooKeepers(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.ACCUMULO_ZOOKEEPERS))// .setAccumuloPassword(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.ACCUMULO_PASSWORD))// - .setUseMockAccumulo(getBoolean( - props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_MOCK_ACCUMULO, "false")))// - .setUseAccumuloPrefixHashing(getBoolean( - props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_PREFIX_HASHING, "false")))// - .setUseCompositeCardinality( - getBoolean(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_COUNT_STATS, "false")))// - .setUseJoinSelectivity(getBoolean( - props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_JOIN_SELECTIVITY, "false"))); + .setUseMockAccumulo(getBoolean(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_MOCK_ACCUMULO, "false")))// + .setUseAccumuloPrefixHashing(getBoolean(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_PREFIX_HASHING, "false")))// + .setUseCompositeCardinality(getBoolean(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_COUNT_STATS, "false")))// + .setUseJoinSelectivity(getBoolean(props.getProperty(AbstractAccumuloRdfConfigurationBuilder.USE_JOIN_SELECTIVITY, "false"))); return builder; } diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java index 6675ae3ff..45c43f24d 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java @@ -18,21 +18,6 @@ */ package org.apache.rya.accumulo; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.PREDOBJECT_CF_TXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.PRED_CF_TXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECTOBJECT_CF_TXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECTPRED_CF_TXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECT_CF_TXT; - -import java.nio.charset.StandardCharsets; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.client.admin.TableOperations; @@ -46,6 +31,21 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Value; +import java.nio.charset.StandardCharsets; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.PREDOBJECT_CF_TXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.PRED_CF_TXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECTOBJECT_CF_TXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECTPRED_CF_TXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECT_CF_TXT; + /** * Class AccumuloRdfEvalStatsDAO * Date: Feb 28, 2012 diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfUtils.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfUtils.java index 4f882a37b..8241dbd70 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfUtils.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfUtils.java @@ -19,10 +19,6 @@ * under the License. */ - - -import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.TableExistsException; @@ -31,6 +27,7 @@ import org.apache.accumulo.core.data.Value; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.rya.api.resolver.triple.TripleRow; import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java index 9b3752b30..3fc8ae00c 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java @@ -18,27 +18,8 @@ */ package org.apache.rya.accumulo; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.apache.rya.accumulo.AccumuloRdfConstants.ALL_AUTHORIZATIONS; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.INFO_NAMESPACE_TXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.MAX_MEMORY; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.MAX_TIME; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.NUM_THREADS; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.RTS_SUBJECT_RYA; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.RTS_VERSION_PREDICATE_RYA; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.VERSION_RYA; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - +import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchDeleter; @@ -62,18 +43,37 @@ import org.apache.rya.accumulo.query.AccumuloRyaQueryEngine; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.layout.TableLayoutStrategy; import org.apache.rya.api.persist.RyaDAO; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.RyaNamespaceManager; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RyaTripleContext; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.model.Namespace; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.apache.rya.accumulo.AccumuloRdfConstants.ALL_AUTHORIZATIONS; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.INFO_NAMESPACE_TXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.MAX_MEMORY; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.MAX_TIME; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.NUM_THREADS; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.RTS_SUBJECT_RYA; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.RTS_VERSION_PREDICATE_RYA; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.VERSION_RYA; public class AccumuloRyaDAO implements RyaDAO, RyaNamespaceManager { private static final Log logger = LogFactory.getLog(AccumuloRyaDAO.class); @@ -141,7 +141,7 @@ public void init() throws RyaDAOException { mt_bw = connector.createMultiTableBatchWriter(batchWriterConfig); - //get the batch writers for tables + // Get the batch writers for tables bw_spo = mt_bw.getBatchWriter(tableLayoutStrategy.getSpo()); bw_po = mt_bw.getBatchWriter(tableLayoutStrategy.getPo()); bw_osp = mt_bw.getBatchWriter(tableLayoutStrategy.getOsp()); @@ -149,9 +149,9 @@ public void init() throws RyaDAOException { bw_ns = mt_bw.getBatchWriter(tableLayoutStrategy.getNs()); for (final AccumuloIndexer index : secondaryIndexers) { - index.setConnector(connector); - index.setMultiTableBatchWriter(mt_bw); - index.init(); + index.setConnector(connector); + index.setMultiTableBatchWriter(mt_bw); + index.init(); } queryEngine = new AccumuloRyaQueryEngine(connector, conf); @@ -167,7 +167,7 @@ public void init() throws RyaDAOException { @Override public String getVersion() throws RyaDAOException { String version = null; - final CloseableIteration versIter = queryEngine.query(new RyaStatement(RTS_SUBJECT_RYA, RTS_VERSION_PREDICATE_RYA, null), conf); + final CloseableIteration versIter = RyaDAOHelper.query(queryEngine, new RyaStatement(RTS_SUBJECT_RYA, RTS_VERSION_PREDICATE_RYA, null), conf); if (versIter.hasNext()) { version = versIter.next().getObject().getData(); } @@ -187,8 +187,8 @@ public void add(final Iterator iter) throws RyaDAOException { } @Override - public void delete(final RyaStatement stmt, final AccumuloRdfConfiguration aconf) throws RyaDAOException { - this.delete(Iterators.singletonIterator(stmt), aconf); + public void delete(final RyaStatement stmt, final AccumuloRdfConfiguration conf) throws RyaDAOException { + this.delete(Iterators.singletonIterator(stmt), conf); } @Override @@ -197,9 +197,10 @@ public void delete(final Iterator statements, final AccumuloRdfCon while (statements.hasNext()) { final RyaStatement stmt = statements.next(); //query first - final CloseableIteration query = this.queryEngine.query(stmt, conf); + final CloseableIteration query = RyaDAOHelper.query(queryEngine, stmt, conf); while (query.hasNext()) { - deleteSingleRyaStatement(query.next()); + RyaStatement statement = query.next(); + deleteSingleRyaStatement(statement); } for (final AccumuloIndexer index : secondaryIndexers) { @@ -215,7 +216,7 @@ public void delete(final Iterator statements, final AccumuloRdfCon } @Override - public void dropGraph(final AccumuloRdfConfiguration conf, final RyaIRI... graphs) throws RyaDAOException { + public void dropGraph(final AccumuloRdfConfiguration conf, final RyaResource... graphs) throws RyaDAOException { BatchDeleter bd_spo = null; BatchDeleter bd_po = null; BatchDeleter bd_osp = null; @@ -229,7 +230,7 @@ public void dropGraph(final AccumuloRdfConfiguration conf, final RyaIRI... graph bd_po.setRanges(Collections.singleton(new Range())); bd_osp.setRanges(Collections.singleton(new Range())); - for (final RyaIRI graph : graphs){ + for (final RyaResource graph : graphs){ bd_spo.fetchColumnFamily(new Text(graph.getData())); bd_po.fetchColumnFamily(new Text(graph.getData())); bd_osp.fetchColumnFamily(new Text(graph.getData())); @@ -548,7 +549,7 @@ private BatchDeleter createBatchDeleter(final String tableName, final Authorizat private void checkVersion() throws RyaDAOException, IOException, MutationsRejectedException { final String version = getVersion(); if (version == null) { - //adding to core Rya tables but not Indexes + // Adding version to core Rya tables but not Indexes final Map> mutationMap = ryaTableMutationsFactory.serialize(getVersionRyaStatement()); final Collection spo = mutationMap.get(TABLE_LAYOUT.SPO); final Collection po = mutationMap.get(TABLE_LAYOUT.PO); diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/RyaTableKeyValues.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/RyaTableKeyValues.java index 7361c692e..eda3cd670 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/RyaTableKeyValues.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/RyaTableKeyValues.java @@ -8,9 +8,9 @@ * 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 @@ -19,14 +19,6 @@ * under the License. */ -import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_VALUE; - -import java.io.IOException; -import java.util.AbstractMap.SimpleEntry; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; - import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.security.ColumnVisibility; @@ -38,6 +30,14 @@ import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolverException; +import java.io.IOException; +import java.util.AbstractMap.SimpleEntry; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_VALUE; + public class RyaTableKeyValues { public static final ColumnVisibility EMPTY_CV = new ColumnVisibility(); public static final Text EMPTY_CV_TEXT = new Text(EMPTY_CV.getExpression()); @@ -45,9 +45,9 @@ public class RyaTableKeyValues { RyaTripleContext instance; private RyaStatement stmt; - private Collection> spo = new ArrayList>(); - private Collection> po = new ArrayList>(); - private Collection> osp = new ArrayList>(); + private Collection> spo = new ArrayList<>(); + private Collection> po = new ArrayList<>(); + private Collection> osp = new ArrayList<>(); public RyaTableKeyValues(RyaStatement stmt, RdfCloudTripleStoreConfiguration conf) { this.stmt = stmt; @@ -71,8 +71,9 @@ public RyaTableKeyValues invoke() throws IOException { /** * TODO: If there are contexts, do we still replicate the information into the default graph as well * as the named graphs? - */try { - Map rowMap = instance.serializeTriple(stmt); + */ + try { + Map rowMap = instance.serializeTriple(stmt); TripleRow tripleRow = rowMap.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); byte[] columnVisibility = tripleRow.getColumnVisibility(); Text cv = columnVisibility == null ? EMPTY_CV_TEXT : new Text(columnVisibility); diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/RyaTableMutationsFactory.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/RyaTableMutationsFactory.java index 05c3c86f4..05c4f04de 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/RyaTableMutationsFactory.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/RyaTableMutationsFactory.java @@ -8,9 +8,9 @@ * 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 @@ -19,42 +19,41 @@ * under the License. */ -import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_CV; -import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_VALUE; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.security.ColumnVisibility; import org.apache.hadoop.io.Text; -import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.resolver.RyaTripleContext; import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolverException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_CV; +import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_VALUE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; + public class RyaTableMutationsFactory { RyaTripleContext ryaContext; public RyaTableMutationsFactory(RyaTripleContext ryaContext) { - this.ryaContext = ryaContext; + this.ryaContext = ryaContext; } //TODO: Does this still need to be collections - public Map> serialize( + public Map> serialize( RyaStatement stmt) throws IOException { - Collection spo_muts = new ArrayList(); - Collection po_muts = new ArrayList(); - Collection osp_muts = new ArrayList(); + Collection spo_muts = new ArrayList<>(); + Collection po_muts = new ArrayList<>(); + Collection osp_muts = new ArrayList<>(); /** * TODO: If there are contexts, do we still replicate the information into the default graph as well * as the named graphs? @@ -71,25 +70,20 @@ public Map> seri throw new IOException(fe); } - Map> mutations = - new HashMap>(); - mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, spo_muts); - mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO, po_muts); - mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP, osp_muts); + Map> mutations = new HashMap<>(); + mutations.put(TABLE_LAYOUT.SPO, spo_muts); + mutations.put(TABLE_LAYOUT.PO, po_muts); + mutations.put(TABLE_LAYOUT.OSP, osp_muts); return mutations; } - public Map> serializeDelete( + public Map> serializeDelete( RyaStatement stmt) throws IOException { - Collection spo_muts = new ArrayList(); - Collection po_muts = new ArrayList(); - Collection osp_muts = new ArrayList(); - /** - * TODO: If there are contexts, do we still replicate the information into the default graph as well - * as the named graphs? - */ + Collection spo_muts = new ArrayList<>(); + Collection po_muts = new ArrayList<>(); + Collection osp_muts = new ArrayList<>(); try { Map rowMap = ryaContext.serializeTriple(stmt); TripleRow tripleRow = rowMap.get(TABLE_LAYOUT.SPO); @@ -102,11 +96,10 @@ public Map> seri throw new IOException(fe); } - Map> mutations = - new HashMap>(); - mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, spo_muts); - mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO, po_muts); - mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP, osp_muts); + Map> mutations = new HashMap<>(); + mutations.put(TABLE_LAYOUT.SPO, spo_muts); + mutations.put(TABLE_LAYOUT.PO, po_muts); + mutations.put(TABLE_LAYOUT.OSP, osp_muts); return mutations; diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java index b39f44f3d..226c638f3 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java @@ -46,9 +46,11 @@ import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; import org.apache.rya.api.domain.RyaRange; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.layout.TableLayoutStrategy; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.query.BatchRyaQuery; @@ -129,9 +131,9 @@ public CloseableIteration, RyaDAOE Collection ranges = new HashSet(); RangeBindingSetEntries rangeMap = new RangeBindingSetEntries(); TABLE_LAYOUT layout = null; - RyaIRI context = null; + RyaResource context = null; TriplePatternStrategy strategy = null; - RyaIRI columnFamily = null; + RyaResource columnFamily = null; boolean columnFamilySet = false; for (Map.Entry stmtbs : stmts) { RyaStatement stmt = stmtbs.getKey(); @@ -152,13 +154,12 @@ public CloseableIteration, RyaDAOE throw new IllegalArgumentException("TriplePattern[" + stmt + "] not supported"); } - Map.Entry entry = strategy.defineRange(stmt.getSubject(), + ByteRange byteRange = strategy.defineRange(stmt.getSubject(), stmt.getPredicate(), stmt.getObject(), stmt.getContext(), conf); // use range to set scanner // populate scanner based on authorizations, ttl - layout = entry.getKey(); - ByteRange byteRange = entry.getValue(); + layout = strategy.getLayout(); Range range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd())); Range rangeMapRange = range; // if context != null, bind context info to Range so that @@ -269,18 +270,17 @@ public CloseableIterable query(RyaQuery ryaQuery) throws RyaDAOExc TriplePatternStrategy strategy = ryaContext.retrieveStrategy(stmt); TABLE_LAYOUT layout; Range range; - RyaIRI subject = stmt.getSubject(); + RyaResource subject = stmt.getSubject(); RyaIRI predicate = stmt.getPredicate(); - RyaType object = stmt.getObject(); - RyaIRI context = stmt.getContext(); + RyaValue object = stmt.getObject(); + RyaResource context = stmt.getContext(); String qualifier = stmt.getQualifer(); TripleRowRegex tripleRowRegex = null; if (strategy != null) { // otherwise, full table scan is supported - Map.Entry entry = strategy.defineRange(subject, predicate, object, + ByteRange byteRange = strategy.defineRange(subject, predicate, object, context, null); - layout = entry.getKey(); - ByteRange byteRange = entry.getValue(); + layout = strategy.getLayout(); range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd())); } else { @@ -347,7 +347,7 @@ public CloseableIterable query(BatchRyaQuery ryaQuery) throws RyaD try { Collection ranges = new HashSet(); TABLE_LAYOUT layout = null; - RyaIRI context = null; + RyaResource context = null; TriplePatternStrategy strategy = null; for (RyaStatement stmt : stmts) { context = stmt.getContext(); // TODO: This will be overwritten @@ -356,13 +356,12 @@ public CloseableIterable query(BatchRyaQuery ryaQuery) throws RyaD throw new IllegalArgumentException("TriplePattern[" + stmt + "] not supported"); } - Map.Entry entry = strategy.defineRange(stmt.getSubject(), + ByteRange byteRange = strategy.defineRange(stmt.getSubject(), stmt.getPredicate(), stmt.getObject(), stmt.getContext(), null); // use range to set scanner // populate scanner based on authorizations, ttl - layout = entry.getKey(); - ByteRange byteRange = entry.getValue(); + layout = strategy.getLayout(); Range range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd())); ranges.add(range); } @@ -382,7 +381,7 @@ public CloseableIterable query(BatchRyaQuery ryaQuery) throws RyaD results = FluentCloseableIterable.from(new ScannerBaseCloseableIterable(scanner)) .transform(keyValueToRyaStatementFunctionMap.get(layout)); } else { - final RyaIRI fcontext = context; + final RyaResource fcontext = context; final RdfCloudTripleStoreConfiguration fconf = ryaQuery.getConf(); FluentIterable fluent = FluentIterable.from(ranges) .transformAndConcat(new Function>>() { @@ -410,7 +409,7 @@ public Iterable> apply(Range range) { } } - protected void fillScanner(ScannerBase scanner, RyaIRI context, String qualifier, Long ttl, Long currentTime, + protected void fillScanner(ScannerBase scanner, RyaResource context, String qualifier, Long ttl, Long currentTime, TripleRowRegex tripleRowRegex, RdfCloudTripleStoreConfiguration conf) throws IOException { if (context != null && qualifier != null) { scanner.fetchColumn(new Text(context.getData()), new Text(qualifier)); diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/RangeBindingSetEntries.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/RangeBindingSetEntries.java index 7d152237f..3242ede87 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/RangeBindingSetEntries.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/RangeBindingSetEntries.java @@ -18,24 +18,24 @@ */ package org.apache.rya.accumulo.query; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.WritableComparator; import org.eclipse.rdf4j.query.BindingSet; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; /** * Class RangeBindingSetCollection Date: Feb 23, 2011 Time: 10:15:48 AM */ public class RangeBindingSetEntries { - private Multimap ranges = HashMultimap.create(); + private Multimap ranges; public RangeBindingSetEntries() { ranges = HashMultimap.create(); @@ -45,6 +45,13 @@ public void put(Range range, BindingSet bs) { ranges.put(range, bs); } + /** + * This method is used to see if a returned {@link Key}/{@link Value} pair is represented by a particular scan range. + * We need to expand upon the default Accumulo behavior by checking not just the row but also the column. + * This is very important when we are looking for specific context values (that are in the column family). + * @param key The returned {@link Key} to be checked. + * @return The relevant {@link BindingSet}s of the returned data from the input query. + */ public Collection containsKey(Key key) { Set bsSet = new HashSet<>(); for (Range range : ranges.keySet()) { diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/RyaStatementKeyValueIterator.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/RyaStatementKeyValueIterator.java index 8f6fe3492..84dffa578 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/RyaStatementKeyValueIterator.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/RyaStatementKeyValueIterator.java @@ -19,9 +19,6 @@ * under the License. */ -import java.util.Iterator; -import java.util.Map; - import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; @@ -32,10 +29,14 @@ import org.apache.rya.api.resolver.triple.TripleRowResolverException; import org.eclipse.rdf4j.common.iteration.CloseableIteration; +import java.util.Iterator; +import java.util.Map; + /** * Date: 7/17/12 * Time: 11:48 AM */ +@Deprecated public class RyaStatementKeyValueIterator implements CloseableIteration { private Iterator> dataIterator; private TABLE_LAYOUT tableLayout; diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/ScannerBaseCloseableIterable.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/ScannerBaseCloseableIterable.java index 199972e92..5b8202a01 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/ScannerBaseCloseableIterable.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/ScannerBaseCloseableIterable.java @@ -8,9 +8,9 @@ * 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 @@ -19,8 +19,6 @@ * under the License. */ - - import com.google.common.base.Preconditions; import org.apache.accumulo.core.client.ScannerBase; import org.apache.accumulo.core.data.Key; @@ -35,6 +33,7 @@ * Date: 1/30/13 * Time: 2:15 PM */ +@Deprecated public class ScannerBaseCloseableIterable extends AbstractCloseableIterable> { protected ScannerBase scanner; diff --git a/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/AccumuloRyaDAOTest.java b/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/AccumuloRyaDAOTest.java index 35d18ea73..38b4b8918 100644 --- a/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/AccumuloRyaDAOTest.java +++ b/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/AccumuloRyaDAOTest.java @@ -19,40 +19,44 @@ * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; - import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.accumulo.core.iterators.FirstEntryInRowIterator; +import org.apache.accumulo.core.security.Authorizations; import org.apache.rya.accumulo.query.AccumuloRyaQueryEngine; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.RyaDAOException; -import org.apache.rya.api.persist.query.RyaQuery; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaContext; -import org.calrissian.mango.collect.FluentCloseableIterable; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** * Class AccumuloRdfDAOTest * Date: Mar 7, 2012 @@ -60,19 +64,40 @@ */ public class AccumuloRyaDAOTest { - private AccumuloRyaDAO dao; + private static final String AUTHS = "U"; private static final ValueFactory VF = SimpleValueFactory.getInstance(); - static String litdupsNS = "urn:test:litdups#"; + private static final String litdupsNS = "urn:test:litdups#"; + private static final long TIMESTAMP = 1587709670229L; + + private AccumuloRyaDAO dao; private AccumuloRdfConfiguration conf; private Connector connector; + RyaIRI cpu = new RyaIRI(litdupsNS + "cpu"); + RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc"); + RyaIRI disk = new RyaIRI(litdupsNS + "disk"); + RyaIRI diskPerc = new RyaIRI(litdupsNS + "diskPerc"); + RyaIRI net = new RyaIRI(litdupsNS + "net"); + RyaIRI netPerc = new RyaIRI(litdupsNS + "netPerc"); + RyaIRI uri1 = new RyaIRI(litdupsNS + "uri1"); + RyaIRI uri2 = new RyaIRI(litdupsNS + "uri2"); + RyaIRI uri3 = new RyaIRI(litdupsNS + "uri3"); + RyaIRI uri4 = new RyaIRI(litdupsNS + "uri4"); + RyaIRI uri5 = new RyaIRI(litdupsNS + "uri5"); + RyaIRI uri6 = new RyaIRI(litdupsNS + "uri6"); + String qualifier = null; + StatementMetadata metadata = null; + @Before public void setUp() throws Exception { dao = new AccumuloRyaDAO(); - connector = new MockInstance().getConnector("", ""); + connector = new MockInstance().getConnector("root", new PasswordToken("")); + connector.securityOperations().changeUserAuthorizations(connector.whoami(), new Authorizations(AUTHS)); dao.setConnector(connector); conf = new AccumuloRdfConfiguration(); dao.setConf(conf); + conf.setAuths(AUTHS); + conf.setFlush(true); dao.init(); } @@ -89,10 +114,10 @@ public void testAdd() throws Exception { RyaIRI uri1 = RdfToRyaConversions.convertIRI(VF.createIRI(litdupsNS, "uri1")); dao.add(new RyaStatement(cpu, loadPerc, uri1)); - CloseableIteration iter = dao.getQueryEngine().query(new RyaStatement(cpu, loadPerc, null), conf); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), new RyaStatement(cpu, loadPerc, null), conf); int count = 0; while (iter.hasNext()) { - assertTrue(uri1.equals(iter.next().getObject())); + assertEquals(uri1, iter.next().getObject()); count++; } iter.close(); @@ -100,7 +125,7 @@ public void testAdd() throws Exception { dao.delete(new RyaStatement(cpu, loadPerc, null), conf); - iter = dao.getQueryEngine().query(new RyaStatement(cpu, loadPerc, null), conf); + iter = RyaDAOHelper.query(dao.getQueryEngine(), new RyaStatement(cpu, loadPerc, null), conf); count = 0; while (iter.hasNext()) { count++; @@ -121,9 +146,9 @@ public void testDeleteDiffVisibility() throws Exception { dao.add(stmt2); AccumuloRdfConfiguration cloneConf = conf.clone(); - cloneConf.setAuth("vis1,vis2"); + cloneConf.setAuths("vis1", "vis2"); - CloseableIteration iter = dao.getQueryEngine().query(new RyaStatement(cpu, loadPerc, null), cloneConf); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), new RyaStatement(cpu, loadPerc, null), cloneConf); int count = 0; while (iter.hasNext()) { iter.next(); @@ -134,14 +159,14 @@ public void testDeleteDiffVisibility() throws Exception { dao.delete(stmt1, cloneConf); - iter = dao.getQueryEngine().query(new RyaStatement(cpu, loadPerc, null), cloneConf); + iter = RyaDAOHelper.query(dao.getQueryEngine(), new RyaStatement(cpu, loadPerc, null), cloneConf); count = 0; while (iter.hasNext()) { iter.next(); count++; } iter.close(); - assertEquals(1, count); + assertEquals(0, count); } @Test @@ -149,23 +174,40 @@ public void testDeleteDiffTimestamp() throws Exception { RyaIRI cpu = RdfToRyaConversions.convertIRI(VF.createIRI(litdupsNS, "cpu")); RyaIRI loadPerc = RdfToRyaConversions.convertIRI(VF.createIRI(litdupsNS, "loadPerc")); RyaIRI uri1 = RdfToRyaConversions.convertIRI(VF.createIRI(litdupsNS, "uri1")); - RyaStatement stmt1 = new RyaStatement(cpu, loadPerc, uri1, null, "1", null, null, 100l); + RyaStatement stmt1 = new RyaStatement(cpu, loadPerc, uri1, null, "1", + (StatementMetadata) null, null, 100l); dao.add(stmt1); - RyaStatement stmt2 = new RyaStatement(cpu, loadPerc, uri1, null, "2", null, null, 100l); + RyaStatement stmt2 = new RyaStatement(cpu, loadPerc, uri1, null, "2", + (StatementMetadata) null, null, 100l); dao.add(stmt2); - int resultSize = FluentCloseableIterable.from(dao.getQueryEngine().query( - RyaQuery.builder(new RyaStatement(cpu, loadPerc, null)).build())).autoClose().size(); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), + new RyaStatement(cpu, loadPerc, null), + dao.getQueryEngine().getConf()); + int resultSize = 0; + while (iter.hasNext()) { + resultSize++; + iter.next(); + } + iter.close(); assertEquals(2, resultSize); final RyaStatement addStmt = new RyaStatement(cpu, loadPerc, uri1, null, "1", - null, null, 101l); + (StatementMetadata) null, null, 101l); dao.delete(stmt1, conf); dao.add(addStmt); + dao.flush(); - resultSize = FluentCloseableIterable.from(dao.getQueryEngine().query( - RyaQuery.builder(new RyaStatement(cpu, loadPerc, null)).build())).autoClose().size(); - assertEquals(2, resultSize); //the delete marker should not delete the new stmt + iter = RyaDAOHelper.query(dao.getQueryEngine(), + new RyaStatement(cpu, loadPerc, null), + dao.getQueryEngine().getConf()); + resultSize = 0; + while (iter.hasNext()) { + resultSize++; + iter.next(); + } + iter.close(); + assertEquals(1, resultSize); //the delete marker should not delete the new stmt } @Test @@ -176,7 +218,7 @@ public void testDelete() throws Exception { // create a "bulk load" of 10,000 statements int statement_count = 10000; for (int i = 0 ; i < statement_count ; i++){ - //make the statement very large so we will get a lot of random flushes + //make the RyaStatement very large so we will get a lot of random flushes RyaIRI obj = RdfToRyaConversions.convertIRI(VF.createIRI(litdupsNS, String.format("object%050d",i))); RyaStatement stmt = new RyaStatement(subj, predicate, obj); dao.add(stmt); @@ -184,11 +226,11 @@ public void testDelete() throws Exception { CloseableIteration iter; - //check to see if all of the statements made it to the subj table - //delete based on the data in the subj table + // check to see if all of the statements made it to the subj table + // delete based on the data in the subj table RyaStatement subjQuery = new RyaStatement(subj, null, null); - iter = dao.getQueryEngine().query(subjQuery, conf); - List stmts = new ArrayList(); + iter = RyaDAOHelper.query(dao.getQueryEngine(), subjQuery, conf); + List stmts = new ArrayList<>(); while (iter.hasNext()) { stmts.add(iter.next()); } @@ -197,7 +239,7 @@ public void testDelete() throws Exception { // check statements in the predicate table RyaStatement predQuery = new RyaStatement(null, predicate, null); - iter = dao.getQueryEngine().query(predQuery, conf); + iter = RyaDAOHelper.query(dao.getQueryEngine(), predQuery, conf); int count = 0; while (iter.hasNext()) { count++; @@ -213,7 +255,7 @@ public void testAddEmptyString() throws Exception { RyaType empty = new RyaType(""); dao.add(new RyaStatement(cpu, loadPerc, empty)); - CloseableIteration iter = dao.getQueryEngine().query(new RyaStatement(cpu, loadPerc, null), conf); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), new RyaStatement(cpu, loadPerc, null), conf); while (iter.hasNext()) { assertEquals("", iter.next().getObject().getData()); } @@ -235,7 +277,7 @@ public void testMaxResults() throws Exception { long limit = 3l; queryConf.setLimit(limit); - CloseableIteration iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf); + CloseableIteration iter = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, null), queryConf); int count = 0; while (iter.hasNext()) { iter.next().getObject(); @@ -250,14 +292,14 @@ public void testAddValue() throws Exception { RyaIRI cpu = new RyaIRI(litdupsNS + "cpu"); RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc"); RyaIRI uri1 = new RyaIRI(litdupsNS + "uri1"); - String myval = "myval"; - byte[] columnVis = null; - dao.add(new RyaStatement(cpu, loadPerc, uri1, null, null, columnVis, myval.getBytes())); + StatementMetadata myval = new StatementMetadata(); + myval.addMetadata(new RyaIRI("urn:example:name"), new RyaType("literal")); + dao.add(new RyaStatement(cpu, loadPerc, uri1, null, null, myval)); AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); - CloseableIteration iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), conf); + CloseableIteration iter = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, null), conf); assertTrue(iter.hasNext()); - assertEquals(myval, new String(iter.next().getValue())); + assertEquals(myval.toString(), iter.next().getMetadata().toString()); iter.close(); } @@ -278,7 +320,7 @@ public void testAddCv() throws Exception { AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); //query with no auth - CloseableIteration iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), conf); + CloseableIteration iter = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, null), conf); int count = 0; while (iter.hasNext()) { count++; @@ -289,7 +331,7 @@ public void testAddCv() throws Exception { AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(); queryConf.setAuth("B"); - iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf); + iter = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, null), queryConf); count = 0; while (iter.hasNext()) { iter.next(); @@ -299,7 +341,7 @@ public void testAddCv() throws Exception { assertEquals(2, count); queryConf.setAuth("A"); - iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf); + iter = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, null), queryConf); count = 0; while (iter.hasNext()) { iter.next(); @@ -314,17 +356,17 @@ public void testTTL() throws Exception { RyaIRI cpu = new RyaIRI(litdupsNS + "cpu"); RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc"); long current = System.currentTimeMillis(); - dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri1"), null, null, null, null, current)); - dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri2"), null, null, null, null, current - 1010l)); - dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri3"), null, null, null, null, current - 2010l)); - dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri4"), null, null, null, null, current - 3010l)); - dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri5"), null, null, null, null, current - 4010l)); + dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri1"), null, null, (StatementMetadata) null, null, current)); + dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri2"), null, null, (StatementMetadata) null, null, current - 1010l)); + dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri3"), null, null, (StatementMetadata) null, null, current - 2010l)); + dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri4"), null, null, (StatementMetadata) null, null, current - 3010l)); + dao.add(new RyaStatement(cpu, loadPerc, new RyaIRI(litdupsNS + "uri5"), null, null, (StatementMetadata) null, null, current - 4010l)); AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); AccumuloRdfConfiguration queryConf = conf.clone(); queryConf.setTtl(3000l); - CloseableIteration iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf); + CloseableIteration iter = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, null), queryConf); int count = 0; while (iter.hasNext()) { iter.next().getObject(); @@ -334,14 +376,14 @@ public void testTTL() throws Exception { assertEquals(3, count); queryConf.setStartTime(current - 3000l); - iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf); + iter = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, null), queryConf); count = 0; while (iter.hasNext()) { iter.next().getObject(); count++; } iter.close(); - assertEquals(2, count); + assertEquals(3, count); } @Test @@ -352,126 +394,372 @@ public void testGetNamespace() throws Exception { assertNull(dao.getNamespace("ns")); } - //TOOD: Add test for set of queries @Test - public void testQuery() throws Exception { - RyaIRI cpu = new RyaIRI(litdupsNS + "cpu"); - RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc"); - RyaIRI uri1 = new RyaIRI(litdupsNS + "uri1"); - RyaIRI uri2 = new RyaIRI(litdupsNS + "uri2"); - RyaIRI uri3 = new RyaIRI(litdupsNS + "uri3"); - RyaIRI uri4 = new RyaIRI(litdupsNS + "uri4"); - RyaIRI uri5 = new RyaIRI(litdupsNS + "uri5"); - RyaIRI uri6 = new RyaIRI(litdupsNS + "uri6"); - dao.add(new RyaStatement(cpu, loadPerc, uri1)); - dao.add(new RyaStatement(cpu, loadPerc, uri2)); - dao.add(new RyaStatement(cpu, loadPerc, uri3)); - dao.add(new RyaStatement(cpu, loadPerc, uri4)); - dao.add(new RyaStatement(cpu, loadPerc, uri5)); - dao.add(new RyaStatement(cpu, loadPerc, uri6)); + public void testQueryWithoutContext() throws Exception { + testQuery(null); + } - AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); + @Test + public void testQueryWithContext() throws Exception { + RyaIRI metrics = new RyaIRI(litdupsNS + "metrics"); + testQuery(metrics); + } - Collection coll = new ArrayList<>(); - coll.add(new RyaStatement(null, loadPerc, uri1)); - coll.add(new RyaStatement(null, loadPerc, uri2)); - CloseableIteration iter = queryEngine.batchQuery(coll, conf); - int count = 0; - while (iter.hasNext()) { - count++; - iter.next(); - } - iter.close(); - assertEquals(2, count); + public void setUpData(RyaIRI context) { + dao.add(new RyaStatement(cpu, loadPerc, uri1, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(cpu, loadPerc, uri2, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(cpu, loadPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(cpu, loadPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(cpu, loadPerc, uri5, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(cpu, loadPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + + dao.add(new RyaStatement(disk, diskPerc, uri1, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(disk, diskPerc, uri2, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(disk, diskPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(disk, diskPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(disk, diskPerc, uri5, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(disk, diskPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + + dao.add(new RyaStatement(net, netPerc, uri1, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(net, netPerc, uri2, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(net, netPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(net, netPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(net, netPerc, uri5, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + dao.add(new RyaStatement(net, netPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + } + + public void testQuery(RyaIRI context) { + setUpData(context); - //now use batchscanner + // Use Scanner AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf); - queryConf.setMaxRangesForScanner(2); + queryConf.setNumThreads(1); - coll = new ArrayList<>(); - coll.add(new RyaStatement(null, loadPerc, uri1)); - coll.add(new RyaStatement(null, loadPerc, uri2)); - coll.add(new RyaStatement(null, loadPerc, uri3)); - coll.add(new RyaStatement(null, loadPerc, uri4)); - iter = queryEngine.batchQuery(coll, queryConf); + Collection coll = new ArrayList<>(); + coll.add(new RyaStatement(null, loadPerc, uri1, context)); + coll.add(new RyaStatement(null, loadPerc, uri2, context)); + coll.add(new RyaStatement(null, loadPerc, uri3, context)); + coll.add(new RyaStatement(null, loadPerc, uri4, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, conf); + int count = 0; assertTrue(iter.hasNext()); //old code had a weird behaviour that could not perform hasNext consecutively assertTrue(iter.hasNext()); assertTrue(iter.hasNext()); - count = 0; while (iter.hasNext()) { count++; - assertTrue(iter.hasNext()); iter.next(); } iter.close(); assertEquals(4, count); } + @Test + public void testQuerySPOC() { + RyaIRI context = new RyaIRI(litdupsNS + "metrics"); + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(disk, diskPerc, uri4, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + List actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + List expected = new ArrayList<>(); + expected.add(new RyaStatement(disk, diskPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + + @Test + public void testQuerySPC() { + RyaIRI context = new RyaIRI(litdupsNS + "metrics"); + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(disk, diskPerc, null, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + List actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + List expected = new ArrayList<>(); + expected.add(new RyaStatement(disk, diskPerc, uri1, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri2, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri5, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + + @Test + public void testQuerySOC() { + RyaIRI context = new RyaIRI(litdupsNS + "metrics"); + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(disk, null, uri4, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + List actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + List expected = new ArrayList<>(); + expected.add(new RyaStatement(disk, diskPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + + @Test + public void testQueryOPC() { + RyaIRI context = new RyaIRI(litdupsNS + "metrics"); + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(null, diskPerc, uri4, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + List actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + List expected = new ArrayList<>(); + expected.add(new RyaStatement(disk, diskPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + + @Test + public void testQuerySC() { + RyaIRI context = new RyaIRI(litdupsNS + "metrics"); + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(disk, null, null, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + List actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + List expected = new ArrayList<>(); + expected.add(new RyaStatement(disk, diskPerc, uri1, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri2, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri5, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + + @Test + public void testQueryPC() { + RyaIRI context = new RyaIRI(litdupsNS + "metrics"); + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(null, diskPerc, null, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + List actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + List expected = new ArrayList<>(); + expected.add(new RyaStatement(disk, diskPerc, uri1, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri2, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri5, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + + @Test + public void testQueryOC() { + RyaIRI context = new RyaIRI(litdupsNS + "metrics"); + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(null, null, uri3, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + List actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + List expected = new ArrayList<>(); + expected.add(new RyaStatement(cpu, loadPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(net, netPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + + @Test + public void testQuerySPO() { + RyaIRI context = null; + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(disk, diskPerc, uri3, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + List actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + List expected = new ArrayList<>(); + expected.add(new RyaStatement(disk, diskPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + + @Test + @Ignore("This doesn't work yet. Not sure yet if it needs to. It tests for multiple table layout support.") + public void testQueryMultipleLayouts() { + RyaIRI context = new RyaIRI(litdupsNS + "metrics"); + setUpData(context); + + Collection query = new ArrayList<>(); + query.add(new RyaStatement(cpu, loadPerc, null, context)); + query.add(new RyaStatement(null, diskPerc, null, context)); + query.add(new RyaStatement(null, null, uri3, context)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), query, conf); + Set actual = new HashSet<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + Set expected = new HashSet<>(); + expected.add(new RyaStatement(cpu, loadPerc, uri1, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(cpu, loadPerc, uri2, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(cpu, loadPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(cpu, loadPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(cpu, loadPerc, uri5, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(cpu, loadPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri1, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri2, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri4, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri5, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(disk, diskPerc, uri6, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + expected.add(new RyaStatement(net, netPerc, uri3, context, qualifier, metadata, AUTHS.getBytes(), TIMESTAMP)); + assertEquals(expected, actual); + } + @Test public void testQueryDates() throws Exception { - RyaIRI cpu = new RyaIRI(litdupsNS + "cpu"); - RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc"); - RyaType uri0 = new RyaType(XMLSchema.DATETIME, "1960-01-01"); // How handles local time - RyaType uri1 = new RyaType(XMLSchema.DATETIME, "1992-01-01T+10:00"); // See Magadan Time - RyaType uri2 = new RyaType(XMLSchema.DATETIME, "2000-01-01TZ"); // How it handles UTC. - RyaType uri3 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z"); - RyaType uri4 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z"); // duplicate - RyaType uri5 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01-00:00"); - RyaType uri6 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01Z"); // duplicate - RyaType uri7 = new RyaType(XMLSchema.DATETIME, "-2000-01-01T00:00:01Z"); - RyaType uri8 = new RyaType(XMLSchema.DATETIME, "111-01-01T00:00:01Z"); - RyaType uri9 = new RyaType(XMLSchema.DATETIME, "12345-01-01T00:00:01Z"); - - dao.add(new RyaStatement(cpu, loadPerc, uri0)); - dao.add(new RyaStatement(cpu, loadPerc, uri1)); - dao.add(new RyaStatement(cpu, loadPerc, uri2)); - dao.add(new RyaStatement(cpu, loadPerc, uri3)); - dao.add(new RyaStatement(cpu, loadPerc, uri4)); - dao.add(new RyaStatement(cpu, loadPerc, uri5)); - dao.add(new RyaStatement(cpu, loadPerc, uri6)); - dao.add(new RyaStatement(cpu, loadPerc, uri7)); - dao.add(new RyaStatement(cpu, loadPerc, uri8)); - dao.add(new RyaStatement(cpu, loadPerc, uri9)); - - AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); - - Collection coll = new ArrayList<>(); - coll.add(new RyaStatement(null, loadPerc, uri0)); - coll.add(new RyaStatement(null, loadPerc, uri1)); - coll.add(new RyaStatement(null, loadPerc, uri2)); - CloseableIteration iter = queryEngine.batchQuery(coll, conf); - int count = 0; - while (iter.hasNext()) { - count++; - iter.next(); - } - iter.close(); - assertEquals("Three time zones should be normalized when stored, then normalized same when queried.",3, count); - - //now use batchscanner - AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf); - queryConf.setMaxRangesForScanner(2); - - coll = new ArrayList<>(); - coll.add(new RyaStatement(null, loadPerc, uri0)); - coll.add(new RyaStatement(null, loadPerc, uri1)); - coll.add(new RyaStatement(null, loadPerc, uri2)); - coll.add(new RyaStatement(null, loadPerc, uri3)); - coll.add(new RyaStatement(null, loadPerc, uri4)); - coll.add(new RyaStatement(null, loadPerc, uri5)); - coll.add(new RyaStatement(null, loadPerc, uri6)); - coll.add(new RyaStatement(null, loadPerc, uri7)); - coll.add(new RyaStatement(null, loadPerc, uri8)); - coll.add(new RyaStatement(null, loadPerc, uri9)); - iter = queryEngine.batchQuery(coll, queryConf); - count = 0; - while (iter.hasNext()) { - count++; - iter.next(); - } - iter.close(); - assertEquals("Variety of time specs, including BC, pre-1970, duplicate pair ovewrite,future, 3 digit year.",8, count); - } + RyaIRI cpu = new RyaIRI(litdupsNS + "cpu"); + RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc"); + RyaType uri0 = new RyaType(XMLSchema.DATETIME, "1960-01-01"); // How handles local time + RyaType uri1 = new RyaType(XMLSchema.DATETIME, "1992-01-01T+10:00"); // See Magadan Time + RyaType uri2 = new RyaType(XMLSchema.DATETIME, "2000-01-01TZ"); // How it handles UTC. + RyaType uri3 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z"); + RyaType uri4 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z"); // duplicate + RyaType uri5 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01-00:00"); + RyaType uri6 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01Z"); // duplicate + RyaType uri7 = new RyaType(XMLSchema.DATETIME, "-2000-01-01T00:00:01Z"); + RyaType uri8 = new RyaType(XMLSchema.DATETIME, "111-01-01T00:00:01Z"); + RyaType uri9 = new RyaType(XMLSchema.DATETIME, "12345-01-01T00:00:01Z"); + long timestamp = 1592457339326L; + + dao.add(new RyaStatement(cpu, loadPerc, uri0, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri1, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri2, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri3, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri4, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri5, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri6, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri7, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri8, timestamp)); + dao.add(new RyaStatement(cpu, loadPerc, uri9, timestamp)); + + { + Collection coll = new ArrayList<>(); + coll.add(new RyaStatement(null, loadPerc, null)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, conf); + + int count = 0; + while (iter.hasNext()) { + count++; + iter.next(); + } + iter.close(); + assertEquals( + "There should be 8 unique items in the table.", // 2 duplicates + 8, count); + } + + { + Collection coll = new ArrayList<>(); + coll.add(new RyaStatement(null, loadPerc, uri0)); + coll.add(new RyaStatement(null, loadPerc, uri1)); + coll.add(new RyaStatement(null, loadPerc, uri2)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, conf); + + Collection expected = new ArrayList<>(); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:00.000Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "1991-12-31T14:00:00.000Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "1959-12-31T14:00:00.000Z"), timestamp)); + + Collection actual = new ArrayList<>(); + while (iter.hasNext()) { + actual.add(iter.next()); + } + iter.close(); + assertEquals( + "Three time zones should be normalized when stored, then normalized same when queried.", + expected.size(), actual.size()); + // They will return in a random order + for (RyaStatement e : expected) { + assertTrue(e.toString(), actual.contains(e)); + } + } + + { + Collection coll = new ArrayList<>(); + coll.add(new RyaStatement(null, loadPerc, uri0)); + coll.add(new RyaStatement(null, loadPerc, uri1)); + coll.add(new RyaStatement(null, loadPerc, uri2)); + coll.add(new RyaStatement(null, loadPerc, uri3)); + coll.add(new RyaStatement(null, loadPerc, uri4)); + coll.add(new RyaStatement(null, loadPerc, uri5)); + coll.add(new RyaStatement(null, loadPerc, uri6)); + coll.add(new RyaStatement(null, loadPerc, uri7)); + coll.add(new RyaStatement(null, loadPerc, uri8)); + coll.add(new RyaStatement(null, loadPerc, uri9)); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, conf); + + Collection expected = new ArrayList<>(); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "0111-01-01T00:00:01.000Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "1959-12-31T14:00:00.000Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "1991-12-31T14:00:00.000Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:00.000Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.000Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.000Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z"), timestamp)); + expected.add(new RyaStatement(cpu, loadPerc, new RyaType(XMLSchema.DATETIME, "12345-01-01T00:00:01.000Z"), timestamp)); + // TODO: Is it correct to return "2000-01-01T00:00:01.000Z" multiple times? + + Collection actual = new ArrayList<>(); + while (iter.hasNext()) { + RyaStatement s = iter.next(); + actual.add(s); + System.out.println("Returned: " + s); + } + iter.close(); + assertEquals( + "Variety of time specs, including BC, pre-1970, duplicate pair ovewrite,future, 3 digit year.", + expected.size(), actual.size()); + // They will return in a random order + for (RyaStatement e : expected) { + assertTrue(e.toString(), actual.contains(e)); + } + //assertEquals(new ArrayList<>(), actual); // For debugging + } + } @Test public void testQueryCollectionRegex() throws Exception { @@ -496,7 +784,7 @@ public void testQueryCollectionRegex() throws Exception { coll.add(new RyaStatement(null, loadPerc, uri1)); coll.add(new RyaStatement(null, loadPerc, uri2)); conf.setRegexPredicate(loadPerc.getData()); - CloseableIteration iter = queryEngine.batchQuery(coll, conf); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, conf); int count = 0; while (iter.hasNext()) { count++; @@ -506,7 +794,7 @@ public void testQueryCollectionRegex() throws Exception { assertEquals(2, count); conf.setRegexPredicate("notLoadPerc"); - iter = queryEngine.batchQuery(coll, conf); + iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, conf); count = 0; while (iter.hasNext()) { count++; @@ -535,13 +823,13 @@ public void testQueryCollectionRegexWBatchScanner() throws Exception { AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf); - queryConf.setMaxRangesForScanner(1); + queryConf.setNumThreads(1); Collection coll = new ArrayList<>(); coll.add(new RyaStatement(null, loadPerc, uri1)); coll.add(new RyaStatement(null, loadPerc, uri2)); conf.setRegexPredicate(loadPerc.getData()); - CloseableIteration iter = queryEngine.batchQuery(coll, queryConf); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, queryConf); int count = 0; while (iter.hasNext()) { count++; @@ -551,7 +839,7 @@ public void testQueryCollectionRegexWBatchScanner() throws Exception { assertEquals(2, count); queryConf.setRegexPredicate("notLoadPerc"); - iter = queryEngine.batchQuery(coll, queryConf); + iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, queryConf); count = 0; while (iter.hasNext()) { count++; @@ -571,7 +859,7 @@ public void testLiteralTypes() throws Exception { AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); - CloseableIteration query = queryEngine.query(new RyaStatement(cpu, null, null), conf); + CloseableIteration query = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, null, null), conf); assertTrue(query.hasNext()); RyaStatement next = query.next(); assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData())); @@ -581,7 +869,7 @@ public void testLiteralTypes() throws Exception { dao.add(new RyaStatement(cpu, loadPerc, doubleLit)); - query = queryEngine.query(new RyaStatement(cpu, loadPerc, doubleLit), conf); + query = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, doubleLit), conf); assertTrue(query.hasNext()); next = query.next(); assertEquals(Double.parseDouble(doubleLit.getData()), Double.parseDouble(next.getObject().getData()), 0.001); @@ -595,17 +883,30 @@ public void testSameLiteralStringTypes() throws Exception { RyaType longLit = new RyaType(XMLSchema.LONG, "10"); RyaType strLit = new RyaType(XMLSchema.STRING, new String(RyaContext.getInstance().serializeType(longLit)[0])); - RyaStatement expected = new RyaStatement(cpu, loadPerc, longLit); + RyaStatement expected = new RyaStatement(cpu, loadPerc, longLit, TIMESTAMP); dao.add(expected); - dao.add(new RyaStatement(cpu, loadPerc, strLit)); + dao.add(new RyaStatement(cpu, loadPerc, strLit, TIMESTAMP)); AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine(); - CloseableIteration query = queryEngine.query(new RyaStatement(cpu, loadPerc, longLit), conf); + CloseableIteration query = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, longLit), conf); + // Both Long and String representations match the search criteria. + assertTrue(query.hasNext()); RyaStatement next = query.next(); + assertEquals(strLit.getData(), next.getObject().getData()); + assertEquals(strLit.getDataType(), next.getObject().getDataType()); + + assertTrue(query.hasNext()); + next = query.next(); assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData())); assertEquals(longLit.getDataType(), next.getObject().getDataType()); + + assertFalse(query.hasNext()); + query.close(); + + RyaType longLitDifferent = new RyaType(XMLSchema.LONG, "11"); + query = RyaDAOHelper.query(queryEngine, new RyaStatement(cpu, loadPerc, longLitDifferent), conf); assertFalse(query.hasNext()); query.close(); } @@ -655,7 +956,7 @@ public void testQueryWithIterators() throws Exception { Collection coll = new ArrayList<>(); coll.add(new RyaStatement(null, loadPerc, uri1)); - CloseableIteration iter = queryEngine.batchQuery(coll, queryConf); + CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, queryConf); int count = 0; while (iter.hasNext()) { count++; @@ -667,7 +968,7 @@ public void testQueryWithIterators() throws Exception { //Assert that without the iterator we get 2 coll = new ArrayList<>(); coll.add(new RyaStatement(null, loadPerc, uri1)); - iter = queryEngine.batchQuery(coll, conf); + iter = RyaDAOHelper.query(dao.getQueryEngine(), coll, conf); count = 0; while (iter.hasNext()) { count++; diff --git a/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/instance/AccumuloRyaDetailsRepositoryIT.java b/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/instance/AccumuloRyaDetailsRepositoryIT.java index ff0df6b48..4d44842bd 100644 --- a/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/instance/AccumuloRyaDetailsRepositoryIT.java +++ b/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/instance/AccumuloRyaDetailsRepositoryIT.java @@ -18,12 +18,7 @@ */ package org.apache.rya.accumulo.instance; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Date; - +import com.google.common.base.Optional; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -47,10 +42,14 @@ import org.apache.rya.test.accumulo.MiniAccumuloClusterInstance; import org.junit.Test; -import com.google.common.base.Optional; +import java.util.Date; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** - * Tests the methods of {@link AccumuloRyaDetailsRepository} by using a {@link MiniAccumuloCluster}. + * Tests the methods of {@link AccumuloRyaInstanceDetailsRepository} by using a {@link MiniAccumuloCluster}. */ public class AccumuloRyaDetailsRepositoryIT extends AccumuloITBase { diff --git a/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/query/RangeBindingSetEntriesTest.java b/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/query/RangeBindingSetEntriesTest.java new file mode 100644 index 000000000..fb980176c --- /dev/null +++ b/dao/accumulo.rya/src/test/java/org/apache/rya/accumulo/query/RangeBindingSetEntriesTest.java @@ -0,0 +1,129 @@ +/* + * 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.rya.accumulo.query; + +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Range; +import org.apache.rya.api.domain.RyaType; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.query.BindingSet; +import org.eclipse.rdf4j.query.impl.ListBindingSet; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + *

Tests the methods of {@link RangeBindingSetEntries}.

+ * + *

This class is critical is two ways: + *

    + *
  1. it is critical to getting the correct answer for any SPARQL query, and
  2. + *
  3. it is critical to the performance of the query time.
  4. + *

+ * + *

This class tests for both the correct answer and for fast performance.

+ * + *

The Glowroot Java profiler found that for a complex SPARQL query that takes about 40 seconds to return, + * a huge 85% of the query time was spend in this class, doing the {@link RangeBindingSetEntries#containsKey(Key)} + * function. Therefore optimising the performance of this method is critical to overall Rya performance.

+ */ +public class RangeBindingSetEntriesTest { + + private final static String CONTEXT = "context"; + private final static String NAME = "name"; + private final static String VALUE = "value"; + + private BindingSet createBindingSet(char letter1, char letter2) { + List bindingNames = new ArrayList<>(); + for (int i = 100; i <= 120; i++) { + bindingNames.add(NAME + letter1 + letter2 + i); + } + List values = new ArrayList<>(); + for (int i = 100; i <= 120; i++) { + values.add(new RyaType(VALUE + letter1 + letter2 + i)); + } + BindingSet bs = new ListBindingSet(bindingNames, values); + return bs; + } + + @Test + public void testRow() { + final RangeBindingSetEntries entries = new RangeBindingSetEntries(); + // Generate enough test data to check for performance characteristics + for (char letter1 = 'A'; letter1 <= 'Z'; letter1++) { + for (char letter2 = 'A'; letter2 <= 'Z'; letter2++) { + // Create genuine ranges of "AA1-AA9" through "ZZ1-ZZ9". + Range range = new Range( + new Key("" + letter1 + letter2 + 1), + new Key("" + letter1 + letter2 + 9)); + BindingSet bs = createBindingSet(letter1, letter2); + entries.put(range, bs); + } + } + + char letter1 = 'S'; // Random letter between A and Z + char letter2 = 'F'; // Random letter between A and Z + short number = 5; // Random number between 1 and 9 + HashSet bsSet = new HashSet<>(); + // This will match one of the entries from the test data + BindingSet bs = createBindingSet(letter1, letter2); + bsSet.add(bs); + assertEquals(bsSet, entries.containsKey( + new Key("" + letter1 + letter2 + number))); + } + + @Test + public void testColumn() { + final RangeBindingSetEntries entries = new RangeBindingSetEntries(); + // Generate enough test data to check for performance characteristics + for (char letter1 = 'A'; letter1 <= 'Z'; letter1++) { + for (char letter2 = 'A'; letter2 <= 'Z'; letter2++) { + BindingSet bs = createBindingSet(letter1, letter2); + // Create genuine ranges of "AA1-AA9" through "ZZ1-ZZ9". + // Create an example with the correct column, and one with an incorrect column. + Range rangeRight = new Range( + new Key("" + letter1 + letter2 + 1, CONTEXT + letter1 + letter2 + "right"), + new Key("" + letter1 + letter2 + 9, CONTEXT + letter1 + letter2 + "right")); + Range rangeWrong = new Range( + new Key("" + letter1 + letter2 + 1, CONTEXT + letter1 + letter2 + "wrong"), + new Key("" + letter1 + letter2 + 9, CONTEXT + letter1 + letter2 + "wrong")); + entries.put(rangeRight, bs); + entries.put(rangeWrong, bs); + } + } + + char letter1 = 'T'; // Random letter between A and Z + char letter2 = 'H'; // Random letter between A and Z + short number = 6; // Random number between 1 and 9 + HashSet bsSet = new HashSet<>(); + // This will match one of the entries from the test data + BindingSet bs = createBindingSet(letter1, letter2); + bsSet.add(bs); + assertEquals(bsSet, entries.containsKey( + new Key("" + letter1 + letter2 + number, CONTEXT + letter1 + letter2 + "right"))); + } + +} \ No newline at end of file diff --git a/dao/accumulo.rya/src/test/resources/log4j.xml b/dao/accumulo.rya/src/test/resources/log4j.xml new file mode 100644 index 000000000..396f16ebe --- /dev/null +++ b/dao/accumulo.rya/src/test/resources/log4j.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java index 229a811d9..2e0a27785 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java @@ -18,19 +18,15 @@ */ package org.apache.rya.mongodb; -import static java.util.Objects.requireNonNull; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - +import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; import org.apache.accumulo.core.security.Authorizations; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.persist.RyaDAO; import org.apache.rya.api.persist.RyaDAOException; @@ -49,10 +45,13 @@ import org.apache.rya.mongodb.document.util.DocumentVisibilityUtil; import org.bson.Document; -import com.mongodb.DuplicateKeyException; -import com.mongodb.MongoClient; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import static java.util.Objects.requireNonNull; /** * Default DAO for mongo backed RYA allowing for CRUD operations. @@ -237,9 +236,9 @@ public void delete(final RyaStatement statement, final StatefulMongoDBRdfConfigu } @Override - public void dropGraph(final StatefulMongoDBRdfConfiguration conf, final RyaIRI... graphs) + public void dropGraph(final StatefulMongoDBRdfConfiguration conf, final RyaResource... graphs) throws RyaDAOException { - + throw new UnsupportedOperationException("You cannot drop graphs in MongoDB!"); } @Override diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java index e9e173f03..b78cf2b1c 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java @@ -18,33 +18,19 @@ */ package org.apache.rya.mongodb.aggregation; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.CONTEXT; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.DOCUMENT_VISIBILITY; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT_HASH; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT_TYPE; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.PREDICATE; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.PREDICATE_HASH; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.STATEMENT_METADATA; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.SUBJECT; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.SUBJECT_HASH; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.TIMESTAMP; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.NavigableSet; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentSkipListSet; -import java.util.function.Function; - +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.Aggregates; +import com.mongodb.client.model.BsonField; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Projections; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.mongodb.MongoDbRdfConstants; @@ -72,15 +58,29 @@ import org.eclipse.rdf4j.query.algebra.Var; import org.eclipse.rdf4j.query.algebra.evaluation.impl.ExternalSet; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.model.Aggregates; -import com.mongodb.client.model.BsonField; -import com.mongodb.client.model.Filters; -import com.mongodb.client.model.Projections; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.NavigableSet; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.function.Function; + +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.CONTEXT; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.DOCUMENT_VISIBILITY; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT_HASH; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT_TYPE; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.PREDICATE; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.PREDICATE_HASH; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.STATEMENT_METADATA; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.SUBJECT; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.SUBJECT_HASH; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.TIMESTAMP; /** * Represents a portion of a query tree as MongoDB aggregation pipeline. Should @@ -260,10 +260,10 @@ private static Document getMatchExpression(final StatementPattern sp, final Stri final Var predVar = sp.getPredicateVar(); final Var objVar = sp.getObjectVar(); final Var contextVar = sp.getContextVar(); - RyaIRI s = null; + RyaResource s = null; RyaIRI p = null; - RyaType o = null; - RyaIRI c = null; + RyaValue o = null; + RyaResource c = null; if (subjVar != null && subjVar.getValue() instanceof Resource) { s = RdfToRyaConversions.convertResource((Resource) subjVar.getValue()); } @@ -274,7 +274,7 @@ private static Document getMatchExpression(final StatementPattern sp, final Stri o = RdfToRyaConversions.convertValue(objVar.getValue()); } if (contextVar != null && contextVar.getValue() instanceof IRI) { - c = RdfToRyaConversions.convertIRI((IRI) contextVar.getValue()); + c = RdfToRyaConversions.convertResource((IRI) contextVar.getValue()); } final RyaStatement rs = new RyaStatement(s, p, o, c); final Document obj = strategy.getQuery(rs); diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java index d39673f3e..068e3be9e 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java @@ -18,18 +18,15 @@ */ package org.apache.rya.mongodb.dao; -import static org.eclipse.rdf4j.model.vocabulary.XMLSchema.ANYURI; - -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - +import com.mongodb.client.MongoCollection; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.log4j.Logger; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.query.RyaQuery; import org.apache.rya.api.utils.LiteralLanguageUtils; @@ -40,7 +37,11 @@ import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; -import com.mongodb.client.MongoCollection; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import static org.eclipse.rdf4j.model.vocabulary.XMLSchema.ANYURI; /** * Defines how {@link RyaStatement}s are stored in MongoDB. @@ -97,10 +98,10 @@ public void createIndices(final MongoCollection coll){ @Override public Document getQuery(final RyaStatement stmt) { - final RyaIRI subject = stmt.getSubject(); + final RyaResource subject = stmt.getSubject(); final RyaIRI predicate = stmt.getPredicate(); - final RyaType object = stmt.getObject(); - final RyaIRI context = stmt.getContext(); + final RyaValue object = stmt.getObject(); + final RyaResource context = stmt.getContext(); final Document query = new Document(); if (subject != null){ query.append(SUBJECT_HASH, hash(subject.getData())); @@ -157,14 +158,13 @@ public RyaStatement deserializeDocument(final Document queryResult) { if(timestamp != null) { statement.setTimestamp(timestamp); } - if(statementMetadata != null) { - try { - final StatementMetadata metadata = new StatementMetadata(statementMetadata); - statement.setStatementMetadata(metadata); - } - catch (final Exception ex){ - LOG.debug("Error deserializing metadata for statement", ex); - } + try { + final StatementMetadata metadata = new StatementMetadata(statementMetadata); + statement.setStatementMetadata(metadata); + } + catch (final Exception ex){ + LOG.error("Error deserializing metadata for statement!", ex); + statement.setStatementMetadata(null); } return statement; } diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/iter/RyaStatementBindingSetCursorIterator.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/iter/RyaStatementBindingSetCursorIterator.java index 82d1a4ed2..c4583dbf2 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/iter/RyaStatementBindingSetCursorIterator.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/iter/RyaStatementBindingSetCursorIterator.java @@ -18,33 +18,32 @@ */ package org.apache.rya.mongodb.iter; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Iterators; +import com.google.common.collect.Multimap; +import com.mongodb.client.AggregateIterable; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.Aggregates; +import com.mongodb.client.model.Filters; import org.apache.accumulo.core.security.Authorizations; import org.apache.log4j.Logger; import org.apache.rya.api.RdfCloudTripleStoreUtils; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.mongodb.dao.MongoDBStorageStrategy; import org.apache.rya.mongodb.document.operators.aggregation.AggregationUtil; import org.bson.Document; import org.bson.conversions.Bson; import org.eclipse.rdf4j.common.iteration.CloseableIteration; +import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.query.BindingSet; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterators; -import com.google.common.collect.Multimap; -import com.mongodb.client.AggregateIterable; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.model.Aggregates; -import com.mongodb.client.model.Filters; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; public class RyaStatementBindingSetCursorIterator implements CloseableIteration, RyaDAOException> { private static final Logger log = Logger.getLogger(RyaStatementBindingSetCursorIterator.class); @@ -129,7 +128,7 @@ private static boolean isResultForQuery(final RyaStatement query, final RyaState isResult(query.getContext(), result.getContext()); } - private static boolean isResult(final RyaType query, final RyaType result) { + private static boolean isResult(final Value query, final Value result) { return (query == null) || query.equals(result); } diff --git a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineIT.java b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineIT.java index f2dd11db7..c9f846101 100644 --- a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineIT.java +++ b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineIT.java @@ -18,16 +18,12 @@ */ package org.apache.rya.mongodb; -import static org.junit.Assert.assertEquals; - -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; - +import com.google.common.collect.Lists; import org.apache.rya.api.RdfCloudTripleStoreUtils; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; @@ -35,7 +31,11 @@ import org.eclipse.rdf4j.query.impl.MapBindingSet; import org.junit.Test; -import com.google.common.collect.Lists; +import java.util.Collection; +import java.util.Map; +import java.util.Map.Entry; + +import static org.junit.Assert.assertEquals; /** * Integration tests the methods of {@link MongoDBQueryEngine}. @@ -79,7 +79,7 @@ public void statementQuery() throws Exception { dao.add(getStatement("u:a", "u:tt", "u:c")); final RyaStatement s = getStatement("u:a", null, null); - assertEquals(2, size(engine.query(s, conf))); + assertEquals(2, size(RyaDAOHelper.query(dao.getQueryEngine(), s, conf))); } finally { dao.destroy(); } diff --git a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java index e9259d75e..e694e4d4d 100644 --- a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java +++ b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java @@ -18,29 +18,28 @@ */ package org.apache.rya.mongodb; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.DOCUMENT_VISIBILITY; -import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.TIMESTAMP; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - +import com.mongodb.MongoException; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; import org.apache.accumulo.core.security.Authorizations; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder; import org.apache.rya.api.persist.RyaDAOException; -import org.apache.rya.api.persist.query.RyaQuery; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.mongodb.document.util.AuthorizationsUtil; import org.apache.rya.mongodb.document.visibility.DocumentVisibility; import org.bson.Document; -import org.calrissian.mango.collect.CloseableIterable; +import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.junit.Test; -import com.mongodb.MongoException; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; +import java.io.IOException; + +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.DOCUMENT_VISIBILITY; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.TIMESTAMP; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class MongoDBRyaDAOIT extends MongoRyaITBase { @@ -606,10 +605,10 @@ private boolean testVisibilityStatement( final MongoDBQueryEngine queryEngine = (MongoDBQueryEngine) dao.getQueryEngine(); queryEngine.setConf(conf); - final CloseableIterable iter = queryEngine.query(new RyaQuery(statement)); + final CloseableIteration iter = RyaDAOHelper.query(queryEngine, statement, conf); // Check if user has authorization to view document based on its visibility - final boolean hasNext = iter.iterator().hasNext(); + final boolean hasNext = iter.hasNext(); // Reset dao.delete(statement, conf); diff --git a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java index 06d7bece3..4b8b240c0 100644 --- a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java +++ b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java @@ -18,11 +18,7 @@ * under the License. */ -import static org.eclipse.rdf4j.model.vocabulary.XMLSchema.ANYURI; -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - +import com.mongodb.MongoException; import org.apache.commons.codec.digest.DigestUtils; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; @@ -37,7 +33,10 @@ import org.eclipse.rdf4j.model.vocabulary.RDF; import org.junit.Test; -import com.mongodb.MongoException; +import java.io.IOException; + +import static org.eclipse.rdf4j.model.vocabulary.XMLSchema.ANYURI; +import static org.junit.Assert.assertEquals; public class SimpleMongoDBStorageStrategyTest { private static final String SUBJECT = "http://subject.com"; @@ -61,6 +60,7 @@ public class SimpleMongoDBStorageStrategyTest { builder.setContext(new RyaIRI(CONTEXT)); builder.setColumnVisibility(DOCUMENT_VISIBILITY.flatten()); builder.setTimestamp(null); + builder.setMetadata(null); testStatement = builder.build(); TEST_DOC = new Document(); @@ -90,6 +90,7 @@ public class SimpleMongoDBStorageStrategyTest { builder.setContext(new RyaIRI(CONTEXT)); builder.setColumnVisibility(DOCUMENT_VISIBILITY.flatten()); builder.setTimestamp(null); + builder.setMetadata(null); testStatement2 = builder.build(); // Check language support diff --git a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/instance/MongoRyaDetailsRepositoryIT.java b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/instance/MongoRyaDetailsRepositoryIT.java index 73133b7ef..e535735a6 100644 --- a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/instance/MongoRyaDetailsRepositoryIT.java +++ b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/instance/MongoRyaDetailsRepositoryIT.java @@ -19,12 +19,8 @@ * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Date; - +import com.google.common.base.Optional; +import com.mongodb.MongoClient; import org.apache.rya.api.instance.RyaDetails; import org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails; import org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails; @@ -44,11 +40,14 @@ import org.junit.Before; import org.junit.Test; -import com.google.common.base.Optional; -import com.mongodb.MongoClient; +import java.util.Date; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** - * Tests the methods of {@link MongoRyaDetailsRepository} by using a mock {@link MongoClient}. + * Tests the methods of {@link MongoRyaInstanceDetailsRepository} by using a mock {@link MongoClient}. */ public class MongoRyaDetailsRepositoryIT extends MongoITBase { private MongoClient client; diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/accumulo/AccumuloCreatePCJ.java b/extras/indexing/src/main/java/org/apache/rya/api/client/accumulo/AccumuloCreatePCJ.java index 243aea617..7daaea1c4 100644 --- a/extras/indexing/src/main/java/org/apache/rya/api/client/accumulo/AccumuloCreatePCJ.java +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/accumulo/AccumuloCreatePCJ.java @@ -18,10 +18,10 @@ */ package org.apache.rya.api.client.accumulo; -import static java.util.Objects.requireNonNull; - -import java.util.Set; - +import com.google.common.base.Optional; +import com.google.common.collect.Sets; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.accumulo.core.client.Connector; import org.apache.fluo.api.client.FluoClient; import org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository; @@ -51,11 +51,9 @@ import org.eclipse.rdf4j.repository.RepositoryException; import org.eclipse.rdf4j.sail.SailException; -import com.google.common.base.Optional; -import com.google.common.collect.Sets; +import java.util.Set; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * An Accumulo implementation of the {@link CreatePCJ} command. @@ -104,7 +102,7 @@ public String createPCJ(final String instanceName, final String sparql, Set { */ public TemporalInterval(TemporalInstant hasBeginning, TemporalInstant hasEnd) { super(); - if (hasBeginning != null && hasEnd != null && 0 < hasBeginning.compareTo(hasEnd)) - throw new IllegalArgumentException("The Beginning instance must not compare greater than the end."); + if (hasBeginning != null && hasEnd != null && 0 < hasBeginning.compareTo(hasEnd)) { + throw new IllegalArgumentException("The Beginning instance must not compare greater than the end. hasBeginning="+hasBeginning+" hasEnd="+hasEnd); + } this.hasBeginning = hasBeginning; this.hasEnd = hasEnd; } diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/AccumuloIndexingConfiguration.java b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/AccumuloIndexingConfiguration.java index 4b703ebb7..a818d38ca 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/AccumuloIndexingConfiguration.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/AccumuloIndexingConfiguration.java @@ -18,10 +18,8 @@ */ package org.apache.rya.indexing.accumulo; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; - +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.rya.accumulo.AbstractAccumuloRdfConfigurationBuilder; @@ -35,8 +33,9 @@ import org.apache.rya.indexing.statement.metadata.matching.StatementMetadataOptimizer; import org.eclipse.rdf4j.sail.Sail; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; /** * This class is an extension of the AccumuloRdfConfiguration object used to to @@ -117,7 +116,7 @@ public static AccumuloIndexingConfiguration fromProperties(final Properties prop /** * - * Specify whether to use use {@link EntitCentricIndex} for ingest and at + * Specify whether to use use {@link EntityCentricIndex} for ingest and at * query time. The default value is false, and if useEntity is set to true * and the EntityIndex does not exist, then useEntity will default to false. * @@ -137,7 +136,7 @@ public boolean getUseEntity() { /** * - * Specify whether to use use {@link AccumuloTemproalIndexer} for ingest and + * Specify whether to use use {@link AccumuloTemporalIndexer} for ingest and * at query time. The default value is false, and if useTemporal is set to * true and the TemporalIndex does not exist, then useTemporal will default * to false. @@ -170,7 +169,7 @@ public boolean getUseFreetext() { * true and the FreeTextIndex does not exist, then useFreeText will default * to false. * - * @param useFreeText + * @param useFreetext * - use freetext indexing */ public void setUseFreetext(final boolean useFreetext) { @@ -220,7 +219,7 @@ public String getFluoAppUpdaterName() { /** * Use Precomputed Joins as a query optimization. * - * @param usePcj + * @param usePCJ * - use PCJ */ public void setUsePCJ(final boolean usePCJ) { @@ -238,7 +237,7 @@ public boolean getUsePCJ() { * Use Precomputed Joins as a query optimization and attempt to find the * best combination of PCJ in the query plan * - * @param useOptimalPcj + * @param useOptimalPCJ * - use optimal pcj plan */ public void setUseOptimalPCJ(final boolean useOptimalPCJ) { @@ -370,7 +369,7 @@ public static class AccumuloIndexingConfigBuilder extends * ingest. Default is false. *
  • "use.entity" - Use Accumulo Entity Index for querying and ingest. * Default is false. - *
  • "use.metadata" - Use Accumulo StatementMetadata index for querying Statement Properties. + *
  • "use.metadata" - Use Accumulo {@link org.apache.rya.api.domain.StatementMetadata} index for querying Statement Properties. * Default is false. *
  • "metadata.properties" - Set Statement Properties that can be queried using the StatementMetadataOptimizer. * Default is empty. @@ -475,7 +474,7 @@ public AccumuloIndexingConfigBuilder setUseAccumuloTemporalIndex(final boolean u /** * - * Specify whether to use use {@link EntitCentricIndex} for ingest and + * Specify whether to use use {@link EntityCentricIndex} for ingest and * at query time. The default value is false, and if useEntity is set to * true and the EntityIndex does not exist, then useEntity will default * to false. @@ -584,7 +583,7 @@ public AccumuloIndexingConfigBuilder setUseStatementMetadata(final boolean useMe /** * Specify properties that the {@link StatementMetadataOptimizer} will use to query - * @param useMetadata + * @param metadataProps * @return AccumuloIndexingConfigBuilder for chaining method invocations */ public AccumuloIndexingConfigBuilder setStatementMetadataProperties(final Set metadataProps) { diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java index cad6a6c91..ccc9bbbba 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java @@ -18,21 +18,9 @@ */ package org.apache.rya.indexing.accumulo.entity; -import static java.util.Objects.requireNonNull; -import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_CV; -import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_VALUE; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Set; - +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.primitives.Bytes; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriter; @@ -51,18 +39,31 @@ import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.experimental.AbstractAccumuloIndexer; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.indexing.accumulo.ConfigUtils; import org.eclipse.rdf4j.model.IRI; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.primitives.Bytes; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +import static java.util.Objects.requireNonNull; +import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_CV; +import static org.apache.rya.accumulo.AccumuloRdfConstants.EMPTY_VALUE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; public class EntityCentricIndex extends AbstractAccumuloIndexer { @@ -231,10 +232,10 @@ private static Mutation createMutation(final TripleRow tripleRow) { } private static List serializeStatement(final RyaStatement stmt) throws RyaTypeResolverException { - final RyaIRI subject = stmt.getSubject(); + final RyaResource subject = stmt.getSubject(); final RyaIRI predicate = stmt.getPredicate(); - final RyaType object = stmt.getObject(); - final RyaIRI context = stmt.getContext(); + final RyaValue object = stmt.getObject(); + final RyaResource context = stmt.getContext(); final Long timestamp = stmt.getTimestamp(); final byte[] columnVisibility = stmt.getColumnVisibility(); final byte[] value = stmt.getValue(); diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/StarQuery.java b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/StarQuery.java index c4b9aebc8..c786ddb37 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/StarQuery.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/StarQuery.java @@ -18,17 +18,15 @@ */ package org.apache.rya.indexing.accumulo.entity; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.common.primitives.Bytes; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.hadoop.io.Text; import org.apache.rya.accumulo.documentIndex.TextColumn; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.domain.VarNameUtils; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaContext; @@ -39,10 +37,11 @@ import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.Var; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.google.common.primitives.Bytes; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; public class StarQuery { @@ -340,7 +339,7 @@ private TextColumn setValue(final TextColumn tc, final Value v) throws RyaTypeRe tc.setColumnQualifier(new Text("subject" + "\u0000" + v.stringValue())); tc.setIsPrefix(false); } else if (cqArray[0].equals("object")) { - final RyaType objType = RdfToRyaConversions.convertValue(v); + final RyaValue objType = RdfToRyaConversions.convertValue(v); final byte[][] b1 = RyaContext.getInstance().serializeType(objType); final byte[] b2 = Bytes.concat("object".getBytes(StandardCharsets.UTF_8), "\u0000".getBytes(StandardCharsets.UTF_8), b1[0], b1[1]); @@ -387,7 +386,7 @@ private TextColumn nodeToTextColumn(final StatementPattern node, final int i) th } else { isCommonVarURI = true; - final RyaType objType = RdfToRyaConversions.convertValue(objVar.getValue()); + final RyaValue objType = RdfToRyaConversions.convertValue(objVar.getValue()); final byte[][] b1 = rc.serializeType(objType); final byte[] b2 = Bytes.concat("object".getBytes(StandardCharsets.UTF_8), "\u0000".getBytes(StandardCharsets.UTF_8), b1[0], b1[1]); diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java index e1afec64e..aba445d97 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java @@ -28,6 +28,7 @@ import org.apache.http.annotation.ThreadingBehavior; import org.apache.log4j.Logger; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.indexing.entity.storage.EntityStorage; import org.apache.rya.indexing.smarturi.SmartUriAdapter; import org.apache.rya.indexing.smarturi.SmartUriException; @@ -78,7 +79,7 @@ public class Entity { private static final Logger log = Logger.getLogger(Entity.class); - private final RyaIRI subject; + private final RyaResource subject; private final ImmutableList explicitTypeIds; // First key is Type ID. @@ -104,7 +105,7 @@ public class Entity { * {@link Entity}. */ private Entity( - final RyaIRI subject, + final RyaResource subject, final ImmutableList explicitTypeIds, final ImmutableMap> typeProperties, final int version, @@ -137,7 +138,7 @@ private Entity( * {@link EntityStorage} to prevent stale updates. */ private Entity( - final RyaIRI subject, + final RyaResource subject, final ImmutableList explicitTypeIds, final ImmutableMap> typeProperties, final int version) { @@ -147,7 +148,7 @@ private Entity( /** * @return Identifies the thing that is being represented as an Entity. */ - public RyaIRI getSubject() { + public RyaResource getSubject() { return subject; } @@ -288,7 +289,7 @@ public static Builder builder(final Entity entity) { @DefaultAnnotation(NonNull.class) public static class Builder { - private RyaIRI subject = null; + private RyaResource subject = null; private final List explicitTypes = new ArrayList<>(); private final Map> properties = new HashMap<>(); private IRI smartUri = null; @@ -324,7 +325,7 @@ public Builder(final Entity entity) { * @param subject - Identifies the {@link TypedEntity}. * @return This {@link Builder} so that method invocations may be chained. */ - public Builder setSubject(@Nullable final RyaIRI subject) { + public Builder setSubject(@Nullable final RyaResource subject) { this.subject = subject; return this; } diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java index cda44bb7a..7970dd3c1 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java @@ -23,7 +23,7 @@ import org.apache.http.annotation.Contract; import org.apache.http.annotation.ThreadingBehavior; import org.apache.rya.api.domain.RyaIRI; -import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import java.util.Objects; @@ -37,15 +37,14 @@ public class Property { private final RyaIRI name; - private final RyaType value; + private final RyaValue value; /** * Constructs an instance of {@link Property}. - * * @param name - Uniquely identifies the {@link Property}. (not null) * @param value - The value of the {@link Property}. (not null) */ - public Property(final RyaIRI name, final RyaType value) { + public Property(final RyaIRI name, final RyaValue value) { this.name = requireNonNull(name); this.value = requireNonNull(value); } @@ -60,7 +59,7 @@ public RyaIRI getName() { /** * @return The value of the {@link Property}. */ - public RyaType getValue() { + public RyaValue getValue() { return value; } diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java index ad0f0dd62..36341c6ad 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java @@ -26,7 +26,8 @@ import org.apache.http.annotation.Contract; import org.apache.http.annotation.ThreadingBehavior; import org.apache.rya.api.domain.RyaIRI; -import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaValue; import java.util.HashMap; import java.util.Map; @@ -46,7 +47,7 @@ public class TypedEntity { /** * The Subject of the {@link Entity} this view was derived from. */ - private final RyaIRI subject; + private final RyaResource subject; /** * The ID of the {@link Type} that defines the structure of this TypedEntity. @@ -75,9 +76,9 @@ public class TypedEntity { * @param explicitlyTyped - {@code true} if the Entity's Type has been explicitly set to the * {@link #typeId} value; {@code false} if it is implicit (this Entity only exists because * it has properties that happen to match that type's properties). - * @param properties - The optional {@link Property} values of this {@link TypedEntity}. (not null) + * @param optionalFields - The map of {@link RyaIRI} to {@link Property} values of this {@link TypedEntity}. (not null) */ - private TypedEntity(final RyaIRI subject, + private TypedEntity(final RyaResource subject, final RyaIRI dataTypeId, final boolean explicitlyTyped, final ImmutableMap optionalFields) { @@ -90,7 +91,7 @@ private TypedEntity(final RyaIRI subject, /** * @return The Subject of the {@link Entity} this view was derived from. */ - public RyaIRI getSubject() { + public RyaResource getSubject() { return subject; } @@ -124,7 +125,7 @@ public ImmutableCollection getProperties() { * @param propertyName - The name of {@link Property} that may be in this Entity. (not null) * @return The value of the Property if it has been set. */ - public Optional getPropertyValue(final RyaIRI propertyName) { + public Optional getPropertyValue(final RyaIRI propertyName) { requireNonNull(propertyName); final Property field = optionalFields.get(propertyName); @@ -183,7 +184,7 @@ public static Builder builder(final TypedEntity entity) { @DefaultAnnotation(NonNull.class) public static class Builder { - private RyaIRI subject; + private RyaResource subject; private RyaIRI typeId; private boolean explicitlyTyped = false; private final Map properties = new HashMap<>(); @@ -192,7 +193,7 @@ public static class Builder { * @param subject - The Subject of the {@link Entity} this view was derived from. * @return This {@link Builder} so that method invocations may be chained. */ - public Builder setId(@Nullable final RyaIRI subject) { + public Builder setId(@Nullable final RyaResource subject) { this.subject = subject; return this; } diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java index 7102e634f..40c747a78 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java @@ -18,20 +18,13 @@ */ package org.apache.rya.indexing.entity.query; -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; - -import org.apache.rya.api.domain.RyaType; +import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; @@ -56,12 +49,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.collect.ImmutableCollection; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * Indexing Node for {@link Entity} expressions to be inserted into execution plan @@ -140,7 +138,7 @@ public EntityQueryNode(final Type type, final Collection patte final RyaIRI predIRI = new RyaIRI(pred.getValue().stringValue()); bindingNames.addAll(sp.getBindingNames()); if(object.isConstant() && !pred.getValue().equals(RDF.TYPE)) { - final RyaType propertyType = RdfToRyaConversions.convertValue(object.getValue()); + final RyaValue propertyType = RdfToRyaConversions.convertValue(object.getValue()); properties.add(new Property(predIRI, propertyType)); } builder.put(predIRI, object); @@ -293,9 +291,9 @@ private List findBindings(final BindingSet bindingSet) throws QueryE final ImmutableCollection properties = typedEntity.getProperties(); //ensure properties match and only add properties that are in the statement patterns to the binding set for(final RyaIRI key : objectVariables.keySet()) { - final Optional prop = typedEntity.getPropertyValue(new RyaIRI(key.getData())); + final Optional prop = typedEntity.getPropertyValue(new RyaIRI(key.getData())); if(prop.isPresent()) { - final RyaType type = prop.get(); + final RyaValue type = prop.get(); final String bindingName = objectVariables.get(key).getName(); resultSet.addBinding(bindingName, SimpleValueFactory.getInstance().createLiteral(type.getData())); } diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java index 22dad9255..a02b6a230 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java @@ -18,10 +18,9 @@ */ package org.apache.rya.indexing.entity.storage; -import java.util.Optional; -import java.util.Set; - -import org.apache.rya.api.domain.RyaIRI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; import org.apache.rya.indexing.entity.model.Type; @@ -30,8 +29,8 @@ import org.apache.rya.indexing.mongodb.update.RyaObjectStorage; import org.calrissian.mango.collect.CloseableIterator; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import java.util.Optional; +import java.util.Set; /** * Stores and provides access to {@link Entity}s. @@ -42,13 +41,13 @@ public interface EntityStorage extends RyaObjectStorage { * Search the stored {@link Entity}s that have a specific {@link Type} as * well as the provided {@link Property} values. * - * @param subject - The {@link RyaIRI} subject of the Entity. (Optional) + * @param subject - The {@link RyaResource} subject of the Entity. (Optional) * @param type - The {@link Type} of the Entities. (not null) * @param properties - The {@link Property} values that must be set on the Entity. (not null) * @return A {@link CloseableIterator} over the {@link TypedEntity}s that match the search parameters. * @throws EntityStorageException A problem occurred while searching the storage. */ - public ConvertingCursor search(final Optional subject, Type type, Set properties) throws EntityStorageException; + public ConvertingCursor search(final Optional subject, Type type, Set properties) throws EntityStorageException; /** * Indicates a problem while interacting with an {@link EntityStorage}. diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java index 4a26128db..505700784 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java @@ -18,21 +18,21 @@ */ package org.apache.rya.indexing.entity.storage.mongo; -import static java.util.Objects.requireNonNull; - -import java.util.List; -import java.util.stream.Collectors; - +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; import org.apache.rya.indexing.entity.storage.mongo.key.MongoDbSafeKey; import org.bson.Document; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import java.util.List; +import java.util.stream.Collectors; + +import static java.util.Objects.requireNonNull; /** * Converts between {@link Entity} and {@link Document}. @@ -66,7 +66,7 @@ public Document toDocument(final Entity entity) { .forEach((propertyNameUri, property) -> { final String propertyName = property.getName().getData(); final String encodedPropertyName = MongoDbSafeKey.encodeKey(propertyName); - final RyaType value = property.getValue(); + final RyaValue value = property.getValue(); typePropertiesDoc.append(encodedPropertyName, ryaTypeConverter.toDocument(value)); }); propertiesDoc.append(typeId.getData(), typePropertiesDoc); diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java index 4d1e19c75..98a4866ed 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java @@ -18,19 +18,19 @@ */ package org.apache.rya.indexing.entity.storage.mongo; -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; +import com.mongodb.ErrorCategory; +import com.mongodb.MongoClient; +import com.mongodb.MongoException; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import com.mongodb.client.model.Filters; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.commons.configuration.ConfigurationException; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; import org.apache.rya.indexing.entity.model.Type; @@ -46,17 +46,16 @@ import org.bson.Document; import org.bson.conversions.Bson; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.mongodb.ErrorCategory; -import com.mongodb.MongoClient; -import com.mongodb.MongoException; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoCursor; -import com.mongodb.client.model.Filters; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * A Mongo DB implementation of {@link EntityStorage}. @@ -172,7 +171,7 @@ public void update(final Entity old, final Entity updated) throws StaleUpdateExc } @Override - public Optional get(final RyaIRI subject) throws EntityStorageException { + public Optional get(final RyaResource subject) throws EntityStorageException { requireNonNull(subject); try { @@ -191,7 +190,7 @@ public Optional get(final RyaIRI subject) throws EntityStorageException } @Override - public ConvertingCursor search(final Optional subject, final Type type, final Set properties) throws EntityStorageException { + public ConvertingCursor search(final Optional subject, final Type type, final Set properties) throws EntityStorageException { requireNonNull(type); requireNonNull(properties); @@ -235,7 +234,7 @@ public ConvertingCursor search(final Optional subject, fina } @Override - public boolean delete(final RyaIRI subject) throws EntityStorageException { + public boolean delete(final RyaResource subject) throws EntityStorageException { requireNonNull(subject); try { @@ -250,7 +249,7 @@ public boolean delete(final RyaIRI subject) throws EntityStorageException { } } - private static Bson makeSubjectFilter(final RyaIRI subject) { + private static Bson makeSubjectFilter(final RyaResource subject) { return Filters.eq(EntityDocumentConverter.SUBJECT, subject.getData()); } @@ -321,7 +320,7 @@ private List searchHasAllExplicitTypes(final ImmutableList expli final RyaIRI firstType = explicitTypeIds.get(0); // Check if that type exists anywhere in storage. - final List subjects = new ArrayList<>(); + final List subjects = new ArrayList<>(); Optional type; try { if (mongoTypeStorage == null) { @@ -336,13 +335,13 @@ private List searchHasAllExplicitTypes(final ImmutableList expli final ConvertingCursor cursor = search(Optional.empty(), type.get(), Collections.emptySet()); while (cursor.hasNext()) { final TypedEntity typedEntity = cursor.next(); - final RyaIRI subject = typedEntity.getSubject(); + final RyaResource subject = typedEntity.getSubject(); subjects.add(subject); } } // Now grab all the Entities that have the subjects we found. - for (final RyaIRI subject : subjects) { + for (final RyaResource subject : subjects) { final Optional entityFromSubject = get(subject); if (entityFromSubject.isPresent()) { final Entity candidateEntity = entityFromSubject.get(); diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java index 80c489e3c..623753132 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java @@ -18,21 +18,21 @@ */ package org.apache.rya.indexing.entity.storage.mongo; -import static java.util.Objects.requireNonNull; - +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.bson.Document; import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * Converts between {@link RyaType} and {@link Document}. */ @DefaultAnnotation(NonNull.class) -public class RyaTypeDocumentConverter implements DocumentConverter { +public class RyaTypeDocumentConverter implements DocumentConverter { private static final ValueFactory VF = SimpleValueFactory.getInstance(); @@ -40,7 +40,7 @@ public class RyaTypeDocumentConverter implements DocumentConverter { public static final String VALUE = "value"; @Override - public Document toDocument(final RyaType ryaType) { + public Document toDocument(final RyaValue ryaType) { requireNonNull(ryaType); return new Document() diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/update/BaseEntityIndexer.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/update/BaseEntityIndexer.java index c495e179a..def5d94b4 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/update/BaseEntityIndexer.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/update/BaseEntityIndexer.java @@ -18,26 +18,15 @@ */ package org.apache.rya.indexing.entity.update; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; -import static java.util.Collections.singleton; -import static java.util.Objects.requireNonNull; -import static java.util.stream.Collectors.groupingBy; - -import java.io.IOException; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; - +import com.google.common.base.Objects; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.hadoop.conf.Configuration; import org.apache.log4j.Logger; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; import org.apache.rya.indexing.entity.model.Type; @@ -52,10 +41,20 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.vocabulary.RDF; -import com.google.common.base.Objects; +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; +import static java.util.Collections.singleton; +import static java.util.Objects.requireNonNull; +import static java.util.stream.Collectors.groupingBy; /** * A base class that may be used to update an {@link EntityStorage} as new @@ -108,10 +107,10 @@ public void storeStatement(final RyaStatement statement) throws IOException { public void storeStatements(final Collection statements) throws IOException { requireNonNull(statements); - final Map> groupedBySubject = statements.stream() + final Map> groupedBySubject = statements.stream() .collect(groupingBy(RyaStatement::getSubject)); - for(final Entry> entry : groupedBySubject.entrySet()) { + for(final Entry> entry : groupedBySubject.entrySet()) { try { updateEntity(entry.getKey(), entry.getValue()); } catch (final IndexingException e) { @@ -127,7 +126,7 @@ public void storeStatements(final Collection statements) throws IO * @param statements - Statements that the {@link Entity} will be updated with. (not null) * @throws IndexingException */ - private void updateEntity(final RyaIRI subject, final Collection statements) throws IndexingException { + private void updateEntity(final RyaResource subject, final Collection statements) throws IndexingException { requireNonNull(subject); requireNonNull(statements); @@ -161,7 +160,7 @@ private void updateEntity(final RyaIRI subject, final Collection s // The Statement is adding a Property to the Entity. else { final RyaIRI propertyName = statement.getPredicate(); - final RyaType propertyValue = statement.getObject(); + final RyaValue propertyValue = statement.getObject(); try(final ConvertingCursor typesIt = types.search(propertyName)) { // Set the Property for each type that includes the Statement's predicate. diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/update/EntityUpdater.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/update/EntityUpdater.java index 6bc368014..6cf33b28e 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/update/EntityUpdater.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/update/EntityUpdater.java @@ -18,25 +18,24 @@ */ package org.apache.rya.indexing.entity.update; -import static java.util.Objects.requireNonNull; - -import java.util.Optional; - -import org.apache.rya.api.domain.RyaIRI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.storage.EntityStorage; import org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException; import org.apache.rya.indexing.mongodb.update.MongoDocumentUpdater; import org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import java.util.Optional; + +import static java.util.Objects.requireNonNull; /** * Performs update operations over an {@link EntityStorage}. */ @DefaultAnnotation(NonNull.class) -public class EntityUpdater implements MongoDocumentUpdater{ +public class EntityUpdater implements MongoDocumentUpdater{ private final EntityStorage storage; @@ -68,7 +67,7 @@ public void update(final Entity old, final Entity updated) throws EntityStorageE } @Override - public Optional getOld(final RyaIRI key) throws EntityStorageException { + public Optional getOld(final RyaResource key) throws EntityStorageException { try { return storage.get(key); } catch (final ObjectStorageException e) { diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/external/matching/AbstractExternalSetOptimizer.java b/extras/indexing/src/main/java/org/apache/rya/indexing/external/matching/AbstractExternalSetOptimizer.java index 9c420e786..9b763792d 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/external/matching/AbstractExternalSetOptimizer.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/external/matching/AbstractExternalSetOptimizer.java @@ -18,10 +18,7 @@ * under the License. */ -import java.util.HashSet; -import java.util.List; -import java.util.Set; - +import com.google.common.base.Optional; import org.apache.rya.indexing.external.matching.QueryNodesToTupleExpr.TupleExprAndNodes; import org.apache.rya.indexing.pcj.matching.PCJOptimizerUtilities; import org.eclipse.rdf4j.query.BindingSet; @@ -37,7 +34,9 @@ import org.eclipse.rdf4j.query.algebra.evaluation.impl.ExternalSet; import org.eclipse.rdf4j.query.algebra.helpers.AbstractQueryModelVisitor; -import com.google.common.base.Optional; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * Abstract base class meant to be extended by any QueryOptimizer that matches ExternalSets @@ -64,7 +63,7 @@ public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) * portion of the query starting with the Join, Filter, or LeftJoin is * replaced by the {@link TupleExpr} returned by * {@link ExternalSetMatcher#getQuery()}. This visitor then visits each of - * the nodes returned by {@link ExternalSetMatcher#getUnmatchedArgs()}. + * the nodes returned by {@link ExternalSetMatcher#getUnmatchedArgNodes()} ()}. * */ protected class QuerySegmentMatchVisitor extends AbstractQueryModelVisitor { diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/external/matching/BasicRater.java b/extras/indexing/src/main/java/org/apache/rya/indexing/external/matching/BasicRater.java index f61fd3f81..c938e107d 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/external/matching/BasicRater.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/external/matching/BasicRater.java @@ -36,24 +36,24 @@ * under the License. */ -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; - import org.apache.rya.api.domain.VarNameUtils; import org.eclipse.rdf4j.query.algebra.QueryModelNode; import org.eclipse.rdf4j.query.algebra.TupleExpr; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * This implementation of the QueryNodeListRater assigns a score to a specified * list between and 0 and 1, where the lower the score, the better the list. It * is assumed that the specified list in * {@link BasicRater#rateQuerySegment(List)} is the result of matching - * {@link ExternalSet}s to the original list specified in the constructor. The + * {@link org.eclipse.rdf4j.query.algebra.evaluation.impl.ExternalSet}s + * to the original list specified in the constructor. The * method {@link BasicRater#rateQuerySegment(List)} determines a score based on * how much smaller the specified list is than the original, and based on how * many connected components the specified list has. Here the components are among diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/MongoDbSmartUri.java b/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/MongoDbSmartUri.java index 17e32c3a3..6446fed6c 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/MongoDbSmartUri.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/MongoDbSmartUri.java @@ -18,15 +18,10 @@ */ package org.apache.rya.indexing.mongodb; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.UnknownHostException; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - +import com.mongodb.MongoClient; +import com.mongodb.MongoException; import org.apache.hadoop.conf.Configuration; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; import org.apache.rya.indexing.entity.model.Type; @@ -43,8 +38,12 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Value; -import com.mongodb.MongoClient; -import com.mongodb.MongoException; +import java.net.UnknownHostException; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; /** * MongoDB implementation of the Smart URI. @@ -64,7 +63,7 @@ public MongoDbSmartUri(final StatefulMongoDBRdfConfiguration conf) { } @Override - public void storeEntity(final RyaIRI subject, final Map map) throws SmartUriException { + public void storeEntity(final RyaResource subject, final Map map) throws SmartUriException { checkInit(); final IRI uri = SmartUriAdapter.serializeUri(subject, map); @@ -103,7 +102,7 @@ public void updateEntity(final Entity oldEntity, final Entity updatedEntity) thr } @Override - public Entity queryEntity(final RyaIRI subject) throws SmartUriException { + public Entity queryEntity(final RyaResource subject) throws SmartUriException { checkInit(); // Query it. diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/update/MongoDocumentUpdater.java b/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/update/MongoDocumentUpdater.java index a7a3eb9a7..cc60151b9 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/update/MongoDocumentUpdater.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/update/MongoDocumentUpdater.java @@ -18,15 +18,14 @@ */ package org.apache.rya.indexing.mongodb.update; -import static java.util.Objects.requireNonNull; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.rya.indexing.mongodb.IndexingException; import java.util.Optional; import java.util.function.Function; -import org.apache.rya.indexing.mongodb.IndexingException; - -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static java.util.Objects.requireNonNull; /** * Performs an update operation on a Document in mongodb. @@ -65,7 +64,7 @@ public default void update(final T key, final DocumentMutator mutator) throws /** * Implementations of this interface are used to update the state of a - * {@link MongoDocumentUpdater#V} in unison with a {@link MongoDocumentUpdater}. + * {@link V} in unison with a {@link MongoDocumentUpdater}. *

    * This table describes what the updater will do depending on if the object * exists and if an updated object is returned. diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/update/RyaObjectStorage.java b/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/update/RyaObjectStorage.java index c420fbaba..9f3a8e61b 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/update/RyaObjectStorage.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/update/RyaObjectStorage.java @@ -18,38 +18,38 @@ */ package org.apache.rya.indexing.mongodb.update; -import java.util.Optional; - -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.indexing.mongodb.IndexingException; +import java.util.Optional; + /** * Stores and provides access to objects of type T. - * The {@link RyaIRI} subject is the primary storage key used. + * The {@link RyaResource} subject is the primary storage key used. * @param - The type of object to store/access. */ public interface RyaObjectStorage { /** - * Creates a new {@link RyaObjectStorage#T} within the storage. The new object's subject must be unique. + * Creates a new {@link T} within the storage. The new object's subject must be unique. * - * @param obj - The {@link RyaObjectStorage#T} to create. (not null) + * @param doc - The {@link T} to create. (not null) * @throws ObjectAlreadyExistsException An Object could not be created because one already exists for the Subject. * @throws ObjectStorageException A problem occurred while creating the Object. */ public void create(T doc) throws ObjectAlreadyExistsException, ObjectStorageException; /** - * Get an Object from the storage by its subject. + * Get an {@link T} object from the storage by its subject. * * @param subject - Identifies which Object to get. (not null) * @return The Object if one exists for the subject. * @throws ObjectStorageException A problem occurred while fetching the Object from the storage. */ - public Optional get(RyaIRI subject) throws ObjectStorageException; + public Optional get(RyaResource subject) throws ObjectStorageException; /** - * Update the state of an {@link RyaObjectStorage#T}. + * Update the state of an {@link T}. * * @param old - The Object the changes were applied to. (not null) * @param updated - The updated Object to store. (not null) @@ -59,13 +59,13 @@ public interface RyaObjectStorage { public void update(T old, T updated) throws StaleUpdateException, ObjectStorageException; /** - * Deletes an {@link RyaObjectStorage#T} from the storage. + * Deletes an {@link RyaResource} from the storage. * - * @param subject -Identifies which {@link RyaObjectStorage#T} to delete. (not null) + * @param subject -Identifies which {@link T} to delete. (not null) * @return {@code true} if something was deleted; otherwise {@code false}. * @throws ObjectStorageException A problem occurred while deleting from the storage. */ - public boolean delete(RyaIRI subject) throws ObjectStorageException; + public boolean delete(RyaResource subject) throws ObjectStorageException; /** * Indicates a problem while interacting with an {@link RyaObjectStorage}. @@ -104,7 +104,7 @@ public ObjectStorageException(final String message, final Throwable cause) { } /** - * An {@link RyaObjectStorage#T} could not be created because one already exists for the Subject. + * An object could not be created because one already exists for the Subject. */ public static class ObjectAlreadyExistsException extends ObjectStorageException { private static final long serialVersionUID = 1L; diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/SmartUriAdapter.java b/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/SmartUriAdapter.java index 21d5ea589..16532c703 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/SmartUriAdapter.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/SmartUriAdapter.java @@ -18,25 +18,22 @@ */ package org.apache.rya.indexing.smarturi; -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - +import com.google.common.base.Charsets; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.ImmutableMap; +import com.google.common.primitives.Doubles; +import com.google.common.primitives.Floats; +import com.google.common.primitives.Ints; +import com.google.common.primitives.Longs; import org.apache.commons.lang3.StringUtils; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaToRdfConversions; import org.apache.rya.indexing.entity.model.Entity; @@ -49,13 +46,17 @@ import org.joda.time.DateTime; import org.joda.time.format.ISODateTimeFormat; -import com.google.common.base.Charsets; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.Doubles; -import com.google.common.primitives.Floats; -import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; /** * Interface for serializing and deserializing Smart URIs. @@ -176,7 +177,7 @@ private static IRI createIndividualTypeWithPropertiesUri(final RyaIRI type, fina final RyaIRI key = entry.getKey(); final Property property = entry.getValue(); - final RyaType ryaType = property.getValue(); + final RyaValue ryaType = property.getValue(); final String keyString = (VF.createIRI(key.getData())).getLocalName(); final Value value = RyaToRdfConversions.convertValue(ryaType); final String valueString = value.stringValue(); @@ -274,7 +275,7 @@ public static IRI serializeUriEntity(final Entity entity) throws SmartUriExcepti final Value typeValue = RyaToRdfConversions.convertValue(valueRyaType); objectMap.put(RYA_TYPES_URI, typeValue); - final RyaIRI subject = entity.getSubject(); + final RyaResource subject = entity.getSubject(); final Map> typeMap = entity.getProperties(); for (final Entry> typeEntry : typeMap.entrySet()) { final RyaIRI type = typeEntry.getKey(); @@ -285,9 +286,9 @@ public static IRI serializeUriEntity(final Entity entity) throws SmartUriExcepti final RyaIRI key = properties.getKey(); final Property property = properties.getValue(); final String valueString = property.getValue().getData(); - final RyaType ryaType = property.getValue(); + final RyaValue ryaType = property.getValue(); - //final RyaType ryaType = new RyaType(VF.createIRI(key.getData()), valueString); + //final RyaValue ryaType = new RyaType(VF.createIRI(key.getData()), valueString); final Value value = RyaToRdfConversions.convertValue(ryaType); @@ -311,7 +312,7 @@ public static IRI serializeUriEntity(final Entity entity) throws SmartUriExcepti * @return the Smart {@link IRI}. * @throws SmartUriException */ - public static IRI serializeUri(final RyaIRI subject, final Map map) throws SmartUriException { + public static IRI serializeUri(final RyaResource subject, final Map map) throws SmartUriException { final String subjectData = subject.getData(); final int fragmentPosition = subjectData.indexOf("#"); String prefix = subjectData; @@ -602,7 +603,7 @@ public static Set mapToProperties(final Map map) { final Value value = entry.getValue(); final RyaIRI ryaIri = new RyaIRI(iri.stringValue()); - final RyaType ryaType = RdfToRyaConversions.convertValue(value); + final RyaValue ryaType = RdfToRyaConversions.convertValue(value); final Property property = new Property(ryaIri, ryaType); properties.add(property); diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/SmartUriStorage.java b/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/SmartUriStorage.java index 0c1650c2f..d310384e8 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/SmartUriStorage.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/SmartUriStorage.java @@ -18,9 +18,8 @@ */ package org.apache.rya.indexing.smarturi; -import java.util.Map; - import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Type; import org.apache.rya.indexing.entity.model.TypedEntity; @@ -29,6 +28,8 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Value; +import java.util.Map; + /** * Interface for interacting with a Smart URI's datastore. */ @@ -40,7 +41,7 @@ public interface SmartUriStorage { * @param map the {@link Map} of {@link IRI}s to {@link Value}s. * @throws SmartUriException */ - public void storeEntity(final RyaIRI subject, final Map map) throws SmartUriException; + public void storeEntity(final RyaResource subject, final Map map) throws SmartUriException; /** * Stores the entity into the datastore. @@ -64,7 +65,7 @@ public interface SmartUriStorage { * @return the {@link Entity} matching the subject. * @throws SmartUriException */ - public Entity queryEntity(final RyaIRI subject) throws SmartUriException; + public Entity queryEntity(final RyaResource subject) throws SmartUriException; /** * Queries the datastore for the map. diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/duplication/DuplicateDataDetector.java b/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/duplication/DuplicateDataDetector.java index 6ac6ab236..60d3bc7ac 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/duplication/DuplicateDataDetector.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/smarturi/duplication/DuplicateDataDetector.java @@ -18,25 +18,11 @@ */ package org.apache.rya.indexing.smarturi.duplication; -import static java.util.Objects.requireNonNull; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.TreeSet; - +import com.google.common.collect.ImmutableMap; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.lang.StringUtils; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.impl.DateTimeRyaTypeResolver; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; @@ -49,7 +35,20 @@ import org.eclipse.rdf4j.model.vocabulary.XMLSchema; import org.joda.time.DateTime; -import com.google.common.collect.ImmutableMap; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; + +import static java.util.Objects.requireNonNull; /** * Detects if two entities contain data that's nearly identical based on a set @@ -266,8 +265,8 @@ public boolean compareEntities(final Entity entity1, final Entity entity2) throw final Optional p2 = entity2.lookupTypeProperty(typeIdUri, propertyNameUri); if (p2.isPresent()) { final Property property2 = p2.get(); - final RyaType value1 = property1.getValue(); - final RyaType value2 = property2.getValue(); + final RyaValue value1 = property1.getValue(); + final RyaValue value2 = property2.getValue(); final String data1 = value1.getData(); final String data2 = value2.getData(); final IRI xmlSchemaUri1 = value1.getDataType(); diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java b/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java index 439d06ae8..ec2214ddf 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java @@ -19,27 +19,15 @@ * under the License. */ -import static java.util.Objects.requireNonNull; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.NoSuchElementException; -import java.util.Optional; -import java.util.Set; - +import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreUtils; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.query.RyaQueryEngine; @@ -60,8 +48,21 @@ import org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet; import org.eclipse.rdf4j.query.algebra.evaluation.impl.ExternalSet; -import com.google.common.base.Joiner; -import com.google.common.base.Preconditions; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.Set; + +import static java.util.Objects.requireNonNull; /** * This class provides users with the ability to issue reified queries to Rya. @@ -98,6 +99,8 @@ * results. This class allows users to issue queries about RyaStatements and any * contextual properties without the inefficiencies associated with reification. * + * See: https://jena.apache.org/documentation/notes/reification.html + * * @param * - Configuration object */ @@ -360,10 +363,10 @@ private RyaStatement getRyaStatementFromBindings(final BindingSet bs) { final Value predValue = getVarValue(statement.getPredicateVar(), bs); final Value objValue = getVarValue(statement.getObjectVar(), bs); final Value contextValue = getVarValue(statement.getContextVar(), bs); - RyaIRI subj = null; + RyaResource subj = null; RyaIRI pred = null; - RyaType obj = null; - RyaIRI context = null; + RyaValue obj = null; + RyaResource context = null; if (subjValue != null) { Preconditions.checkArgument(subjValue instanceof IRI); @@ -636,7 +639,7 @@ private Optional buildBindingSet(final RyaStatement statement, final */ private Optional buildPropertyBindingSet(final RyaStatement statement) { final StatementMetadata metadata = statement.getMetadata(); - final Map statementProps = metadata.getMetadata(); + final Map statementProps = metadata.getMetadata(); if (statementProps.size() < properties.size()) { return Optional.empty(); } diff --git a/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java b/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java index 6d7edfe5d..e78935257 100644 --- a/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java +++ b/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java @@ -18,11 +18,11 @@ */ package org.apache.rya.sail.config; -import static java.util.Objects.requireNonNull; - -import java.util.List; -import java.util.Objects; - +import com.mongodb.MongoClient; +import com.mongodb.MongoClientOptions; +import com.mongodb.MongoCredential; +import com.mongodb.MongoException; +import com.mongodb.ServerAddress; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -51,11 +51,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoCredential; -import com.mongodb.MongoException; -import com.mongodb.ServerAddress; +import java.util.List; +import java.util.Objects; + +import static java.util.Objects.requireNonNull; public class RyaSailFactory { private static final Logger LOG = LoggerFactory.getLogger(RyaSailFactory.class); @@ -218,7 +217,7 @@ public static void updateAccumuloConfig(final AccumuloRdfConfiguration config, f /** * Connects to MongoDB and creates a MongoDBRyaDAO. - * @param config - user configuration + * @param mongoConfig - user configuration * @return - MongoDBRyaDAO with Indexers configured according to user's specification * @throws RyaDAOException if the DAO can't be initialized */ diff --git a/extras/indexing/src/test/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIteratorTest.java b/extras/indexing/src/test/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIteratorTest.java index 02ed88776..241caef73 100644 --- a/extras/indexing/src/test/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIteratorTest.java +++ b/extras/indexing/src/test/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIteratorTest.java @@ -19,10 +19,7 @@ * under the License. */ -import java.util.Collection; -import java.util.List; -import java.util.Map; - +import com.google.common.primitives.Bytes; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriter; @@ -39,9 +36,10 @@ import org.apache.hadoop.io.Text; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.RyaTableMutationsFactory; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaToRdfConversions; @@ -61,7 +59,9 @@ import org.junit.Before; import org.junit.Test; -import com.google.common.primitives.Bytes; +import java.util.Collection; +import java.util.List; +import java.util.Map; public class DocumentIndexIntersectingIteratorTest { @@ -1777,8 +1777,8 @@ public void testSerialization1() throws Exception { System.out.println(spList1); System.out.println(spList2); - RyaType rt1 = RdfToRyaConversions.convertValue(spList1.get(2).getObjectVar().getValue()); - RyaType rt2 = RdfToRyaConversions.convertValue(spList2.get(2).getObjectVar().getValue()); + RyaValue rt1 = RdfToRyaConversions.convertValue(spList1.get(2).getObjectVar().getValue()); + RyaValue rt2 = RdfToRyaConversions.convertValue(spList2.get(2).getObjectVar().getValue()); RyaIRI predURI1 = (RyaIRI) RdfToRyaConversions.convertValue(spList1.get(0).getPredicateVar().getValue()); RyaIRI predURI2 = (RyaIRI) RdfToRyaConversions.convertValue(spList1.get(1).getPredicateVar().getValue()); diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/accumulo/entity/StarQueryTest.java b/extras/indexing/src/test/java/org/apache/rya/indexing/accumulo/entity/StarQueryTest.java index d66dc8e96..6da89bcc4 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/accumulo/entity/StarQueryTest.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/accumulo/entity/StarQueryTest.java @@ -18,13 +18,11 @@ */ package org.apache.rya.indexing.accumulo.entity; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import com.google.common.collect.Sets; +import com.google.common.primitives.Bytes; import org.apache.hadoop.io.Text; import org.apache.rya.accumulo.documentIndex.TextColumn; -import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaTypeResolverException; @@ -42,8 +40,9 @@ import org.junit.Assert; import org.junit.Test; -import com.google.common.collect.Sets; -import com.google.common.primitives.Bytes; +import java.util.List; +import java.util.Map; +import java.util.Set; public class StarQueryTest { @@ -204,7 +203,7 @@ public void testGetContrainedQuery() throws RyaTypeResolverException, MalformedQ Assert.assertTrue(tc1[i].equals(tc3[i])); } else { Assert.assertEquals(tc3[i].getColumnFamily(), new Text("uri:cf3")); - RyaType objType = RdfToRyaConversions.convertValue(v2); + RyaValue objType = RdfToRyaConversions.convertValue(v2); byte[][] b1 = null; b1 = RyaContext.getInstance().serializeType(objType); byte[] b2 = Bytes.concat("object".getBytes(), diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverterTest.java b/extras/indexing/src/test/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverterTest.java index 5ffde39d9..44644650f 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverterTest.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverterTest.java @@ -18,9 +18,8 @@ */ package org.apache.rya.indexing.entity.storage.mongo; -import static org.junit.Assert.assertEquals; - import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException; import org.bson.Document; @@ -28,6 +27,8 @@ import org.eclipse.rdf4j.model.vocabulary.XMLSchema; import org.junit.Test; +import static org.junit.Assert.assertEquals; + /** * Tests the methods of {@link RyaTypeDocumentConverter}. */ @@ -36,7 +37,7 @@ public class RyaTypeDocumentConverterTest { @Test public void toDocument() { // Convert the RyaType into a Document. - final RyaType ryaType = RdfToRyaConversions.convertLiteral( SimpleValueFactory.getInstance().createLiteral( 4.5 ) ); + final RyaValue ryaType = RdfToRyaConversions.convertLiteral( SimpleValueFactory.getInstance().createLiteral( 4.5 ) ); final Document document = new RyaTypeDocumentConverter().toDocument( ryaType ); // Show the document has the correct structure. @@ -55,7 +56,7 @@ public void fromDocument() throws DocumentConverterException { final RyaType ryaType = new RyaTypeDocumentConverter().fromDocument( document ); // Show the converted value has the expected structure. - final RyaType expected = RdfToRyaConversions.convertLiteral( SimpleValueFactory.getInstance().createLiteral( 4.5 ) ); + final RyaValue expected = RdfToRyaConversions.convertLiteral( SimpleValueFactory.getInstance().createLiteral( 4.5 ) ); assertEquals(expected, ryaType); } diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/external/tupleSet/AccumuloIndexSetTest.java b/extras/indexing/src/test/java/org/apache/rya/indexing/external/tupleSet/AccumuloIndexSetTest.java index 6bddd85a9..6f575fae9 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/external/tupleSet/AccumuloIndexSetTest.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/external/tupleSet/AccumuloIndexSetTest.java @@ -18,13 +18,9 @@ */ package org.apache.rya.indexing.external.tupleSet; -import java.math.BigInteger; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - +import com.google.common.base.Optional; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -62,9 +58,12 @@ import org.junit.Before; import org.junit.Test; -import com.google.common.base.Optional; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; +import java.math.BigInteger; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; public class AccumuloIndexSetTest { @@ -130,7 +129,7 @@ public void accumuloIndexSetTestWithEmptyBindingSet() throws RepositoryException final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName); final CloseableIteration results = ais.evaluate(new QueryBindingSet()); - final Set fetchedResults = new HashSet(); + final Set fetchedResults = new HashSet<>(); while(results.hasNext()) { fetchedResults.add(results.next()); } diff --git a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/AccumuloRyaStatementStore.java b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/AccumuloRyaStatementStore.java index ddcdd4c32..4b249c347 100644 --- a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/AccumuloRyaStatementStore.java +++ b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/AccumuloRyaStatementStore.java @@ -18,15 +18,8 @@ */ package org.apache.rya.export.accumulo; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; - +import com.google.common.base.Function; +import com.google.common.collect.Iterators; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.data.Key; @@ -36,6 +29,7 @@ import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.persist.RyaDAOException; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RyaTripleContext; import org.apache.rya.api.resolver.triple.TripleRowResolverException; import org.apache.rya.export.accumulo.parent.AccumuloParentMetadataRepository; @@ -50,8 +44,14 @@ import org.apache.rya.export.api.store.UpdateStatementException; import org.eclipse.rdf4j.common.iteration.CloseableIteration; -import com.google.common.base.Function; -import com.google.common.collect.Iterators; +import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; /** * Allows specific CRUD operations an Accumulo {@link RyaStatement} storage @@ -193,7 +193,7 @@ public RyaStatement findStatement(final RyaStatement ryaStatement) throws RyaDAO RyaStatement resultRyaStatement = null; CloseableIteration iter = null; try { - iter = accumuloRyaDao.getQueryEngine().query(ryaStatement, accumuloRyaDao.getConf()); + iter = RyaDAOHelper.query(accumuloRyaDao.getQueryEngine(), ryaStatement, accumuloRyaDao.getConf()); if (iter.hasNext()) { resultRyaStatement = iter.next(); } diff --git a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/util/AccumuloInstanceDriver.java b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/util/AccumuloInstanceDriver.java index e077751dc..0abb36749 100644 --- a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/util/AccumuloInstanceDriver.java +++ b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/util/AccumuloInstanceDriver.java @@ -18,17 +18,9 @@ */ package org.apache.rya.export.accumulo.util; -import java.io.File; -import java.io.IOException; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.io.Files; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -52,9 +44,16 @@ import org.apache.rya.export.InstanceType; import org.apache.rya.export.accumulo.conf.AccumuloExportConstants; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; /** * Handles running a single {@link MiniAccumuloCluster} or a single {@link MockInstance} for an instance. @@ -584,7 +583,7 @@ public ZooKeeperInstance getZooKeeperInstance() { } /** - * @return the {@link ZooKeepInstance} or {@link MockInstance}. + * @return the {@link ZooKeeperInstance} or {@link MockInstance}. */ public Instance getInstance() { return instance; diff --git a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/util/AccumuloRyaUtils.java b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/util/AccumuloRyaUtils.java index 7e8125c7b..bc0e090eb 100644 --- a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/util/AccumuloRyaUtils.java +++ b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/accumulo/util/AccumuloRyaUtils.java @@ -18,15 +18,8 @@ */ package org.apache.rya.export.accumulo.util; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; - +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -53,8 +46,9 @@ import org.apache.rya.accumulo.mr.MRUtils; import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaTripleContext; @@ -63,8 +57,14 @@ import org.apache.rya.indexing.accumulo.ConfigUtils; import org.eclipse.rdf4j.model.ValueFactory; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; /** * Utility methods for an Accumulo Rya instance. @@ -122,7 +122,7 @@ public static String convertRyaIriToString(final RyaIRI ryaIri) { * @param ryaIri the {@link RyaIRI} to convert. * @return the data value without the namespace. */ - public static String convertRyaIriToString(final String namespace, final RyaIRI ryaIri) { + public static String convertRyaIriToString(final String namespace, final RyaResource ryaIri) { return StringUtils.replaceOnce(ryaIri.getData(), namespace, ""); } @@ -172,7 +172,7 @@ public static void addCommonScannerIteratorsTo(final Scanner scanner) { /** * Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}. * This applies common iterator settings to the table scanner that ignore internal metadata keys. - * @param tablename the name of the table to scan. + * @param tableName the name of the table to scan. * @param config the {@link Configuration}. * @return the {@link Scanner} for the table. * @throws IOException @@ -183,7 +183,7 @@ public static Scanner getScanner(final String tableName, final Configuration con /** * Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}. - * @param tablename the name of the table to scan. + * @param tableName the name of the table to scan. * @param config the {@link Configuration}. * @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner. * {@code false} otherwise. @@ -418,7 +418,7 @@ public static Connector setupConnector(final AccumuloRdfConfiguration accumuloRd /** * Sets up a {@link AccumuloRyaDAO} with the specified connector. - * @param connector the {@link Connector}. + * @param accumuloRdfConfiguration the {@link AccumuloRdfConfiguration}. * @return the {@link AccumuloRyaDAO}. */ public static AccumuloRyaDAO setupDao(final AccumuloRdfConfiguration accumuloRdfConfiguration) { diff --git a/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/TestUtils.java b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/TestUtils.java index d0a00c6a3..cfd0d5025 100644 --- a/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/TestUtils.java +++ b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/TestUtils.java @@ -18,12 +18,13 @@ */ package org.apache.rya.export.accumulo; -import java.util.Date; - -import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.export.accumulo.util.AccumuloRyaUtils; +import java.util.Date; + /** * Utility methods for testing merging/copying. */ @@ -44,7 +45,7 @@ public static RyaIRI createRyaIri(final String localName) { * @param ryaIri the {@link RyaIRI} to convert. * @return the data value without the namespace. */ - public static String convertRyaIriToString(final RyaIRI ryaIri) { + public static String convertRyaIriToString(final RyaResource ryaIri) { return AccumuloRyaUtils.convertRyaIriToString(NAMESPACE, ryaIri); } diff --git a/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/MongoPipelineStrategy.java b/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/MongoPipelineStrategy.java index a0989afc1..3879d9a4d 100644 --- a/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/MongoPipelineStrategy.java +++ b/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/MongoPipelineStrategy.java @@ -18,17 +18,16 @@ */ package org.apache.rya.forwardchain.strategy; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.LongAdder; -import java.util.function.Consumer; - +import com.google.common.base.Preconditions; +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; import org.apache.log4j.Logger; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.RyaDAOException; -import org.apache.rya.api.persist.query.RyaQuery; import org.apache.rya.api.persist.query.RyaQueryEngine; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.forwardchain.ForwardChainException; import org.apache.rya.forwardchain.rule.AbstractConstructRule; import org.apache.rya.forwardchain.rule.Rule; @@ -50,10 +49,10 @@ import org.eclipse.rdf4j.query.algebra.QueryRoot; import org.eclipse.rdf4j.query.algebra.TupleExpr; -import com.google.common.base.Preconditions; -import com.mongodb.MongoClient; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.LongAdder; +import java.util.function.Consumer; /** * A rule execution strategy for MongoDB Rya that converts a single rule into an @@ -208,7 +207,7 @@ public long executeConstructRule(final AbstractConstructRule rule, private boolean statementExists(final RyaStatement rstmt) { try { - return engine.query(new RyaQuery(rstmt)).iterator().hasNext(); + return RyaDAOHelper.query(engine, rstmt, engine.getConf()).hasNext(); } catch (final RyaDAOException e) { logger.error("Error querying for " + rstmt, e); return false; diff --git a/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/RoundRobinStrategy.java b/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/RoundRobinStrategy.java index 9d54f9356..76af8c32b 100644 --- a/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/RoundRobinStrategy.java +++ b/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/RoundRobinStrategy.java @@ -18,13 +18,7 @@ */ package org.apache.rya.forwardchain.strategy; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicBoolean; - +import com.google.common.base.Preconditions; import org.apache.log4j.Logger; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.StatementMetadata; @@ -34,7 +28,12 @@ import org.apache.rya.forwardchain.rule.Ruleset; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; -import com.google.common.base.Preconditions; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.concurrent.atomic.AtomicBoolean; /** * A simple {@link AbstractForwardChainStrategy} that iterates over every @@ -67,7 +66,7 @@ * that could produce triples in response will be triggered. *

    * The procedure for executing the individual rules is governed by the - * {@link RuleExecutionStrategy}. This class uses the strategy's reported counts + * {@link AbstractRuleExecutionStrategy}. This class uses the strategy's reported counts * to determine whether or not a rule has produced inferences. */ public class RoundRobinStrategy extends AbstractForwardChainStrategy { diff --git a/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/SailExecutionStrategy.java b/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/SailExecutionStrategy.java index 86e04eb19..79e99a5aa 100644 --- a/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/SailExecutionStrategy.java +++ b/extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/strategy/SailExecutionStrategy.java @@ -18,6 +18,7 @@ */ package org.apache.rya.forwardchain.strategy; +import com.google.common.base.Preconditions; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.log4j.Logger; @@ -27,15 +28,15 @@ import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.RyaDAO; import org.apache.rya.api.persist.RyaDAOException; -import org.apache.rya.api.persist.query.RyaQuery; import org.apache.rya.api.persist.query.RyaQueryEngine; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.forwardchain.ForwardChainException; import org.apache.rya.forwardchain.rule.AbstractConstructRule; import org.apache.rya.indexing.accumulo.ConfigUtils; import org.apache.rya.mongodb.MongoDBRdfConfiguration; import org.apache.rya.sail.config.RyaSailFactory; -import org.calrissian.mango.collect.CloseableIterable; +import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.query.GraphQuery; import org.eclipse.rdf4j.query.QueryEvaluationException; @@ -47,8 +48,6 @@ import org.eclipse.rdf4j.rio.RDFHandlerException; import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler; -import com.google.common.base.Preconditions; - /** * A naive but back-end-agnostic rule execution strategy that applies a * construct rule by submitting the associated query to a Rya SAIL, then @@ -206,8 +205,9 @@ public void handleStatement(Statement statement) { try { // Need to check whether the statement already exists, because // we need an accurate count of newly added statements. - CloseableIterable iter = engine.query(new RyaQuery(ryaStatement)); - if (!iter.iterator().hasNext()) { + CloseableIteration iter = RyaDAOHelper.query(engine, ryaStatement, engine.getConf()); + if (!iter.hasNext()) { + // Statement does not already exist dao.add(ryaStatement); numStatementsAdded++; } diff --git a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjSerializer.java b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjSerializer.java index 599a48af4..c0065bdeb 100644 --- a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjSerializer.java +++ b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjSerializer.java @@ -18,18 +18,10 @@ */ package org.apache.rya.indexing.pcj.storage.accumulo; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; - -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -import org.apache.rya.api.domain.RyaType; +import com.google.common.primitives.Bytes; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaContext; import org.apache.rya.api.resolver.RyaToRdfConversions; @@ -38,10 +30,16 @@ import org.eclipse.rdf4j.query.BindingSet; import org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet; -import com.google.common.primitives.Bytes; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; /** * Converts {@link BindingSet}s to byte[]s and back again. The bytes do not @@ -63,7 +61,7 @@ public byte[] convert(BindingSet bindingSet, VariableOrder varOrder) throws Bind for(final String varName: varOrder) { // Only write information for a variable name if the binding set contains it. if(bindingSet.hasBinding(varName)) { - final RyaType rt = RdfToRyaConversions.convertValue(bindingSet.getBinding(varName).getValue()); + final RyaValue rt = RdfToRyaConversions.convertValue(bindingSet.getBinding(varName).getValue()); final byte[][] serializedVal = RyaContext.getInstance().serializeType(rt); byteSegments.add(serializedVal[0]); byteSegments.add(serializedVal[1]); @@ -158,7 +156,7 @@ private static Value deserializeValue(byte[] byteVal) throws RyaTypeResolverExce checkArgument(typeIndex >= 0); final byte[] data = Arrays.copyOf(byteVal, typeIndex); final byte[] type = Arrays.copyOfRange(byteVal, typeIndex, byteVal.length); - final RyaType rt = RyaContext.getInstance().deserialize(Bytes.concat(data,type)); + final RyaValue rt = RyaContext.getInstance().deserialize(Bytes.concat(data,type)); return RyaToRdfConversions.convertValue(rt); } } \ No newline at end of file diff --git a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/BindingSetStringConverter.java b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/BindingSetStringConverter.java index 4647b8be0..74f07517b 100644 --- a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/BindingSetStringConverter.java +++ b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/BindingSetStringConverter.java @@ -18,13 +18,10 @@ */ package org.apache.rya.indexing.pcj.storage.accumulo; -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.rya.api.domain.RyaType; +import com.google.common.base.Joiner; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Value; @@ -35,10 +32,11 @@ import org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet; import org.eclipse.rdf4j.query.impl.MapBindingSet; -import com.google.common.base.Joiner; +import java.util.ArrayList; +import java.util.List; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; /** * Converts {@link BindingSet}s to Strings and back again. The Strings do not @@ -64,7 +62,7 @@ public String convert(final BindingSet bindingSet, final VariableOrder varOrder) if(bindingSet.hasBinding(varName)) { // Add a value to the binding set. final Value value = bindingSet.getBinding(varName).getValue(); - final RyaType ryaValue = RdfToRyaConversions.convertValue(value); + final RyaValue ryaValue = RdfToRyaConversions.convertValue(value); final String bindingString = ryaValue.getData() + TYPE_DELIM + ryaValue.getDataType(); bindingStrings.add(bindingString); } else { diff --git a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/PcjTables.java b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/PcjTables.java index 2380ebb5d..5f2ebf03b 100644 --- a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/PcjTables.java +++ b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/PcjTables.java @@ -18,18 +18,9 @@ */ package org.apache.rya.indexing.pcj.storage.accumulo; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - +import com.google.common.base.Optional; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriter; @@ -68,10 +59,17 @@ import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; -import com.google.common.base.Optional; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * Functions that create and maintain the PCJ tables that are used by Rya. @@ -187,7 +185,7 @@ public void createPcjTable( } /** - * Create the {@link Mutation}s required to write a {@link PCJMetadata} object + * Create the {@link Mutation}s required to write a {@link PcjMetadata} object * to an Accumulo table. * * @param metadata - The metadata to write. (not null) @@ -225,7 +223,7 @@ private static List makeWriteMetadataMutations(final PcjMetadata metad } /** - * Fetch the {@link PCJMetadata} from an Accumulo table. + * Fetch the {@link PcjMetadata} from an Accumulo table. *

    * This method assumes the PCJ table has already been created. * @@ -387,7 +385,7 @@ private void writeResults( } /** - * Create the {@link Mutations} required to write a new {@link BindingSet} + * Create the {@link Mutation}s required to write a new {@link BindingSet} * to a PCJ table for each {@link VariableOrder} that is provided. * * @param varOrders - The variables orders the result will be written to. (not null) @@ -574,7 +572,7 @@ public void populatePcj( final TupleQueryResult results = query.evaluate(); // Load batches of 1000 of them at a time into the PCJ table - final Set batch = new HashSet<>(1000); + final Set batch = new HashSet<>(1000); // Match below while(results.hasNext()) { batch.add( new VisibilityBindingSet(results.next()) ); diff --git a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/VariableOrder.java b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/VariableOrder.java index 8a7d15b5d..9c31ac807 100644 --- a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/VariableOrder.java +++ b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/VariableOrder.java @@ -18,20 +18,18 @@ */ package org.apache.rya.indexing.pcj.storage.accumulo; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.rdf4j.query.Binding; -import org.eclipse.rdf4j.query.BindingSet; - import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; - import edu.umd.cs.findbugs.annotations.DefaultAnnotation; import edu.umd.cs.findbugs.annotations.NonNull; import net.jcip.annotations.Immutable; +import org.eclipse.rdf4j.query.Binding; +import org.eclipse.rdf4j.query.BindingSet; + +import java.util.Collection; +import java.util.Iterator; + +import static com.google.common.base.Preconditions.checkNotNull; /** * An ordered list of {@link BindingSet} variable names. These are used to @@ -64,7 +62,7 @@ public VariableOrder(final String... varOrder) { } /** - * Constructs an instance of {@link VariableOrdeR{. + * Constructs an instance of {@link VariableOrder}. * * @param varOrder - An ordered collection of Binding Set variables. (not null) */ diff --git a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/mongo/MongoPcjDocuments.java b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/mongo/MongoPcjDocuments.java index 86890a39a..95e45cb13 100644 --- a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/mongo/MongoPcjDocuments.java +++ b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/mongo/MongoPcjDocuments.java @@ -18,20 +18,13 @@ */ package org.apache.rya.indexing.pcj.storage.mongo; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.apache.rya.api.domain.RyaType; +import com.mongodb.MongoClient; +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.model.VisibilityBindingSet; import org.apache.rya.api.resolver.RdfToRyaConversions; -import org.apache.rya.api.resolver.RyaToRdfConversions; import org.apache.rya.api.utils.CloseableIterator; import org.apache.rya.indexing.pcj.storage.PcjMetadata; import org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException; @@ -44,6 +37,7 @@ import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.XMLSchema; import org.eclipse.rdf4j.query.BindingSet; import org.eclipse.rdf4j.query.MalformedQueryException; import org.eclipse.rdf4j.query.QueryEvaluationException; @@ -54,10 +48,15 @@ import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; -import com.mongodb.MongoClient; -import com.mongodb.client.FindIterable; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoCursor; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * Creates and modifies PCJs in MongoDB. PCJ's are stored as follows: @@ -238,7 +237,7 @@ public void addResults(final String pcjId, final Collection { - final RyaType type = RdfToRyaConversions.convertValue(binding.getValue()); + final RyaValue type = RdfToRyaConversions.convertValue(binding.getValue()); bindingDoc.append(binding.getName(), new Document() .append(BINDING_TYPE, type.getDataType().stringValue()) @@ -393,7 +392,7 @@ public CloseableIterator getResults(final String pcjId, final Collec final Document bindingDoc = new Document(); final List bindings = new ArrayList<>(); bindingSet.forEach(binding -> { - final RyaType type = RdfToRyaConversions.convertValue(binding.getValue()); + final RyaValue type = RdfToRyaConversions.convertValue(binding.getValue()); final Document typeDoc = new Document() .append(BINDING_TYPE, type.getDataType().stringValue()) .append(BINDING_VALUE, type.getData()); @@ -427,8 +426,14 @@ public BindingSet next() { // is the binding value. final Document typeDoc = (Document) bs.get(key); final IRI dataType = VF.createIRI(typeDoc.getString(BINDING_TYPE)); - final RyaType type = new RyaType(dataType, typeDoc.getString(BINDING_VALUE)); - final Value value = RyaToRdfConversions.convertValue(type); + final Value value; + // Decide whether the value is a IRI or a Literal + if (XMLSchema.ANYURI.equals(dataType)) { + value = VF.createIRI(typeDoc.getString(BINDING_VALUE)); + } else { + // We need to do this to correctly convert the string representation to the correct data type + value = VF.createLiteral(typeDoc.getString(BINDING_VALUE), dataType); + } binding.addBinding(key, value); } } diff --git a/extras/rya.indexing.pcj/src/test/java/org/apache/rya/indexing/pcj/storage/mongo/MongoPcjStorageIT.java b/extras/rya.indexing.pcj/src/test/java/org/apache/rya/indexing/pcj/storage/mongo/MongoPcjStorageIT.java index 8a2bd1743..fc2849ad9 100644 --- a/extras/rya.indexing.pcj/src/test/java/org/apache/rya/indexing/pcj/storage/mongo/MongoPcjStorageIT.java +++ b/extras/rya.indexing.pcj/src/test/java/org/apache/rya/indexing/pcj/storage/mongo/MongoPcjStorageIT.java @@ -18,16 +18,8 @@ */ package org.apache.rya.indexing.pcj.storage.mongo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; import org.apache.rya.api.instance.RyaDetails; import org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails; import org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails; @@ -40,7 +32,6 @@ import org.apache.rya.api.utils.CloseableIterator; import org.apache.rya.indexing.pcj.storage.PcjMetadata; import org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage; -import org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage; import org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory; import org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder; import org.apache.rya.mongodb.MongoRyaITBase; @@ -51,11 +42,18 @@ import org.eclipse.rdf4j.query.impl.MapBindingSet; import org.junit.Test; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** - * Integration tests the methods of {@link AccumuloPcjStorage}. + * Integration tests the methods of {@link MongoPcjStorage}. *

    * These tests ensures that the PCJ tables are maintained and that these operations * also update the Rya instance's details. diff --git a/extras/rya.indexing.pcj/src/test/java/org/apache/rya/indexing/pcj/storage/mongo/PcjDocumentsIntegrationTest.java b/extras/rya.indexing.pcj/src/test/java/org/apache/rya/indexing/pcj/storage/mongo/PcjDocumentsIntegrationTest.java index 64a7433d5..9b6e61c6e 100644 --- a/extras/rya.indexing.pcj/src/test/java/org/apache/rya/indexing/pcj/storage/mongo/PcjDocumentsIntegrationTest.java +++ b/extras/rya.indexing.pcj/src/test/java/org/apache/rya/indexing/pcj/storage/mongo/PcjDocumentsIntegrationTest.java @@ -18,14 +18,8 @@ */ package org.apache.rya.indexing.pcj.storage.mongo; -import static org.junit.Assert.assertEquals; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - +import com.google.common.base.Optional; +import com.google.common.collect.Sets; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -54,8 +48,13 @@ import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; import org.junit.Test; -import com.google.common.base.Optional; -import com.google.common.collect.Sets; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertEquals; /** * Performs integration test using {@link MongoClient} to ensure the @@ -197,7 +196,7 @@ public void listResults() throws Exception { * Ensure when results are already stored in Rya, that we are able to populate * the PCJ table for a new SPARQL query using those results. *

    - * The method being tested is: {@link PcjTables#populatePcj(Connector, String, RepositoryConnection, String)} + * The method being tested is: {@link PcjTables#populatePcj(Connector, String, RepositoryConnection)} */ @Test public void populatePcj() throws Exception { diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/mappers/FileCopyToolMapper.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/mappers/FileCopyToolMapper.java index afb0585be..8c369a00b 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/mappers/FileCopyToolMapper.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/mappers/FileCopyToolMapper.java @@ -18,13 +18,9 @@ */ package org.apache.rya.accumulo.mr.merge.mappers; -import java.io.IOException; -import java.util.Map; - import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; import org.apache.log4j.Logger; - import org.apache.rya.accumulo.AccumuloRdfUtils; import org.apache.rya.accumulo.mr.merge.util.AccumuloRyaUtils; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; @@ -32,6 +28,9 @@ import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolverException; +import java.io.IOException; +import java.util.Map; + /** * Extended {@link BaseCopyToolMapper} that handles the {@code AccumuloFileOutputFormat} for the copy tool. */ @@ -70,7 +69,7 @@ protected void addMetadataKeys(final Context context) throws IOException { } private void writeRyaStatement(final RyaStatement ryaStatement, final Context context) throws TripleRowResolverException, IOException, InterruptedException { - final Map serialize = childRyaContext.getTripleResolver().serialize(ryaStatement); + final Map serialize = childRyaContext.serializeTriple(ryaStatement); final TripleRow tripleRow = serialize.get(TABLE_LAYOUT.SPO); final Key key = AccumuloRdfUtils.from(tripleRow); final Value value = AccumuloRdfUtils.extractValue(tripleRow); diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloQueryRuleset.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloQueryRuleset.java index aa0f6155f..8712c187f 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloQueryRuleset.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloQueryRuleset.java @@ -18,12 +18,6 @@ */ package org.apache.rya.accumulo.mr.merge.util; -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - import org.apache.accumulo.core.client.mapreduce.InputTableConfig; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Range; @@ -34,15 +28,18 @@ import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.query.strategy.TriplePatternStrategy; -import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaTripleContext; -import org.apache.rya.api.utils.NullableStatementImpl; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; -import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.Var; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + /** * A {@link QueryRuleset} that additionally maps rules to ranges in Accumulo tables. Also enables * copying one or more entire tables, independent of the query-derived rules. @@ -78,19 +75,18 @@ public AccumuloQueryRuleset(final RdfCloudTripleStoreConfiguration conf) throws /** * Turn a single StatementPattern into a Range. - * @param conf + * @param sp * @throws IOException if the range can't be resolved */ private Map.Entry getRange(final StatementPattern sp) throws IOException { final Var context = sp.getContextVar(); - final Statement stmt = new NullableStatementImpl((Resource) sp.getSubjectVar().getValue(), + final RyaStatement rs = new RyaStatement((Resource) sp.getSubjectVar().getValue(), (IRI) sp.getPredicateVar().getValue(), sp.getObjectVar().getValue(), context == null ? null : (Resource) context.getValue()); - final RyaStatement rs = RdfToRyaConversions.convertStatement(stmt); final TriplePatternStrategy strategy = ryaContext.retrieveStrategy(rs); - final Map.Entry entry = + final ByteRange range = strategy.defineRange(rs.getSubject(), rs.getPredicate(), rs.getObject(), rs.getContext(), conf); - return entry; + return new RdfCloudTripleStoreUtils.CustomEntry<>(strategy.getLayout(), range); } /** diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java index 12e40989e..21724ac78 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java @@ -18,17 +18,8 @@ */ package org.apache.rya.accumulo.mr.merge.util; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; - +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -54,18 +45,27 @@ import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.accumulo.mr.MRUtils; import org.apache.rya.api.RdfCloudTripleStoreConstants; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.persist.RyaDAOException; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.indexing.accumulo.ConfigUtils; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.model.ValueFactory; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; /** * Utility methods for an Accumulo Rya instance. @@ -227,7 +227,7 @@ private static String getMetadata(final RyaIRI predicateRyaIri, final AccumuloRy private static String getMetadata(final RyaStatement ryaStatement, final AccumuloRyaDAO dao) throws RyaDAOException { String metadata = null; final AccumuloRdfConfiguration config = dao.getConf(); - final CloseableIteration iter = dao.getQueryEngine().query(ryaStatement, config); + final CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), ryaStatement, config); if (iter.hasNext()) { metadata = iter.next().getObject().getData(); } @@ -350,7 +350,7 @@ public static void addCommonScannerIteratorsTo(final Scanner scanner) { /** * Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}. * This applies common iterator settings to the table scanner that ignore internal metadata keys. - * @param tablename the name of the table to scan. + * @param tableName the name of the table to scan. * @param config the {@link Configuration}. * @return the {@link Scanner} for the table. * @throws IOException @@ -361,7 +361,7 @@ public static Scanner getScanner(final String tableName, final Configuration con /** * Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}. - * @param tablename the name of the table to scan. + * @param tableName the name of the table to scan. * @param config the {@link Configuration}. * @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner. * {@code false} otherwise. @@ -596,7 +596,7 @@ public static Connector setupConnector(final AccumuloRdfConfiguration accumuloRd /** * Sets up a {@link AccumuloRyaDAO} with the specified connector. - * @param connector the {@link Connector}. + * @param accumuloRdfConfiguration the {@link AccumuloRdfConfiguration}. * @return the {@link AccumuloRyaDAO}. */ public static AccumuloRyaDAO setupDao(final AccumuloRdfConfiguration accumuloRdfConfiguration) { diff --git a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java index d78505224..93c57fb88 100644 --- a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java +++ b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java @@ -18,20 +18,6 @@ */ package org.apache.rya.accumulo.mr.merge; -import static org.apache.rya.accumulo.mr.merge.util.TestUtils.LAST_MONTH; -import static org.apache.rya.accumulo.mr.merge.util.TestUtils.TODAY; -import static org.apache.rya.accumulo.mr.merge.util.TestUtils.YESTERDAY; -import static org.apache.rya.accumulo.mr.merge.util.TestUtils.createRyaStatement; -import static org.apache.rya.accumulo.mr.merge.util.ToolConfigUtils.makeArgument; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.io.File; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -56,6 +42,7 @@ import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.persist.RyaDAOException; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.indexing.accumulo.ConfigUtils; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.junit.After; @@ -65,6 +52,20 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.io.File; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import static org.apache.rya.accumulo.mr.merge.util.TestUtils.LAST_MONTH; +import static org.apache.rya.accumulo.mr.merge.util.TestUtils.TODAY; +import static org.apache.rya.accumulo.mr.merge.util.TestUtils.YESTERDAY; +import static org.apache.rya.accumulo.mr.merge.util.TestUtils.createRyaStatement; +import static org.apache.rya.accumulo.mr.merge.util.ToolConfigUtils.makeArgument; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** * Tests for {@link CopyTool}. */ @@ -298,7 +299,7 @@ public void testCopyTool() throws Exception { // Check that it can NOT be queried with some other visibility childConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, "bad_auth"); - final CloseableIteration iter = childDao.getQueryEngine().query(ryaStatementVisibilityDifferent, childConfig); + final CloseableIteration iter = RyaDAOHelper.query(childDao.getQueryEngine(), ryaStatementVisibilityDifferent, childConfig); count = 0; try { while (iter.hasNext()) { diff --git a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java index 24902e06b..0c2b809ba 100644 --- a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java +++ b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java @@ -18,19 +18,6 @@ */ package org.apache.rya.accumulo.mr.merge; -import static org.apache.rya.accumulo.mr.merge.util.TestUtils.LAST_MONTH; -import static org.apache.rya.accumulo.mr.merge.util.TestUtils.TODAY; -import static org.apache.rya.accumulo.mr.merge.util.TestUtils.YESTERDAY; -import static org.apache.rya.accumulo.mr.merge.util.TestUtils.createRyaStatement; -import static org.apache.rya.accumulo.mr.merge.util.ToolConfigUtils.makeArgument; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.util.Date; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.TreeSet; - import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Scanner; @@ -52,6 +39,7 @@ import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.persist.RyaDAOException; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.junit.After; import org.junit.AfterClass; @@ -59,6 +47,19 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.util.Date; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.TreeSet; + +import static org.apache.rya.accumulo.mr.merge.util.TestUtils.LAST_MONTH; +import static org.apache.rya.accumulo.mr.merge.util.TestUtils.TODAY; +import static org.apache.rya.accumulo.mr.merge.util.TestUtils.YESTERDAY; +import static org.apache.rya.accumulo.mr.merge.util.TestUtils.createRyaStatement; +import static org.apache.rya.accumulo.mr.merge.util.ToolConfigUtils.makeArgument; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** * Tests for {@link MergeTool}. */ @@ -267,7 +268,7 @@ public void testMergeTool() throws Exception { // Check that it can NOT be queried with some other visibility parentConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, "bad_auth"); - final CloseableIteration iter = parentDao.getQueryEngine().query(ryaStatementVisibilityDifferent, parentConfig); + final CloseableIteration iter = RyaDAOHelper.query(parentDao.getQueryEngine(), ryaStatementVisibilityDifferent, parentConfig); count = 0; try { while (iter.hasNext()) { diff --git a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/util/TestUtils.java b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/util/TestUtils.java index 23e35a251..c5a3f0f32 100644 --- a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/util/TestUtils.java +++ b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/util/TestUtils.java @@ -18,18 +18,19 @@ */ package org.apache.rya.accumulo.mr.merge.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Date; - import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; -import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.persist.RyaDAOException; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.eclipse.rdf4j.common.iteration.CloseableIteration; +import java.util.Date; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Utility methods for testing merging/copying. */ @@ -196,7 +197,7 @@ public static Date dateFrom(final Date date, final long duration, final Calendar * @throws RyaDAOException */ public static void assertStatementInInstance(final String description, final int verifyResultCount, final RyaStatement matchStatement, final AccumuloRyaDAO dao, final AccumuloRdfConfiguration config) throws RyaDAOException { - final CloseableIteration iter = dao.getQueryEngine().query(matchStatement, config); + final CloseableIteration iter = RyaDAOHelper.query(dao.getQueryEngine(), matchStatement, config); int count = 0; while (iter.hasNext()) { final RyaStatement statement = iter.next(); diff --git a/extras/rya.pcj.fluo/pcj.fluo.api/src/main/java/org/apache/rya/indexing/pcj/fluo/api/CreateFluoPcj.java b/extras/rya.pcj.fluo/pcj.fluo.api/src/main/java/org/apache/rya/indexing/pcj/fluo/api/CreateFluoPcj.java index 220b7fa22..4d6da3ff3 100644 --- a/extras/rya.pcj.fluo/pcj.fluo.api/src/main/java/org/apache/rya/indexing/pcj/fluo/api/CreateFluoPcj.java +++ b/extras/rya.pcj.fluo/pcj.fluo.api/src/main/java/org/apache/rya/indexing/pcj/fluo/api/CreateFluoPcj.java @@ -18,16 +18,10 @@ */ package org.apache.rya.indexing.pcj.fluo.api; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.Objects.requireNonNull; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -39,11 +33,12 @@ import org.apache.rya.accumulo.query.AccumuloRyaQueryEngine; import org.apache.rya.api.client.CreatePCJ.ExportStrategy; import org.apache.rya.api.client.CreatePCJ.QueryType; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; -import org.apache.rya.api.persist.query.BatchRyaQuery; +import org.apache.rya.api.persist.utils.RyaDAOHelper; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.indexing.pcj.fluo.app.FluoStringConverter; import org.apache.rya.indexing.pcj.fluo.app.NodeType; @@ -56,18 +51,22 @@ import org.apache.rya.indexing.pcj.storage.PcjException; import org.apache.rya.indexing.pcj.storage.PcjMetadata; import org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage; -import org.calrissian.mango.collect.CloseableIterable; +import org.eclipse.rdf4j.common.iteration.CloseableIteration; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.query.MalformedQueryException; import org.eclipse.rdf4j.query.algebra.StatementPattern; -import com.google.common.base.Preconditions; -import com.google.common.collect.Sets; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * Sets up a new Pre Computed Join (PCJ) in Fluo from a SPARQL query. @@ -136,7 +135,6 @@ public CreateFluoPcj(final int spInsertBatchSize, final int joinBatchSize) { * according to the Kafka {@link ExportStrategy}. * * @param sparql - sparql query String to be registered with Fluo - * @param strategies - ExportStrategies used to specify how final results will be handled * @param fluo - A connection to the Fluo application that updates the PCJ index. (not null) * @return The metadata that was written to the Fluo application for the PCJ. * @throws MalformedQueryException The SPARQL query stored for the {@code pcjId} is malformed. @@ -385,11 +383,12 @@ private void importHistoricResultsIntoFluo(FluoClient fluo, FluoQuery fluoQuery, conf.setAuths(getAuths(accumulo)); try (final AccumuloRyaQueryEngine queryEngine = new AccumuloRyaQueryEngine(accumulo, conf); - CloseableIterable queryIterable = queryEngine.query(new BatchRyaQuery(queryBatch))) { + CloseableIteration query = RyaDAOHelper.query(queryEngine, queryBatch, conf)) { final Set triplesBatch = new HashSet<>(); // Insert batches of the binding sets into Fluo. - for (final RyaStatement ryaStatement : queryIterable) { + while (query.hasNext()) { + final RyaStatement ryaStatement = query.next(); if (triplesBatch.size() == spInsertBatchSize) { writeBatch(fluo, triplesBatch); triplesBatch.clear(); @@ -418,9 +417,9 @@ private static RyaStatement spToRyaStatement(final StatementPattern sp) { final Value predVal = sp.getPredicateVar().getValue(); final Value objVal = sp.getObjectVar().getValue(); - RyaIRI subjIRI = null; + RyaResource subjIRI = null; RyaIRI predIRI = null; - RyaType objType = null; + RyaValue objType = null; if(subjVal != null) { if(!(subjVal instanceof Resource)) { diff --git a/extras/rya.pcj.fluo/pcj.fluo.app/src/main/java/org/apache/rya/indexing/pcj/fluo/app/ConstructProjection.java b/extras/rya.pcj.fluo/pcj.fluo.app/src/main/java/org/apache/rya/indexing/pcj/fluo/app/ConstructProjection.java index 819695531..dc0fdd3f3 100644 --- a/extras/rya.pcj.fluo/pcj.fluo.app/src/main/java/org/apache/rya/indexing/pcj/fluo/app/ConstructProjection.java +++ b/extras/rya.pcj.fluo/pcj.fluo.app/src/main/java/org/apache/rya/indexing/pcj/fluo/app/ConstructProjection.java @@ -19,15 +19,14 @@ * under the License. */ -import java.io.UnsupportedEncodingException; -import java.util.Map; -import java.util.Optional; - +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.log4j.Logger; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.domain.VarNameUtils; import org.apache.rya.api.model.VisibilityBindingSet; import org.apache.rya.api.resolver.RdfToRyaConversions; @@ -41,8 +40,9 @@ import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.Var; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; +import java.io.UnsupportedEncodingException; +import java.util.Map; +import java.util.Optional; /** * This class projects a VisibilityBindingSet onto a RyaStatement. The Binding @@ -205,9 +205,9 @@ public RyaStatement projectBindingSet(VisibilityBindingSet vBs, Map statements = graph.createGraphFromBindingSet(vBs); Set statements2 = graph.createGraphFromBindingSet(vBs); - - RyaIRI subject = null; + + RyaResource subject = null; for(RyaStatement statement: statements) { - RyaIRI subjURI = statement.getSubject(); + RyaResource subjURI = statement.getSubject(); if(subject == null) { subject = subjURI; } else { assertEquals(subjURI, subject); } } - RyaIRI subject2 = null; + RyaResource subject2 = null; for(RyaStatement statement: statements2) { - RyaIRI subjURI = statement.getSubject(); + RyaResource subjURI = statement.getSubject(); if(subject2 == null) { subject2 = subjURI; } else { diff --git a/extras/rya.pcj.fluo/pcj.fluo.app/src/test/java/org/apache/rya/indexing/pcj/fluo/app/ConstructGraphTestUtils.java b/extras/rya.pcj.fluo/pcj.fluo.app/src/test/java/org/apache/rya/indexing/pcj/fluo/app/ConstructGraphTestUtils.java index ac21cdf4d..cb13885c7 100644 --- a/extras/rya.pcj.fluo/pcj.fluo.app/src/test/java/org/apache/rya/indexing/pcj/fluo/app/ConstructGraphTestUtils.java +++ b/extras/rya.pcj.fluo/pcj.fluo.app/src/test/java/org/apache/rya/indexing/pcj/fluo/app/ConstructGraphTestUtils.java @@ -18,19 +18,18 @@ * under the License. */ -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - +import com.google.common.base.Objects; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaSubGraph; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.resolver.RyaToRdfConversions; import org.eclipse.rdf4j.model.Statement; import org.junit.Assert; -import com.google.common.base.Objects; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; public class ConstructGraphTestUtils { @@ -61,7 +60,7 @@ private static int getKey(RyaSubGraph subgraph) { } public static void ryaStatementsEqualIgnoresBlankNode(Set statements1, Set statements2) { - Map bNodeMap = new HashMap<>(); + Map bNodeMap = new HashMap<>(); statements1.forEach(x-> bNodeMap.put(x.getPredicate().getData(), x.getSubject())); statements2.forEach(x -> x.setSubject(bNodeMap.get(x.getPredicate().getData()))); ryaStatementSetsEqualIgnoresTimestamp(statements1, statements2); diff --git a/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/FluoAndHistoricPcjsDemo.java b/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/FluoAndHistoricPcjsDemo.java index b12dc9e93..56b16d8e4 100644 --- a/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/FluoAndHistoricPcjsDemo.java +++ b/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/FluoAndHistoricPcjsDemo.java @@ -18,9 +18,8 @@ */ package org.apache.rya.indexing.pcj.fluo.demo; -import java.nio.charset.StandardCharsets; -import java.util.Set; - +import com.google.common.base.Optional; +import com.google.common.collect.Sets; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.minicluster.MiniAccumuloCluster; import org.apache.commons.lang3.StringUtils; @@ -28,9 +27,10 @@ import org.apache.fluo.api.mini.MiniFluo; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.resolver.RyaToRdfConversions; import org.apache.rya.api.utils.CloseableIterator; @@ -50,8 +50,8 @@ import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; -import com.google.common.base.Optional; -import com.google.common.collect.Sets; +import java.nio.charset.StandardCharsets; +import java.util.Set; /** * Demonstrates historicly added Rya statements that are stored within the core @@ -292,9 +292,9 @@ private static void loadDataIntoFluo(final FluoClient fluoClient, final Set <"+ p.getData() + "> <" + o.getData() + ">"; } diff --git a/extras/rya.pcj.fluo/pcj.fluo.integration/src/test/java/org/apache/rya/indexing/pcj/fluo/ConstructGraphTestUtils.java b/extras/rya.pcj.fluo/pcj.fluo.integration/src/test/java/org/apache/rya/indexing/pcj/fluo/ConstructGraphTestUtils.java index 0f15a5d4b..daa588ace 100644 --- a/extras/rya.pcj.fluo/pcj.fluo.integration/src/test/java/org/apache/rya/indexing/pcj/fluo/ConstructGraphTestUtils.java +++ b/extras/rya.pcj.fluo/pcj.fluo.integration/src/test/java/org/apache/rya/indexing/pcj/fluo/ConstructGraphTestUtils.java @@ -18,20 +18,19 @@ * under the License. */ -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaSubGraph; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.resolver.RyaToRdfConversions; import org.eclipse.rdf4j.model.Statement; import org.junit.Assert; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; public class ConstructGraphTestUtils { @@ -72,7 +71,7 @@ private static int getKey(RyaSubGraph subgraph) { } public static void ryaStatementsEqualIgnoresBlankNode(Set statements1, Set statements2) { - Map bNodeMap = new HashMap<>(); + Map bNodeMap = new HashMap<>(); statements1.forEach(x-> bNodeMap.put(x.getPredicate().getData(), x.getSubject())); statements2.forEach(x -> x.setSubject(bNodeMap.get(x.getPredicate().getData()))); ryaStatementSetsEqualIgnoresTimestamp(statements1, statements2); diff --git a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/domain/TripleValueType.java b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/domain/TripleValueType.java index 16e7916b7..e3116ed07 100644 --- a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/domain/TripleValueType.java +++ b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/domain/TripleValueType.java @@ -18,10 +18,10 @@ */ package org.apache.rya.prospector.domain; -import static java.util.Objects.requireNonNull; - import com.google.common.collect.ImmutableMap; +import static java.util.Objects.requireNonNull; + /** * Enumerates the different types of counts that are performed over a Rya instance's * Statements as part of a Prospector run. @@ -46,7 +46,7 @@ public enum TripleValueType { OBJECT("object"), /** - * The data portion of an {@link IndexEntrY} contains a unique Namespace from + * The data portion of an {@link IndexEntry} contains a unique Namespace from * the Subjects that appear within a Rya instance. */ ENTITY("entity"), diff --git a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/mr/Prospector.java b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/mr/Prospector.java index 78ea37132..fb9274429 100644 --- a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/mr/Prospector.java +++ b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/mr/Prospector.java @@ -18,20 +18,6 @@ */ package org.apache.rya.prospector.mr; -import static org.apache.rya.prospector.utils.ProspectorConstants.DEFAULT_VIS; -import static org.apache.rya.prospector.utils.ProspectorConstants.EMPTY; -import static org.apache.rya.prospector.utils.ProspectorConstants.METADATA; -import static org.apache.rya.prospector.utils.ProspectorConstants.PERFORMANT; -import static org.apache.rya.prospector.utils.ProspectorConstants.PROSPECT_TIME; -import static org.apache.rya.prospector.utils.ProspectorUtils.connector; -import static org.apache.rya.prospector.utils.ProspectorUtils.getReverseIndexDateTime; -import static org.apache.rya.prospector.utils.ProspectorUtils.instance; -import static org.apache.rya.prospector.utils.ProspectorUtils.writeMutations; - -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; - import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.security.ColumnVisibility; @@ -46,6 +32,20 @@ import org.apache.rya.prospector.domain.IntermediateProspect; import org.apache.rya.prospector.utils.ProspectorUtils; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; + +import static org.apache.rya.prospector.utils.ProspectorConstants.DEFAULT_VIS; +import static org.apache.rya.prospector.utils.ProspectorConstants.EMPTY; +import static org.apache.rya.prospector.utils.ProspectorConstants.METADATA; +import static org.apache.rya.prospector.utils.ProspectorConstants.PERFORMANT; +import static org.apache.rya.prospector.utils.ProspectorConstants.PROSPECT_TIME; +import static org.apache.rya.prospector.utils.ProspectorUtils.connector; +import static org.apache.rya.prospector.utils.ProspectorUtils.getReverseIndexDateTime; +import static org.apache.rya.prospector.utils.ProspectorUtils.instance; +import static org.apache.rya.prospector.utils.ProspectorUtils.writeMutations; + /** * Configures and runs the Hadoop Map Reduce job that executes the Prospector's work. */ @@ -106,6 +106,8 @@ public int run(String[] args) throws Exception { final Mutation m = new Mutation(METADATA); m.put(PROSPECT_TIME, getReverseIndexDateTime(truncatedDate), new ColumnVisibility(DEFAULT_VIS), truncatedDate.getTime(), new Value(EMPTY)); writeMutations(connector(instance(conf), conf), outTable, Collections.singleton(m)); + } else { + System.err.println("Job was not successful!\n" + job.toString()); } return success; diff --git a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/mr/ProspectorMapper.java b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/mr/ProspectorMapper.java index ff4c30fc7..669b08f33 100644 --- a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/mr/ProspectorMapper.java +++ b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/mr/ProspectorMapper.java @@ -18,10 +18,6 @@ */ package org.apache.rya.prospector.mr; -import java.io.IOException; -import java.util.Collection; -import java.util.Map.Entry; - import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; import org.apache.hadoop.io.LongWritable; @@ -37,6 +33,10 @@ import org.apache.rya.prospector.plans.IndexWorkPlanManager; import org.apache.rya.prospector.plans.impl.ServicesBackedIndexWorkPlanManager; +import java.io.IOException; +import java.util.Collection; +import java.util.Map.Entry; + /** * Loads {@link RyaStatement}s from Accumulo and maps them into {@link IntermediateProspect}s * paired with count information during the Map portion of the Hadoop Map Reduce framework. @@ -69,6 +69,7 @@ public void map(Key row, Value data, Context context) throws IOException, Interr ); } catch (final TripleRowResolverException e) { // Do nothing. The row didn't contain a Rya Statement. + e.printStackTrace(); } if(ryaStatement != null) { diff --git a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/plans/IndexWorkPlan.java b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/plans/IndexWorkPlan.java index db9952345..ad6ad3008 100644 --- a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/plans/IndexWorkPlan.java +++ b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/plans/IndexWorkPlan.java @@ -18,12 +18,6 @@ */ package org.apache.rya.prospector.plans; -import java.io.IOException; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; - import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.hadoop.io.LongWritable; @@ -33,8 +27,15 @@ import org.apache.rya.prospector.domain.IntermediateProspect; import org.apache.rya.prospector.mr.ProspectorCombiner; import org.apache.rya.prospector.mr.ProspectorMapper; +import org.apache.rya.prospector.mr.ProspectorReducer; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; +import java.io.IOException; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; + /** * Contains the methods that perform each of the Map Reduce functions that result * in the final {@link IndexEntry} values as well as a way to query those values @@ -73,7 +74,7 @@ public interface IndexWorkPlan { public Collection> combine(IntermediateProspect prospect, Iterable counts); /** - * This method is invoked by {@link ProsectorReducer}. It is used to reduce + * This method is invoked by {@link ProspectorReducer}. It is used to reduce * the counts to their final states and write them to output via the * {@code context}.l * @@ -108,7 +109,7 @@ public interface IndexWorkPlan { * @param index - The data portion of the {@link IndexEntry}s that may be returned. * @param dataType - The data type of the {@link IndexEntry}s that may be returned. * @param auths - The authorizations used to search for the entries. - * @return The {@link IndexEntries} that match the provided values. + * @return The {@link IndexEntry}s that match the provided values. * @throws TableNotFoundException No table exists for {@code tableName}. */ public List query(Connector connector, String tableName, List prospectTimes, String type, String index, String dataType, String[] auths) throws TableNotFoundException; diff --git a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/plans/impl/CountPlan.java b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/plans/impl/CountPlan.java index f25b67d53..02a267fc7 100644 --- a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/plans/impl/CountPlan.java +++ b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/plans/impl/CountPlan.java @@ -18,19 +18,6 @@ */ package org.apache.rya.prospector.plans.impl; -import static org.apache.rya.prospector.utils.ProspectorConstants.COUNT; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - import org.apache.accumulo.core.client.BatchScanner; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.TableNotFoundException; @@ -44,9 +31,10 @@ import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.prospector.domain.IndexEntry; import org.apache.rya.prospector.domain.IntermediateProspect; import org.apache.rya.prospector.domain.TripleValueType; @@ -56,6 +44,19 @@ import org.eclipse.rdf4j.model.util.URIUtil; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import static org.apache.rya.prospector.utils.ProspectorConstants.COUNT; + /** * An implementation of {@link IndexWorkPlan} that counts the number of times * a piece of data appears within a Rya Instance for every {@link TripleValueType}. @@ -64,12 +65,12 @@ public class CountPlan implements IndexWorkPlan { @Override public Collection> map(final RyaStatement ryaStatement) { - final RyaIRI subject = ryaStatement.getSubject(); + final RyaResource subject = ryaStatement.getSubject(); final RyaIRI predicate = ryaStatement.getPredicate(); final String subjpred = ryaStatement.getSubject().getData() + DELIM + ryaStatement.getPredicate().getData(); final String predobj = ryaStatement.getPredicate().getData() + DELIM + ryaStatement.getObject().getData(); final String subjobj = ryaStatement.getSubject().getData() + DELIM + ryaStatement.getObject().getData(); - final RyaType object = ryaStatement.getObject(); + final RyaValue object = ryaStatement.getObject(); final int localIndex = URIUtil.getLocalNameIndex(subject.getData()); final String namespace = subject.getData().substring(0, localIndex - 1); final String visibility = new String(ryaStatement.getColumnVisibility(), StandardCharsets.UTF_8); diff --git a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java index 6e0609df3..56fcd6ef3 100644 --- a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java +++ b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java @@ -18,16 +18,6 @@ */ package org.apache.rya.prospector.service; -import static java.util.Objects.requireNonNull; -import static org.apache.rya.prospector.utils.ProspectorConstants.METADATA; -import static org.apache.rya.prospector.utils.ProspectorConstants.PROSPECT_TIME; - -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -46,6 +36,16 @@ import org.apache.rya.prospector.plans.impl.ServicesBackedIndexWorkPlanManager; import org.apache.rya.prospector.utils.ProspectorUtils; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import static java.util.Objects.requireNonNull; +import static org.apache.rya.prospector.utils.ProspectorConstants.METADATA; +import static org.apache.rya.prospector.utils.ProspectorConstants.PROSPECT_TIME; + /** * Provides access to the Prospect results that have been stored within a specific Accumulo table. */ @@ -150,7 +150,7 @@ public Long next() { * @param index - The data portion of the {@link IndexEntry}s that may be returned. * @param dataType - The data type of the {@link IndexEntry}s that may be returned. * @param auths - The authorizations used to search for the entries. - * @return The {@link IndexEntries} that match the provided values. + * @return The {@link IndexEntry}s that match the provided values. * @throws TableNotFoundException No table exists for {@code tableName}. */ public List query(List prospectTimes, String indexType, String type, List index, String dataType, String[] auths) throws TableNotFoundException { diff --git a/extras/rya.prospector/src/test/java/org/apache/rya/joinselect/mr/JoinSelectStatisticsTest.java b/extras/rya.prospector/src/test/java/org/apache/rya/joinselect/mr/JoinSelectStatisticsTest.java index 15cd0d426..79928773a 100644 --- a/extras/rya.prospector/src/test/java/org/apache/rya/joinselect/mr/JoinSelectStatisticsTest.java +++ b/extras/rya.prospector/src/test/java/org/apache/rya/joinselect/mr/JoinSelectStatisticsTest.java @@ -20,47 +20,6 @@ */ - -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.INPUTPATH; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.INSTANCE; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.OUTPUTPATH; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.PASSWORD; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.PROSPECTS_OUTPUTPATH; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.PROSPECTS_TABLE; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.SELECTIVITY_TABLE; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.SPO_OUTPUTPATH; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.SPO_TABLE; -import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.USERNAME; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; -import org.apache.rya.api.resolver.RyaTripleContext; -import org.apache.rya.api.resolver.triple.TripleRow; -import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinReducer; -import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinSelectAggregateMapper; -import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinSelectGroupComparator; -import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinSelectPartitioner; -import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinSelectSortComparator; -import org.apache.rya.joinselect.mr.JoinSelectProspectOutput.CardinalityMapper; -import org.apache.rya.joinselect.mr.JoinSelectSpoTableOutput.JoinSelectMapper; -import org.apache.rya.joinselect.mr.JoinSelectStatisticsSum.CardinalityIdentityCombiner; -import org.apache.rya.joinselect.mr.JoinSelectStatisticsSum.CardinalityIdentityMapper; -import org.apache.rya.joinselect.mr.JoinSelectStatisticsSum.CardinalityIdentityReducer; -import org.apache.rya.joinselect.mr.utils.CardList; -import org.apache.rya.joinselect.mr.utils.CompositeType; -import org.apache.rya.joinselect.mr.utils.JoinSelectStatsUtil; -import org.apache.rya.joinselect.mr.utils.TripleCard; -import org.apache.rya.joinselect.mr.utils.TripleEntry; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriter; @@ -90,10 +49,49 @@ import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.resolver.RyaTripleContext; +import org.apache.rya.api.resolver.triple.TripleRow; +import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinReducer; +import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinSelectAggregateMapper; +import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinSelectGroupComparator; +import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinSelectPartitioner; +import org.apache.rya.joinselect.mr.JoinSelectAggregate.JoinSelectSortComparator; +import org.apache.rya.joinselect.mr.JoinSelectProspectOutput.CardinalityMapper; +import org.apache.rya.joinselect.mr.JoinSelectSpoTableOutput.JoinSelectMapper; +import org.apache.rya.joinselect.mr.JoinSelectStatisticsSum.CardinalityIdentityCombiner; +import org.apache.rya.joinselect.mr.JoinSelectStatisticsSum.CardinalityIdentityMapper; +import org.apache.rya.joinselect.mr.JoinSelectStatisticsSum.CardinalityIdentityReducer; +import org.apache.rya.joinselect.mr.utils.CardList; +import org.apache.rya.joinselect.mr.utils.CompositeType; +import org.apache.rya.joinselect.mr.utils.JoinSelectStatsUtil; +import org.apache.rya.joinselect.mr.utils.TripleCard; +import org.apache.rya.joinselect.mr.utils.TripleEntry; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.INPUTPATH; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.INSTANCE; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.OUTPUTPATH; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.PASSWORD; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.PROSPECTS_OUTPUTPATH; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.PROSPECTS_TABLE; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.SELECTIVITY_TABLE; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.SPO_OUTPUTPATH; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.SPO_TABLE; +import static org.apache.rya.joinselect.mr.utils.JoinSelectConstants.USERNAME; + public class JoinSelectStatisticsTest { private static final String PREFIX = JoinSelectStatisticsTest.class.getSimpleName(); @@ -446,7 +444,7 @@ public void testMap1() throws Exception { - Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[]{""})); + Assert.assertEquals("MapReduce job failed!", 0, ToolRunner.run(new JoinSelectTestDriver(), new String[]{""})); Scanner scan = c.createScanner("rya_selectivity", new Authorizations()); scan.setRange(new Range()); @@ -557,7 +555,7 @@ public void testMap2() throws Exception { } bw_table2.close(); - Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[]{""})); + Assert.assertEquals("MapReduce job failed!", 0, ToolRunner.run(new JoinSelectTestDriver(), new String[]{""})); Scanner scan1 = c.createScanner("rya_selectivity" , new Authorizations()); scan1.setRange(Range.prefix("subject" +DELIM + iri + 1)); int i = 0; @@ -652,7 +650,7 @@ public void testMap3() throws Exception { - Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[]{""})); + Assert.assertEquals("MapReduce job failed!", 0, ToolRunner.run(new JoinSelectTestDriver(), new String[]{""})); Scanner scan = c.createScanner("rya_selectivity", new Authorizations()); scan.setRange(new Range()); @@ -762,7 +760,7 @@ public void testMap4() throws Exception { - Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[]{""})); + Assert.assertEquals("MapReduce job failed!", 0, ToolRunner.run(new JoinSelectTestDriver(), new String[]{""})); Scanner scan = c.createScanner("rya_selectivity", new Authorizations()); scan.setRange(new Range()); diff --git a/extras/rya.prospector/src/test/java/org/apache/rya/prospector/mr/ProspectorTest.java b/extras/rya.prospector/src/test/java/org/apache/rya/prospector/mr/ProspectorTest.java index 06e500514..3a2330bdc 100644 --- a/extras/rya.prospector/src/test/java/org/apache/rya/prospector/mr/ProspectorTest.java +++ b/extras/rya.prospector/src/test/java/org/apache/rya/prospector/mr/ProspectorTest.java @@ -18,13 +18,7 @@ */ package org.apache.rya.prospector.mr; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; - +import com.google.common.collect.Lists; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Instance; import org.apache.accumulo.core.client.TableNotFoundException; @@ -38,17 +32,23 @@ import org.apache.hadoop.util.ToolRunner; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.prospector.domain.IndexEntry; import org.apache.rya.prospector.domain.TripleValueType; import org.apache.rya.prospector.service.ProspectorService; import org.apache.rya.prospector.utils.ProspectorConstants; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; +import org.junit.Assert; import org.junit.Test; -import com.google.common.collect.Lists; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import static org.junit.Assert.assertEquals; /** * Tests that show when the {@link Prospector} job is run, it creates a table @@ -82,7 +82,7 @@ public void testCount() throws Exception { final String confFile = "stats_cluster_config.xml"; final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString()); final String[] args = { confPath.toString() }; - ToolRunner.run(new Prospector(), args); + Assert.assertEquals("MapReduce job failed!", 0, ToolRunner.run(new Prospector(), args)); ryaDAO.destroy(); // Interrogate the results of the Prospect job to ensure the correct results were created. diff --git a/extras/rya.prospector/src/test/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.java b/extras/rya.prospector/src/test/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.java index 21e3e8fed..6a79c2f1f 100644 --- a/extras/rya.prospector/src/test/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.java +++ b/extras/rya.prospector/src/test/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.java @@ -18,13 +18,6 @@ */ package org.apache.rya.prospector.service; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; - import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Instance; import org.apache.accumulo.core.client.TableNotFoundException; @@ -37,9 +30,9 @@ import org.apache.hadoop.util.ToolRunner; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.persist.RdfEvalStatsDAO; import org.apache.rya.api.persist.RdfEvalStatsDAO.CARDINALITY_OF; import org.apache.rya.prospector.mr.Prospector; @@ -47,8 +40,16 @@ import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; +import org.junit.Assert; import org.junit.Test; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import static org.junit.Assert.assertEquals; + /** * Tests that show when the {@link Prospector} job is run, the * {@link ProspectorServiceEvalStatsDAO} may be used to fetch cardinality @@ -82,7 +83,7 @@ public void testCount() throws Exception { final String confFile = "stats_cluster_config.xml"; final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString()); final String[] args = { confPath.toString() }; - ToolRunner.run(new Prospector(), args); + Assert.assertEquals("MapReduce job failed!", 0, ToolRunner.run(new Prospector(), args)); ryaDAO.destroy(); @@ -139,7 +140,7 @@ public void testNoAuthsCount() throws Exception { final String confFile = "stats_cluster_config.xml"; final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString()); final String[] args = { confPath.toString() }; - ToolRunner.run(new Prospector(), args); + assertEquals("MapReduce job failed!", 0, ToolRunner.run(new Prospector(), args)); ryaDAO.destroy(); diff --git a/extras/rya.reasoning/src/test/java/org/apache/rya/reasoning/mr/DuplicateEliminationTest.java b/extras/rya.reasoning/src/test/java/org/apache/rya/reasoning/mr/DuplicateEliminationTest.java index 30ced205d..30f1c6ade 100644 --- a/extras/rya.reasoning/src/test/java/org/apache/rya/reasoning/mr/DuplicateEliminationTest.java +++ b/extras/rya.reasoning/src/test/java/org/apache/rya/reasoning/mr/DuplicateEliminationTest.java @@ -19,10 +19,6 @@ * under the License. */ -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; import org.apache.hadoop.io.LongWritable; @@ -48,6 +44,10 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + @RunWith(PowerMockRunner.class) @PrepareForTest({DuplicateElimination.DuplicateEliminationReducer.class}) public class DuplicateEliminationTest { diff --git a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/GraphXEdgeInputFormat.java b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/GraphXEdgeInputFormat.java index 1670e2376..cef3fdaed 100644 --- a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/GraphXEdgeInputFormat.java +++ b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/GraphXEdgeInputFormat.java @@ -19,13 +19,6 @@ * under the License. */ -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.List; -import java.util.Map.Entry; - import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.client.mapreduce.AbstractInputFormat; @@ -39,12 +32,19 @@ import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RyaTripleContext; import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolverException; import org.apache.spark.graphx.Edge; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.Map.Entry; + /** * Subclass of {@link AbstractInputFormat} for reading * {@link RyaStatementWritable}s directly from a running Rya instance. @@ -185,10 +185,10 @@ protected void setupIterators(final TaskAttemptContext context, } - public static long getVertexId(final RyaType resource) throws IOException { + public static long getVertexId(final RyaValue resource) throws IOException { String iri = ""; if (resource != null) { - iri = resource.getData().toString(); + iri = resource.getData(); } try { // SHA-256 the string value and then generate a hashcode from diff --git a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaOutputFormat.java b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaOutputFormat.java index 6d964ead1..c4168981c 100644 --- a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaOutputFormat.java +++ b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaOutputFormat.java @@ -19,13 +19,6 @@ * under the License. */ -import java.io.Closeable; -import java.io.Flushable; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.concurrent.TimeUnit; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriterConfig; @@ -50,9 +43,10 @@ import org.apache.rya.accumulo.AccumuloRdfConstants; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaTripleContext; @@ -65,6 +59,13 @@ import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; +import java.io.Closeable; +import java.io.Flushable; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; + /** * {@link OutputFormat} that uses Rya, the {@link GeoIndexer}, the * {@link FreeTextIndexer}, the {@link TemporalIndexer}, and the @@ -485,10 +486,10 @@ public void write(final Writable key, final RyaStatementWritable value) throws I } private int statementSize(final RyaStatement ryaStatement) { - final RyaIRI subject = ryaStatement.getSubject(); + final RyaResource subject = ryaStatement.getSubject(); final RyaIRI predicate = ryaStatement.getPredicate(); - final RyaType object = ryaStatement.getObject(); - final RyaIRI context = ryaStatement.getContext(); + final RyaValue object = ryaStatement.getObject(); + final RyaResource context = ryaStatement.getContext(); int size = 3 + subject.getData().length() + predicate.getData().length() + object.getData().length(); if (!XMLSchema.ANYURI.equals(object.getDataType())) { size += 2 + object.getDataType().toString().length(); diff --git a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaTypeWritable.java b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaTypeWritable.java index 3050b61e7..7404cda8b 100644 --- a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaTypeWritable.java +++ b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/RyaTypeWritable.java @@ -19,16 +19,16 @@ * under the License. */ -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - import org.apache.hadoop.io.WritableComparable; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.utils.LiteralLanguageUtils; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + public class RyaTypeWritable implements WritableComparable{ private RyaType ryatype; @@ -80,8 +80,8 @@ public RyaType getRyaType() { } /** * Sets the contained RyaStatement. - * @param ryaStatement The statement to be represented by this - * RyaStatementWritable. + * @param ryatype The statement to be represented by this + * {@link RyaTypeWritable}. */ public void setRyaType(final RyaType ryatype) { this.ryatype = ryatype; @@ -95,8 +95,8 @@ public int compareTo(final RyaTypeWritable o) { /** * Tests for equality using the equals method of the enclosed RyaType. * @param o Object to compare with - * @return true if both objects are RyaTypeWritables containing equivalent - * RyaTypes. + * @return true if both objects are {@link RyaTypeWritable}s containing equivalent + * {@link RyaType}s. */ @Override public boolean equals(final Object o) { diff --git a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/tools/AccumuloRdfCountTool.java b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/tools/AccumuloRdfCountTool.java index 5c6829110..7a08767c6 100644 --- a/mapreduce/src/main/java/org/apache/rya/accumulo/mr/tools/AccumuloRdfCountTool.java +++ b/mapreduce/src/main/java/org/apache/rya/accumulo/mr/tools/AccumuloRdfCountTool.java @@ -19,10 +19,10 @@ * under the License. */ -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Date; - +import com.google.common.collect.Lists; +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; import org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Mutation; @@ -42,18 +42,17 @@ import org.apache.rya.accumulo.mr.AbstractAccumuloMRTool; import org.apache.rya.accumulo.mr.MRUtils; import org.apache.rya.api.RdfCloudTripleStoreConstants; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.resolver.RyaTripleContext; import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolverException; import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import com.google.common.collect.Lists; -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Date; /** * Count subject, predicate, object. Save in table @@ -152,7 +151,7 @@ protected void map(final Key key, final Value value, final Context context) thro final String subj = statement.getSubject().getData(); final String pred = statement.getPredicate().getData(); // byte[] objBytes = tripleFormat.getValueFormat().serialize(statement.getObject()); - final RyaIRI scontext = statement.getContext(); + final RyaResource scontext = statement.getContext(); final boolean includesContext = scontext != null; final String scontext_str = (includesContext) ? scontext.getData() : null; diff --git a/mapreduce/src/test/java/org/apache/rya/accumulo/mr/GraphXEdgeInputFormatTest.java b/mapreduce/src/test/java/org/apache/rya/accumulo/mr/GraphXEdgeInputFormatTest.java index 0c9c06c9c..79f92e870 100644 --- a/mapreduce/src/test/java/org/apache/rya/accumulo/mr/GraphXEdgeInputFormatTest.java +++ b/mapreduce/src/test/java/org/apache/rya/accumulo/mr/GraphXEdgeInputFormatTest.java @@ -17,14 +17,6 @@ * specific language governing permissions and limitations * under the License. */ -import java.util.ArrayList; -import java.util.List; - -import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.accumulo.AccumuloRyaDAO; -import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaIRI; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Instance; @@ -39,12 +31,20 @@ import org.apache.hadoop.mapreduce.TaskID; import org.apache.hadoop.mapreduce.task.JobContextImpl; import org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.accumulo.AccumuloRyaDAO; +import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaStatement; import org.apache.spark.graphx.Edge; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import java.util.ArrayList; +import java.util.List; + public class GraphXEdgeInputFormatTest { static String username = "root", table = "rya_spo"; @@ -129,6 +129,6 @@ public void testInputFormat() throws Exception { System.out.println(results.size()); System.out.println(results); - Assert.assertTrue(results.size() == 2); + Assert.assertEquals(2, results.size()); } } diff --git a/mapreduce/src/test/java/org/apache/rya/accumulo/mr/RyaInputFormatTest.java b/mapreduce/src/test/java/org/apache/rya/accumulo/mr/RyaInputFormatTest.java index 0c9763cc0..4d166cf2f 100644 --- a/mapreduce/src/test/java/org/apache/rya/accumulo/mr/RyaInputFormatTest.java +++ b/mapreduce/src/test/java/org/apache/rya/accumulo/mr/RyaInputFormatTest.java @@ -17,8 +17,6 @@ * specific language governing permissions and limitations * under the License. */ -import java.util.ArrayList; -import java.util.List; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Instance; @@ -39,14 +37,17 @@ import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.accumulo.mr.RyaInputFormat.RyaStatementRecordReader; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaStatement; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import java.util.ArrayList; +import java.util.List; + public class RyaInputFormatTest { static String username = "root", table = "rya_spo"; @@ -141,7 +142,7 @@ public void testInputFormat() throws Exception { System.out.println(value); } - Assert.assertTrue(results.size() == 2); + Assert.assertEquals(2, results.size()); Assert.assertTrue(results.contains(input)); } } diff --git a/mapreduce/src/test/java/org/apache/rya/accumulo/mr/RyaOutputFormatTest.java b/mapreduce/src/test/java/org/apache/rya/accumulo/mr/RyaOutputFormatTest.java index a2691d620..f694523a3 100644 --- a/mapreduce/src/test/java/org/apache/rya/accumulo/mr/RyaOutputFormatTest.java +++ b/mapreduce/src/test/java/org/apache/rya/accumulo/mr/RyaOutputFormatTest.java @@ -1,10 +1,5 @@ package org.apache.rya.accumulo.mr; -import java.io.IOException; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - import org.apache.accumulo.core.client.BatchWriterConfig; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.MultiTableBatchWriter; @@ -21,9 +16,10 @@ import org.apache.hadoop.mapreduce.RecordWriter; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.api.resolver.RyaToRdfConversions; import org.apache.rya.api.resolver.RyaTripleContext; @@ -45,6 +41,11 @@ import org.junit.Before; import org.junit.Test; +import java.io.IOException; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -225,7 +226,7 @@ public void testTemporalIndexing() throws Exception { RyaOutputFormat.setEntityEnabled(job, false); final ValueFactory vf = SimpleValueFactory.getInstance(); for (int i = 0; i < instants.length; i++) { - final RyaType time = RdfToRyaConversions.convertLiteral(vf.createLiteral(instants[i].toString())); + final RyaValue time = RdfToRyaConversions.convertLiteral(vf.createLiteral(instants[i].toString())); final RyaStatement input = RyaStatement.builder() .setSubject(new RyaIRI(GRAPH + ":s")) .setPredicate(new RyaIRI(GRAPH + ":p")) diff --git a/mapreduce/src/test/java/org/apache/rya/accumulo/mr/TestUtils.java b/mapreduce/src/test/java/org/apache/rya/accumulo/mr/TestUtils.java index 5e1670bfb..f21510c05 100644 --- a/mapreduce/src/test/java/org/apache/rya/accumulo/mr/TestUtils.java +++ b/mapreduce/src/test/java/org/apache/rya/accumulo/mr/TestUtils.java @@ -19,19 +19,17 @@ * under the License. */ -import java.io.IOException; -import java.util.Iterator; - import org.apache.accumulo.core.client.Connector; -import org.calrissian.mango.collect.CloseableIterable; -import org.junit.Assert; - import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.accumulo.query.AccumuloRyaQueryEngine; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.persist.RyaDAOException; -import org.apache.rya.api.persist.query.RyaQuery; +import org.apache.rya.api.persist.utils.RyaDAOHelper; +import org.eclipse.rdf4j.common.iteration.CloseableIteration; +import org.junit.Assert; + +import java.io.IOException; public class TestUtils { public static void verify(Connector connector, AccumuloRdfConfiguration conf, RyaStatement... ryaStatements) @@ -50,9 +48,10 @@ public static void verify(Connector connector, AccumuloRdfConfiguration conf, Ry public static RyaStatement verify(RyaStatement ryaStatement, AccumuloRyaQueryEngine queryEngine) throws RyaDAOException, IOException { //check osp - CloseableIterable statements = - queryEngine.query(RyaQuery.builder(new RyaStatement(null, null, ryaStatement.getObject())) - .build()); + CloseableIteration statements = + RyaDAOHelper.query(queryEngine, + new RyaStatement(null, null, ryaStatement.getObject()), + queryEngine.getConf()); try { verifyFirstStatement(ryaStatement, statements); } finally { @@ -60,9 +59,9 @@ public static RyaStatement verify(RyaStatement ryaStatement, AccumuloRyaQueryEng } //check po - statements = queryEngine.query(RyaQuery.builder( - new RyaStatement(null, ryaStatement.getPredicate(), - ryaStatement.getObject())).build()); + statements = RyaDAOHelper.query(queryEngine, + new RyaStatement(null, ryaStatement.getPredicate(), + ryaStatement.getObject()), queryEngine.getConf()); try { verifyFirstStatement(ryaStatement, statements); } finally { @@ -71,10 +70,10 @@ public static RyaStatement verify(RyaStatement ryaStatement, AccumuloRyaQueryEng //check spo RyaStatement result; - statements = queryEngine.query(RyaQuery.builder( - new RyaStatement(ryaStatement.getSubject(), + statements = RyaDAOHelper.query(queryEngine, + new RyaStatement(ryaStatement.getSubject(), ryaStatement.getPredicate(), - ryaStatement.getObject())).build()); + ryaStatement.getObject()), queryEngine.getConf()); try { result = verifyFirstStatement(ryaStatement, statements); } finally { @@ -84,8 +83,7 @@ public static RyaStatement verify(RyaStatement ryaStatement, AccumuloRyaQueryEng } private static RyaStatement verifyFirstStatement( - RyaStatement ryaStatement, CloseableIterable statements) { - final Iterator iterator = statements.iterator(); + RyaStatement ryaStatement, CloseableIteration iterator) { Assert.assertTrue(iterator.hasNext()); final RyaStatement first = iterator.next(); Assert.assertEquals(ryaStatement.getSubject(), first.getSubject()); diff --git a/pig/accumulo.pig/src/main/java/org/apache/rya/accumulo/pig/StatementPatternStorage.java b/pig/accumulo.pig/src/main/java/org/apache/rya/accumulo/pig/StatementPatternStorage.java index 7c87de705..9af5cc700 100644 --- a/pig/accumulo.pig/src/main/java/org/apache/rya/accumulo/pig/StatementPatternStorage.java +++ b/pig/accumulo.pig/src/main/java/org/apache/rya/accumulo/pig/StatementPatternStorage.java @@ -19,12 +19,8 @@ * under the License. */ -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteStreams; import org.apache.accumulo.core.client.ZooKeeperInstance; import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.accumulo.core.data.Key; @@ -39,9 +35,10 @@ import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.query.strategy.ByteRange; import org.apache.rya.api.query.strategy.TriplePatternStrategy; @@ -62,8 +59,11 @@ import org.eclipse.rdf4j.query.parser.QueryParser; import org.eclipse.rdf4j.query.parser.sparql.SPARQLParser; -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.Map; +import java.util.Set; /** */ @@ -190,17 +190,16 @@ public void meet(StatementPattern node) throws IOException { } protected Map.Entry createRange(Value s_v, Value p_v, Value o_v) throws IOException { - RyaIRI subject_rya = RdfToRyaConversions.convertResource((Resource) s_v); + RyaResource subject_rya = RdfToRyaConversions.convertResource((Resource) s_v); RyaIRI predicate_rya = RdfToRyaConversions.convertIRI((IRI) p_v); - RyaType object_rya = RdfToRyaConversions.convertValue(o_v); + RyaValue object_rya = RdfToRyaConversions.convertValue(o_v); TriplePatternStrategy strategy = ryaContext.retrieveStrategy(subject_rya, predicate_rya, object_rya, null); if (strategy == null) { - return new RdfCloudTripleStoreUtils.CustomEntry(TABLE_LAYOUT.SPO, new Range()); + return new RdfCloudTripleStoreUtils.CustomEntry<>(TABLE_LAYOUT.SPO, new Range()); } - Map.Entry entry = strategy.defineRange(subject_rya, predicate_rya, object_rya, null, null); - ByteRange byteRange = entry.getValue(); - return new RdfCloudTripleStoreUtils.CustomEntry( - entry.getKey(), new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd())) + ByteRange byteRange = strategy.defineRange(subject_rya, predicate_rya, object_rya, null, null); + return new RdfCloudTripleStoreUtils.CustomEntry<>( + strategy.getLayout(), new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd())) ); } diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java index 56394883a..1619923a3 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java @@ -18,23 +18,12 @@ */ package org.apache.rya.rdftriplestore; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.lang.reflect.Constructor; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.NoSuchElementException; - import org.apache.hadoop.conf.Configurable; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConstants; -import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; +import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.RdfEvalStatsDAO; import org.apache.rya.api.persist.RyaDAO; @@ -106,6 +95,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.reflect.Constructor; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NoSuchElementException; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + public class RdfCloudTripleStoreConnection extends AbstractSailConnection { private static final Logger logger = LoggerFactory.getLogger(RdfCloudTripleStoreConnection.class); @@ -189,7 +190,7 @@ protected void addStatementInternal(final Resource subject, final IRI predicate, @Override protected void clearInternal(final Resource... aresource) throws SailException { try { - final RyaIRI[] graphs = new RyaIRI[aresource.length]; + final RyaResource[] graphs = new RyaIRI[aresource.length]; for (int i = 0 ; i < graphs.length ; i++){ graphs[i] = RdfToRyaConversions.convertResource(aresource[i]); } @@ -578,8 +579,7 @@ protected void removeStatementsInternal(final Resource subject, final IRI predic final RyaStatement statement = new RyaStatement( RdfToRyaConversions.convertResource(subject), RdfToRyaConversions.convertIRI(predicate), - RdfToRyaConversions.convertValue(object), - null); + RdfToRyaConversions.convertValue(object)); ryaDAO.delete(statement, conf); } @@ -630,15 +630,12 @@ public StoreTripleSource(final C conf, final RyaDAO ryaDAO) { public CloseableIteration getStatements( final Resource subject, final IRI predicate, final Value object, final Resource... contexts) throws QueryEvaluationException { - return RyaDAOHelper.query(ryaDAO, subject, predicate, object, conf, contexts); + return RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), subject, predicate, object, conf, contexts); } public CloseableIteration, QueryEvaluationException> getStatements( - final Collection> statements, - final Resource... contexts) throws QueryEvaluationException { - - return RyaDAOHelper.query(ryaDAO, statements, conf); - } + final Collection> statements) throws QueryEvaluationException { + return RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), statements, conf); } @Override public ValueFactory getValueFactory() { diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/evaluation/ParallelEvaluationStrategyImpl.java b/sail/src/main/java/org/apache/rya/rdftriplestore/evaluation/ParallelEvaluationStrategyImpl.java index 47e5269ba..bd543c12e 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/evaluation/ParallelEvaluationStrategyImpl.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/evaluation/ParallelEvaluationStrategyImpl.java @@ -31,7 +31,7 @@ import org.apache.log4j.Logger; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.RdfCloudTripleStoreUtils; -import org.apache.rya.api.utils.NullableStatementImpl; +import org.apache.rya.api.utils.WildcardStatement; import org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection; import org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection.StoreTripleSource; import org.apache.rya.rdftriplestore.inference.InferenceEngine; @@ -199,8 +199,8 @@ public CloseableIteration evaluate(final S (predValue != null && !(predValue instanceof IRI))) { continue; } - stmts.add(new RdfCloudTripleStoreUtils.CustomEntry( - new NullableStatementImpl((Resource) subjValue, (IRI) predValue, objValue, contxtValue), binding)); + stmts.add(new RdfCloudTripleStoreUtils.CustomEntry<>( + new WildcardStatement((Resource) subjValue, (IRI) predValue, objValue, contxtValue), binding)); } if (stmts.size() == 0) { return new EmptyIteration(); diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitor.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitor.java index d609ac63c..02be86795 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitor.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitor.java @@ -18,20 +18,20 @@ * under the License. */ -import java.util.Map; -import java.util.Set; -import java.util.UUID; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.OWL; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.Var; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + /** * Expands the query tree to account for any universal class expressions (property restrictions * using owl:allValuesFrom) in the ontology known to the {@link InferenceEngine}. @@ -100,8 +100,8 @@ protected void meetSP(StatementPattern node) throws Exception { new Var(OWL.ONPROPERTY.stringValue(), OWL.ONPROPERTY), avfPredVar); for (Resource avfRestrictionType : relevantAvfRestrictions.keySet()) { for (IRI avfProperty : relevantAvfRestrictions.get(avfRestrictionType)) { - avfPropertyTypes.statements.add(new NullableStatementImpl(avfRestrictionType, - OWL.ONPROPERTY, avfProperty)); + avfPropertyTypes.statements.add(SimpleValueFactory.getInstance().createStatement( + avfRestrictionType, OWL.ONPROPERTY, avfProperty)); } } final InferJoin avfInferenceQuery = new InferJoin(avfPropertyTypes, avfPattern); diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitor.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitor.java index b13398e35..7963b11e6 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitor.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitor.java @@ -18,19 +18,19 @@ * under the License. */ -import java.util.Set; -import java.util.UUID; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.RDFS; import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.TupleExpr; import org.eclipse.rdf4j.query.algebra.Var; +import java.util.Set; +import java.util.UUID; + /** * Expands the query tree to account for any relevant domain and range information known to the * {@link InferenceEngine}. @@ -87,7 +87,7 @@ protected void meetSP(StatementPattern node) throws Exception { // Enumerate predicates having this type as domain FixedStatementPattern domainFSP = new FixedStatementPattern(domainPredVar, domainVar, objVar); for (IRI property : domainProperties) { - domainFSP.statements.add(new NullableStatementImpl(property, RDFS.DOMAIN, inferredType)); + domainFSP.statements.add(SimpleValueFactory.getInstance().createStatement(property, RDFS.DOMAIN, inferredType)); } // For each such predicate, any triple implies the type currentNode = new InferUnion(currentNode, new InferJoin(domainFSP, domainSP)); @@ -103,7 +103,7 @@ protected void meetSP(StatementPattern node) throws Exception { // Enumerate predicates having this type as range FixedStatementPattern rangeFSP = new FixedStatementPattern(rangePredVar, rangeVar, objVar); for (IRI property : rangeProperties) { - rangeFSP.statements.add(new NullableStatementImpl(property, RDFS.RANGE, inferredType)); + rangeFSP.statements.add(SimpleValueFactory.getInstance().createStatement(property, RDFS.RANGE, inferredType)); } // For each such predicate, any triple <_:any predicate subjVar> implies the type currentNode = new InferUnion(currentNode, new InferJoin(rangeFSP, rangeSP)); diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/HasValueVisitor.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/HasValueVisitor.java index 974f4dffa..3b0d7c395 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/HasValueVisitor.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/HasValueVisitor.java @@ -18,22 +18,22 @@ * under the License. */ -import java.util.Map; -import java.util.Set; -import java.util.UUID; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.OWL; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.TupleExpr; import org.eclipse.rdf4j.query.algebra.Var; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + /** * Expands the query tree to account for any relevant has-value class * expressions in the ontology known to the {@link InferenceEngine}. @@ -109,7 +109,7 @@ protected void meetSP(StatementPattern node) throws Exception { final TupleExpr valueSP = new DoNotExpandSP(subjVar, propVar, valueVar); final FixedStatementPattern relevantValues = new FixedStatementPattern(objVar, propVar, valueVar); for (Value value : sufficientValues.get(property)) { - relevantValues.statements.add(new NullableStatementImpl(objType, property, value)); + relevantValues.statements.add(SimpleValueFactory.getInstance().createStatement(objType, property, value)); } currentNode = new InferUnion(currentNode, new InferJoin(relevantValues, valueSP)); } @@ -130,7 +130,7 @@ protected void meetSP(StatementPattern node) throws Exception { for (Resource type : impliedValues.keySet()) { // { ?var rdf:type :type } implies { ?var :property :val } for certain (:type, :val) pairs for (Value impliedValue : impliedValues.get(type)) { - typeToValue.statements.add(new NullableStatementImpl(type, OWL.HASVALUE, impliedValue)); + typeToValue.statements.add(SimpleValueFactory.getInstance().createStatement(type, OWL.HASVALUE, impliedValue)); } } node.replaceWith(new InferUnion(new InferJoin(typeToValue, typeSP), directValueSP)); diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java index 9da1c4a2b..4348473ca 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java @@ -18,28 +18,7 @@ */ package org.apache.rya.rdftriplestore.inference; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.Stack; -import java.util.Timer; -import java.util.TimerTask; -import java.util.TreeMap; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.locks.ReentrantLock; - +import com.google.common.collect.Sets; import org.apache.commons.lang3.mutable.MutableObject; import org.apache.log4j.Logger; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; @@ -66,7 +45,27 @@ import org.eclipse.rdf4j.rio.RDFHandlerException; import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler; -import com.google.common.collect.Sets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Stack; +import java.util.Timer; +import java.util.TimerTask; +import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.ReentrantLock; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; /** * Will pull down inference relationships from dao every x seconds.
    @@ -102,7 +101,7 @@ public class InferenceEngine { private final Map> hasSelfByProperty = new ConcurrentHashMap<>(); private final Map> hasSelfByType = new ConcurrentHashMap<>(); - private RyaDAO ryaDAO; + private RyaDAO ryaDAO; private RdfCloudTripleStoreConfiguration conf; private RyaDaoQueryWrapper ryaDaoQueryWrapper; private final AtomicBoolean isInitialized = new AtomicBoolean(); @@ -205,7 +204,7 @@ public void refreshGraph() throws InferenceEngineException { * to have few members, such as ontology vocabulary terms, as instances will be collected in * memory. */ - private Set fetchInstances(final IRI type) throws QueryEvaluationException { + private Set fetchInstances(final Value type) throws QueryEvaluationException { final Set instances = new HashSet<>(); ryaDaoQueryWrapper.queryAll(null, RDF.TYPE, type, new AbstractRDFHandler() { @Override @@ -231,7 +230,7 @@ public void handleStatement(final Statement st) throws RDFHandlerException { */ private void addPredicateEdges(final IRI predicate, final Direction dir, final Graph graph, final String edgeName) throws QueryEvaluationException { - final CloseableIteration iter = RyaDAOHelper.query(ryaDAO, + final CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), null, predicate, null, conf); try { while (iter.hasNext()) { @@ -262,7 +261,7 @@ private void addPredicateEdges(final IRI predicate, final Direction dir, final G * @throws QueryEvaluationException */ private void addUnions(final Graph graph) throws QueryEvaluationException { - final CloseableIteration iter = RyaDAOHelper.query(ryaDAO, null, OWL.UNIONOF, null, conf); + final CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), null, OWL.UNIONOF, null, conf); try { while (iter.hasNext()) { final Statement st = iter.next(); @@ -271,7 +270,7 @@ private void addUnions(final Graph graph) throws QueryEvaluationException { Value current = st.getObject(); while (current instanceof Resource && !RDF.NIL.equals(current)) { final Resource listNode = (Resource) current; - CloseableIteration listIter = RyaDAOHelper.query(ryaDAO, + CloseableIteration listIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), listNode, RDF.FIRST, null, conf); try { if (listIter.hasNext()) { @@ -285,7 +284,7 @@ private void addUnions(final Graph graph) throws QueryEvaluationException { } finally { listIter.close(); } - listIter = RyaDAOHelper.query(ryaDAO, listNode, RDF.REST, null, conf); + listIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), listNode, RDF.REST, null, conf); try { if (listIter.hasNext()) { current = listIter.next().getObject(); @@ -306,7 +305,7 @@ private void addUnions(final Graph graph) throws QueryEvaluationException { } private void refreshInverseOf() throws QueryEvaluationException { - final CloseableIteration iter = RyaDAOHelper.query(ryaDAO, null, OWL.INVERSEOF, null, conf); + final CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), null, OWL.INVERSEOF, null, conf); final Map invProp = new HashMap<>(); try { while (iter.hasNext()) { @@ -326,65 +325,64 @@ private void refreshInverseOf() throws QueryEvaluationException { } private void refreshPropertyChainPropertyToChain() throws QueryEvaluationException { - CloseableIteration iter = RyaDAOHelper.query(ryaDAO, null, - VF.createIRI("http://www.w3.org/2002/07/owl#propertyChainAxiom"), - null, conf); + CloseableIteration propertyChainIter = RyaDAOHelper.queryRdf4j( + ryaDAO.getQueryEngine(), null, VF.createIRI("http://www.w3.org/2002/07/owl#propertyChainAxiom"), null, conf); final Map propertyChainPropertiesToBNodes = new HashMap<>(); final Map> tempPropertyChainPropertyToChain = new HashMap<>(); try { - while (iter.hasNext()){ - final Statement st = iter.next(); + while (propertyChainIter.hasNext()){ + final Statement st = propertyChainIter.next(); propertyChainPropertiesToBNodes.put((IRI)st.getSubject(), (IRI)st.getObject()); } } finally { - if (iter != null) { - iter.close(); + if (propertyChainIter != null) { + propertyChainIter.close(); } } // now for each property chain bNode, get the indexed list of properties associated with that chain for (final IRI propertyChainProperty : propertyChainPropertiesToBNodes.keySet()){ final IRI bNode = propertyChainPropertiesToBNodes.get(propertyChainProperty); // query for the list of indexed properties - iter = RyaDAOHelper.query(ryaDAO, bNode, VF.createIRI("http://www.w3.org/2000/10/swap/list#index"), - null, conf); + propertyChainIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), + bNode, VF.createIRI("http://www.w3.org/2000/10/swap/list#index"), null, conf); final TreeMap orderedProperties = new TreeMap<>(); // TODO refactor this. Wish I could execute sparql try { - while (iter.hasNext()){ - final Statement st = iter.next(); + while (propertyChainIter.hasNext()){ + final Statement st = propertyChainIter.next(); final String indexedElement = st.getObject().stringValue(); log.info(indexedElement); - CloseableIteration iter2 = RyaDAOHelper.query(ryaDAO, VF.createIRI(st.getObject().stringValue()), RDF.FIRST, - null, conf); + CloseableIteration indexedPropertiesIter = RyaDAOHelper.queryRdf4j( + ryaDAO.getQueryEngine(), VF.createIRI(st.getObject().stringValue()), RDF.FIRST, null, conf); String integerValue = ""; Value anonPropNode = null; Value propIRI = null; - if (iter2 != null){ - while (iter2.hasNext()){ - final Statement iter2Statement = iter2.next(); - integerValue = iter2Statement.getObject().stringValue(); + if (indexedPropertiesIter != null){ + while (indexedPropertiesIter.hasNext()){ + final Statement property = indexedPropertiesIter.next(); + integerValue = property.getObject().stringValue(); break; } - iter2.close(); + indexedPropertiesIter.close(); } - iter2 = RyaDAOHelper.query(ryaDAO, VF.createIRI(st.getObject().stringValue()), RDF.REST, - null, conf); - if (iter2 != null){ - while (iter2.hasNext()){ - final Statement iter2Statement = iter2.next(); - anonPropNode = iter2Statement.getObject(); + indexedPropertiesIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), + VF.createIRI(st.getObject().stringValue()), RDF.REST, null, conf); + if (indexedPropertiesIter != null){ + while (indexedPropertiesIter.hasNext()){ + final Statement property = indexedPropertiesIter.next(); + anonPropNode = property.getObject(); break; } - iter2.close(); + indexedPropertiesIter.close(); if (anonPropNode != null){ - iter2 = RyaDAOHelper.query(ryaDAO, VF.createIRI(anonPropNode.stringValue()), RDF.FIRST, - null, conf); - while (iter2.hasNext()){ - final Statement iter2Statement = iter2.next(); - propIRI = iter2Statement.getObject(); + indexedPropertiesIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), + VF.createIRI(anonPropNode.stringValue()), RDF.FIRST, null, conf); + while (indexedPropertiesIter.hasNext()){ + final Statement property = indexedPropertiesIter.next(); + propIRI = property.getObject(); break; } - iter2.close(); + indexedPropertiesIter.close(); } } if (!integerValue.isEmpty() && propIRI!=null) { @@ -399,8 +397,8 @@ private void refreshPropertyChainPropertyToChain() throws QueryEvaluationExcepti } } } finally{ - if (iter != null){ - iter.close(); + if (propertyChainIter != null){ + propertyChainIter.close(); } } final List properties = new ArrayList<>(); @@ -416,41 +414,41 @@ private void refreshPropertyChainPropertyToChain() throws QueryEvaluationExcepti // if we didn't get a chain, try to get it through following the collection if ((existingChain == null) || existingChain.isEmpty()) { - CloseableIteration iter2 = RyaDAOHelper.query(ryaDAO, propertyChainPropertiesToBNodes.get(propertyChainProperty), RDF.FIRST, - null, conf); + CloseableIteration bNodesPropertiesIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), + propertyChainPropertiesToBNodes.get(propertyChainProperty), RDF.FIRST, null, conf); final List properties = new ArrayList<>(); IRI previousBNode = propertyChainPropertiesToBNodes.get(propertyChainProperty); - if (iter2.hasNext()) { - Statement iter2Statement = iter2.next(); - Value currentPropValue = iter2Statement.getObject(); + if (bNodesPropertiesIter.hasNext()) { + Statement property = bNodesPropertiesIter.next(); + Value currentPropValue = property.getObject(); while ((currentPropValue != null) && (!currentPropValue.stringValue().equalsIgnoreCase(RDF.NIL.stringValue()))){ if (currentPropValue instanceof IRI){ - iter2 = RyaDAOHelper.query(ryaDAO, VF.createIRI(currentPropValue.stringValue()), RDF.FIRST, - null, conf); - if (iter2.hasNext()){ - iter2Statement = iter2.next(); - if (iter2Statement.getObject() instanceof IRI){ - properties.add((IRI)iter2Statement.getObject()); + bNodesPropertiesIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), + VF.createIRI(currentPropValue.stringValue()), RDF.FIRST, null, conf); + if (bNodesPropertiesIter.hasNext()){ + property = bNodesPropertiesIter.next(); + if (property.getObject() instanceof IRI){ + properties.add((IRI)property.getObject()); } } // otherwise see if there is an inverse declaration else { - iter2 = RyaDAOHelper.query(ryaDAO, VF.createIRI(currentPropValue.stringValue()), OWL.INVERSEOF, - null, conf); - if (iter2.hasNext()){ - iter2Statement = iter2.next(); - if (iter2Statement.getObject() instanceof IRI){ - properties.add(new InverseIRI((IRI)iter2Statement.getObject())); + bNodesPropertiesIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), + VF.createIRI(currentPropValue.stringValue()), OWL.INVERSEOF, null, conf); + if (bNodesPropertiesIter.hasNext()){ + property = bNodesPropertiesIter.next(); + if (property.getObject() instanceof IRI){ + properties.add(new InverseIRI((IRI)property.getObject())); } } } // get the next prop pointer - iter2 = RyaDAOHelper.query(ryaDAO, previousBNode, RDF.REST, - null, conf); - if (iter2.hasNext()){ - iter2Statement = iter2.next(); + bNodesPropertiesIter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), + previousBNode, RDF.REST, null, conf); + if (bNodesPropertiesIter.hasNext()){ + property = bNodesPropertiesIter.next(); previousBNode = (IRI)currentPropValue; - currentPropValue = iter2Statement.getObject(); + currentPropValue = property.getObject(); } else { currentPropValue = null; @@ -491,7 +489,7 @@ private void refreshDomainRange() throws QueryEvaluationException { final Map> domainByTypePartial = new ConcurrentHashMap<>(); final Map> rangeByTypePartial = new ConcurrentHashMap<>(); // First, populate domain and range based on direct domain/range triples. - CloseableIteration iter = RyaDAOHelper.query(ryaDAO, null, RDFS.DOMAIN, null, conf); + CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), null, RDFS.DOMAIN, null, conf); try { while (iter.hasNext()) { final Statement st = iter.next(); @@ -509,7 +507,7 @@ private void refreshDomainRange() throws QueryEvaluationException { iter.close(); } } - iter = RyaDAOHelper.query(ryaDAO, null, RDFS.RANGE, null, conf); + iter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), null, RDFS.RANGE, null, conf); try { while (iter.hasNext()) { final Statement st = iter.next(); @@ -638,7 +636,7 @@ private void refreshDomainRange() throws QueryEvaluationException { private void refreshPropertyRestrictions() throws QueryEvaluationException { // Get a set of all property restrictions of any type - final CloseableIteration iter = RyaDAOHelper.query(ryaDAO, null, OWL.ONPROPERTY, null, conf); + final CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), null, OWL.ONPROPERTY, null, conf); final Map restrictions = new HashMap<>(); try { while (iter.hasNext()) { @@ -660,7 +658,7 @@ private void refreshPropertyRestrictions() throws QueryEvaluationException { private void refreshHasValueRestrictions(final Map restrictions) throws QueryEvaluationException { hasValueByType.clear(); hasValueByProperty.clear(); - final CloseableIteration iter = RyaDAOHelper.query(ryaDAO, null, OWL.HASVALUE, null, conf); + final CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), null, OWL.HASVALUE, null, conf); try { while (iter.hasNext()) { final Statement st = iter.next(); @@ -743,7 +741,7 @@ private void refreshHasSelfRestrictions(final Map restrictions) t for(final Resource type : restrictions.keySet()) { final IRI property = restrictions.get(type); - final CloseableIteration iter = RyaDAOHelper.query(ryaDAO, type, HAS_SELF, null, conf); + final CloseableIteration iter = RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), type, HAS_SELF, null, conf); try { if (iter.hasNext()) { Set typeSet = hasSelfByType.get(type); @@ -991,7 +989,7 @@ public Set getHasSelfImplyingProperty(final IRI property) { * @throws QueryEvaluationException */ private List getList(final IRI firstItem) throws QueryEvaluationException { - IRI head = firstItem; + Resource head = firstItem; final List list = new ArrayList<>(); // Go through and find all bnodes that are part of the defined list. while (!RDF.NIL.equals(head)) { @@ -1255,7 +1253,7 @@ public Set findSameAs(final Resource value, final Resource... contxts) } public CloseableIteration queryDao(final Resource subject, final IRI predicate, final Value object, final Resource... contexts) throws QueryEvaluationException { - return RyaDAOHelper.query(ryaDAO, subject, predicate, object, conf, contexts); + return RyaDAOHelper.queryRdf4j(ryaDAO.getQueryEngine(), subject, predicate, object, conf, contexts); } /** @@ -1341,7 +1339,7 @@ public synchronized RyaDAO getRyaDAO() { return ryaDAO; } - public synchronized void setRyaDAO(final RyaDAO ryaDAO) { + public synchronized void setRyaDAO(final RyaDAO ryaDAO) { this.ryaDAO = ryaDAO; ryaDaoQueryWrapper = new RyaDaoQueryWrapper(ryaDAO); } diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SameAsVisitor.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SameAsVisitor.java index a71aaaa02..7a03dd126 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SameAsVisitor.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SameAsVisitor.java @@ -19,12 +19,8 @@ * under the License. */ -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; +import org.apache.rya.api.utils.WildcardStatement; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.apache.rya.rdftriplestore.utils.TransitivePropertySP; import org.eclipse.rdf4j.model.IRI; @@ -37,6 +33,10 @@ import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.Var; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + /** * All predicates are changed * Class SubPropertyOfVisitor @@ -134,7 +134,7 @@ else if (subjVar.getValue() == null) { StatementPattern origDummyStatement = new DoNotExpandSP(origStatement.getSubjectVar(), origStatement.getPredicateVar(), dummyVar, cntxtVar); FixedStatementPattern fsp = new FixedStatementPattern(dummyVar, new Var("c-" + s, OWL.SAMEAS), objVar, cntxtVar); for (Resource sameAs : objURIs){ - NullableStatementImpl newStatement = new NullableStatementImpl(sameAs, OWL.SAMEAS, + WildcardStatement newStatement = new WildcardStatement(sameAs, OWL.SAMEAS, objVar.getValue(), getVarValue(cntxtVar)); fsp.statements.add(newStatement); } @@ -168,7 +168,7 @@ private InferJoin getReplaceJoin(Set uris, boolean subSubj, Var subjVa } FixedStatementPattern fsp = new FixedStatementPattern(dummyVar, new Var("c-" + s, OWL.SAMEAS), subVar, cntxtVar); for (Resource sameAs : uris){ - NullableStatementImpl newStatement = new NullableStatementImpl(sameAs, OWL.SAMEAS, + WildcardStatement newStatement = new WildcardStatement(sameAs, OWL.SAMEAS, subVar.getValue(), getVarValue(cntxtVar)); fsp.statements.add(newStatement); } diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SomeValuesFromVisitor.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SomeValuesFromVisitor.java index bd03f54a8..82d9d9db5 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SomeValuesFromVisitor.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SomeValuesFromVisitor.java @@ -18,20 +18,20 @@ * under the License. */ -import java.util.Map; -import java.util.Set; -import java.util.UUID; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.OWL; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.Var; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + /** * Expands the query tree to account for any existential class expressions (property restrictions * using owl:someValuesFrom) in the ontology known to the {@link InferenceEngine}. @@ -98,8 +98,8 @@ protected void meetSP(StatementPattern node) throws Exception { new Var(OWL.SOMEVALUESFROM.stringValue(), OWL.SOMEVALUESFROM), valueTypeVar); for (Resource svfValueType : relevantSvfRestrictions.keySet()) { for (IRI svfProperty : relevantSvfRestrictions.get(svfValueType)) { - svfPropertyTypes.statements.add(new NullableStatementImpl(svfProperty, - OWL.SOMEVALUESFROM, svfValueType)); + svfPropertyTypes.statements.add(SimpleValueFactory.getInstance().createStatement( + svfProperty, OWL.SOMEVALUESFROM, svfValueType)); } } final InferJoin svfInferenceQuery = new InferJoin(svfPropertyTypes, svfPattern); diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SubClassOfVisitor.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SubClassOfVisitor.java index 31b779234..d5afacf50 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SubClassOfVisitor.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SubClassOfVisitor.java @@ -18,18 +18,18 @@ */ package org.apache.rya.rdftriplestore.inference; -import java.util.Collection; -import java.util.UUID; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.RDFS; import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.Var; +import java.util.Collection; +import java.util.UUID; + /** * Class SubClassOfVisitor * Date: Mar 29, 2011 @@ -69,7 +69,7 @@ protected void meetSP(final StatementPattern node) throws Exception { final FixedStatementPattern fsp = new FixedStatementPattern(typeVar, new Var("c-" + s, RDFS.SUBCLASSOF), objVar, conVar); parents.add(subclassof_iri); for (final IRI iri : parents) { - fsp.statements.add(new NullableStatementImpl(iri, RDFS.SUBCLASSOF, subclassof_iri)); + fsp.statements.add(SimpleValueFactory.getInstance().createStatement(iri, RDFS.SUBCLASSOF, subclassof_iri)); } final StatementPattern rdfType = new DoNotExpandSP(sp.getSubjectVar(), sp.getPredicateVar(), typeVar, conVar); diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SubPropertyOfVisitor.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SubPropertyOfVisitor.java index e49e6056d..2a6308853 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SubPropertyOfVisitor.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/SubPropertyOfVisitor.java @@ -18,19 +18,19 @@ */ package org.apache.rya.rdftriplestore.inference; -import java.util.Set; -import java.util.UUID; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.RDFS; import org.eclipse.rdf4j.model.vocabulary.SESAME; import org.eclipse.rdf4j.query.algebra.StatementPattern; import org.eclipse.rdf4j.query.algebra.Var; +import java.util.Set; +import java.util.UUID; + /** * All predicates are changed * Class SubPropertyOfVisitor @@ -104,7 +104,7 @@ protected void meetSP(final StatementPattern node) throws Exception { //add self parents.add(subprop_iri); for (final IRI u : parents) { - fsp.statements.add(new NullableStatementImpl(u, RDFS.SUBPROPERTYOF, subprop_iri)); + fsp.statements.add(SimpleValueFactory.getInstance().createStatement(u, RDFS.SUBPROPERTYOF, subprop_iri)); } final StatementPattern rdfType = new DoNotExpandSP(sp.getSubjectVar(), typeVar, sp.getObjectVar(), cntxtVar); diff --git a/sail/src/test/java/org/apache/rya/HashJoinTest.java b/sail/src/test/java/org/apache/rya/HashJoinTest.java index 8fc2590d4..baa532583 100644 --- a/sail/src/test/java/org/apache/rya/HashJoinTest.java +++ b/sail/src/test/java/org/apache/rya/HashJoinTest.java @@ -19,21 +19,16 @@ * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.HashSet; -import java.util.Set; - import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.api.RdfCloudTripleStoreUtils; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.query.join.HashJoin; import org.eclipse.rdf4j.common.iteration.CloseableIteration; @@ -41,6 +36,13 @@ import org.junit.Before; import org.junit.Test; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Date: 7/24/12 * Time: 5:51 PM @@ -69,12 +71,12 @@ public void destroy() throws Exception { public void testSimpleJoin() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, two)); @@ -87,12 +89,12 @@ public void testSimpleJoin() throws Exception { //1 join - HashJoin hjoin = new HashJoin(dao.getQueryEngine()); - CloseableIteration join = hjoin.join(null, - new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two)); + HashJoin hjoin = new HashJoin<>(dao.getQueryEngine()); + CloseableIteration join = hjoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two)); - Set uris = new HashSet(); + Set uris = new HashSet<>(); while (join.hasNext()) { uris.add(join.next()); } @@ -107,14 +109,14 @@ public void testSimpleJoin() throws Exception { public void testSimpleJoinMultiWay() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaType four = new RyaType("4"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaValue four = new RyaType("4"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, two)); @@ -136,11 +138,11 @@ public void testSimpleJoinMultiWay() throws Exception { //1 join HashJoin hjoin = new HashJoin(dao.getQueryEngine()); - CloseableIteration join = hjoin.join(null, - new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two), - new RdfCloudTripleStoreUtils.CustomEntry(pred, three), - new RdfCloudTripleStoreUtils.CustomEntry(pred, four) + CloseableIteration join = hjoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, three), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, four) ); Set uris = new HashSet(); @@ -158,15 +160,15 @@ public void testSimpleJoinMultiWay() throws Exception { public void testMergeJoinMultiWay() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType zero = new RyaType("0"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaType four = new RyaType("4"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue zero = new RyaType("0"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaValue four = new RyaType("4"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, two)); @@ -188,11 +190,11 @@ public void testMergeJoinMultiWay() throws Exception { //1 join HashJoin hjoin = new HashJoin(dao.getQueryEngine()); - CloseableIteration join = hjoin.join(null, - new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two), - new RdfCloudTripleStoreUtils.CustomEntry(pred, three), - new RdfCloudTripleStoreUtils.CustomEntry(pred, four) + CloseableIteration join = hjoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, three), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, four) ); Set uris = new HashSet(); @@ -209,15 +211,15 @@ public void testMergeJoinMultiWay() throws Exception { public void testMergeJoinMultiWayNone() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType zero = new RyaType("0"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaType four = new RyaType("4"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue zero = new RyaType("0"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaValue four = new RyaType("4"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, three)); @@ -234,11 +236,11 @@ public void testMergeJoinMultiWayNone() throws Exception { //1 join HashJoin hjoin = new HashJoin(dao.getQueryEngine()); - CloseableIteration join = hjoin.join(null, - new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two), - new RdfCloudTripleStoreUtils.CustomEntry(pred, three), - new RdfCloudTripleStoreUtils.CustomEntry(pred, four) + CloseableIteration join = hjoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, three), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, four) ); assertFalse(join.hasNext()); @@ -249,15 +251,15 @@ public void testMergeJoinMultiWayNone() throws Exception { public void testMergeJoinMultiWayNone2() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType zero = new RyaType("0"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaType four = new RyaType("4"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue zero = new RyaType("0"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaValue four = new RyaType("4"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, four)); @@ -272,11 +274,11 @@ public void testMergeJoinMultiWayNone2() throws Exception { //1 join HashJoin hjoin = new HashJoin(dao.getQueryEngine()); - CloseableIteration join = hjoin.join(null, - new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two), - new RdfCloudTripleStoreUtils.CustomEntry(pred, three), - new RdfCloudTripleStoreUtils.CustomEntry(pred, four) + CloseableIteration join = hjoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, three), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, four) ); assertFalse(join.hasNext()); @@ -288,11 +290,11 @@ public void testSimpleHashJoinPredicateOnly() throws Exception { //add data RyaIRI pred1 = new RyaIRI(litdupsNS, "pred1"); RyaIRI pred2 = new RyaIRI(litdupsNS, "pred2"); - RyaType one = new RyaType("1"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue one = new RyaType("1"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred1, one)); dao.add(new RyaStatement(subj1, pred2, one)); @@ -305,8 +307,8 @@ public void testSimpleHashJoinPredicateOnly() throws Exception { //1 join - HashJoin ijoin = new HashJoin(dao.getQueryEngine()); - CloseableIteration join = ijoin.join(null, pred1, pred2); + HashJoin ijoin = new HashJoin<>(dao.getQueryEngine()); + CloseableIteration join = ijoin.join(conf, pred1, pred2); int count = 0; while (join.hasNext()) { @@ -322,13 +324,13 @@ public void testSimpleMergeJoinPredicateOnly2() throws Exception { //add data RyaIRI pred1 = new RyaIRI(litdupsNS, "pred1"); RyaIRI pred2 = new RyaIRI(litdupsNS, "pred2"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred1, one)); dao.add(new RyaStatement(subj1, pred1, two)); @@ -357,8 +359,8 @@ public void testSimpleMergeJoinPredicateOnly2() throws Exception { //1 join - HashJoin ijoin = new HashJoin(dao.getQueryEngine()); - CloseableIteration join = ijoin.join(null, pred1, pred2); + HashJoin ijoin = new HashJoin<>(dao.getQueryEngine()); + CloseableIteration join = ijoin.join(conf, pred1, pred2); int count = 0; while (join.hasNext()) { diff --git a/sail/src/test/java/org/apache/rya/IterativeJoinTest.java b/sail/src/test/java/org/apache/rya/IterativeJoinTest.java index 6612f9ea9..06949bc4a 100644 --- a/sail/src/test/java/org/apache/rya/IterativeJoinTest.java +++ b/sail/src/test/java/org/apache/rya/IterativeJoinTest.java @@ -19,21 +19,16 @@ * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.HashSet; -import java.util.Set; - import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.api.RdfCloudTripleStoreUtils; +import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaResource; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.query.join.IterativeJoin; import org.eclipse.rdf4j.common.iteration.CloseableIteration; @@ -41,6 +36,13 @@ import org.junit.Before; import org.junit.Test; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Date: 7/24/12 * Time: 5:51 PM @@ -69,12 +71,12 @@ public void destroy() throws Exception { public void testSimpleIterativeJoin() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, two)); @@ -86,11 +88,12 @@ public void testSimpleIterativeJoin() throws Exception { dao.add(new RyaStatement(subj4, pred, two)); //1 join - IterativeJoin iterJoin = new IterativeJoin(dao.getQueryEngine()); - CloseableIteration join = iterJoin.join(null, new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two)); + IterativeJoin iterJoin = new IterativeJoin<>(dao.getQueryEngine()); + CloseableIteration join = iterJoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two)); - Set uris = new HashSet(); + Set uris = new HashSet<>(); while (join.hasNext()) { uris.add(join.next()); } @@ -105,14 +108,14 @@ public void testSimpleIterativeJoin() throws Exception { public void testSimpleIterativeJoinMultiWay() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaType four = new RyaType("4"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaValue four = new RyaType("4"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, two)); @@ -132,15 +135,15 @@ public void testSimpleIterativeJoinMultiWay() throws Exception { dao.add(new RyaStatement(subj4, pred, four)); //1 join - IterativeJoin iterativeJoin = new IterativeJoin(dao.getQueryEngine()); - CloseableIteration join = iterativeJoin.join(null, - new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two), - new RdfCloudTripleStoreUtils.CustomEntry(pred, three), - new RdfCloudTripleStoreUtils.CustomEntry(pred, four) + IterativeJoin iterJoin = new IterativeJoin<>(dao.getQueryEngine()); + CloseableIteration join = iterJoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, three), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, four) ); - Set uris = new HashSet(); + Set uris = new HashSet<>(); while (join.hasNext()) { uris.add(join.next()); } @@ -155,15 +158,15 @@ public void testSimpleIterativeJoinMultiWay() throws Exception { public void testIterativeJoinMultiWay() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType zero = new RyaType("0"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaType four = new RyaType("4"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue zero = new RyaType("0"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaValue four = new RyaType("4"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, two)); @@ -183,15 +186,15 @@ public void testIterativeJoinMultiWay() throws Exception { dao.add(new RyaStatement(subj4, pred, four)); //1 join - IterativeJoin iterativeJoin = new IterativeJoin(dao.getQueryEngine()); - CloseableIteration join = iterativeJoin.join(null, - new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two), - new RdfCloudTripleStoreUtils.CustomEntry(pred, three), - new RdfCloudTripleStoreUtils.CustomEntry(pred, four) + IterativeJoin iterJoin = new IterativeJoin<>(dao.getQueryEngine()); + CloseableIteration join = iterJoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, three), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, four) ); - Set uris = new HashSet(); + Set uris = new HashSet<>(); while (join.hasNext()) { uris.add(join.next()); } @@ -205,15 +208,15 @@ public void testIterativeJoinMultiWay() throws Exception { public void testIterativeJoinMultiWayNone() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType zero = new RyaType("0"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaType four = new RyaType("4"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue zero = new RyaType("0"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaValue four = new RyaType("4"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, three)); @@ -228,12 +231,12 @@ public void testIterativeJoinMultiWayNone() throws Exception { dao.add(new RyaStatement(subj4, pred, three)); //1 join - IterativeJoin iterativeJoin = new IterativeJoin(dao.getQueryEngine()); - CloseableIteration join = iterativeJoin.join(null, - new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two), - new RdfCloudTripleStoreUtils.CustomEntry(pred, three), - new RdfCloudTripleStoreUtils.CustomEntry(pred, four) + IterativeJoin iterJoin = new IterativeJoin<>(dao.getQueryEngine()); + CloseableIteration join = iterJoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, one), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, three), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, four) ); assertFalse(join.hasNext()); @@ -244,15 +247,15 @@ public void testIterativeJoinMultiWayNone() throws Exception { public void testIterativeJoinMultiWayNone2() throws Exception { //add data RyaIRI pred = new RyaIRI(litdupsNS, "pred1"); - RyaType zero = new RyaType("0"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaType four = new RyaType("4"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue zero = new RyaType("0"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaValue four = new RyaType("4"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred, one)); dao.add(new RyaStatement(subj1, pred, four)); @@ -265,11 +268,11 @@ public void testIterativeJoinMultiWayNone2() throws Exception { dao.add(new RyaStatement(subj4, pred, two)); //1 join - IterativeJoin iterativeJoin = new IterativeJoin(dao.getQueryEngine()); - CloseableIteration join = iterativeJoin.join(null, new RdfCloudTripleStoreUtils.CustomEntry(pred, one), - new RdfCloudTripleStoreUtils.CustomEntry(pred, two), - new RdfCloudTripleStoreUtils.CustomEntry(pred, three), - new RdfCloudTripleStoreUtils.CustomEntry(pred, four) + IterativeJoin iterJoin = new IterativeJoin<>(dao.getQueryEngine()); + CloseableIteration join = iterJoin.join(conf, + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, two), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, three), + new RdfCloudTripleStoreUtils.CustomEntry<>(pred, four) ); assertFalse(join.hasNext()); @@ -281,11 +284,11 @@ public void testSimpleIterativeJoinPredicateOnly() throws Exception { //add data RyaIRI pred1 = new RyaIRI(litdupsNS, "pred1"); RyaIRI pred2 = new RyaIRI(litdupsNS, "pred2"); - RyaType one = new RyaType("1"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue one = new RyaType("1"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred1, one)); dao.add(new RyaStatement(subj1, pred2, one)); @@ -298,8 +301,8 @@ public void testSimpleIterativeJoinPredicateOnly() throws Exception { //1 join - IterativeJoin ijoin = new IterativeJoin(dao.getQueryEngine()); - CloseableIteration join = ijoin.join(null, pred1, pred2); + IterativeJoin ijoin = new IterativeJoin<>(dao.getQueryEngine()); + CloseableIteration join = ijoin.join(conf, pred1, pred2); int count = 0; while (join.hasNext()) { @@ -315,13 +318,13 @@ public void testSimpleIterativeJoinPredicateOnly2() throws Exception { //add data RyaIRI pred1 = new RyaIRI(litdupsNS, "pred1"); RyaIRI pred2 = new RyaIRI(litdupsNS, "pred2"); - RyaType one = new RyaType("1"); - RyaType two = new RyaType("2"); - RyaType three = new RyaType("3"); - RyaIRI subj1 = new RyaIRI(litdupsNS, "subj1"); - RyaIRI subj2 = new RyaIRI(litdupsNS, "subj2"); - RyaIRI subj3 = new RyaIRI(litdupsNS, "subj3"); - RyaIRI subj4 = new RyaIRI(litdupsNS, "subj4"); + RyaValue one = new RyaType("1"); + RyaValue two = new RyaType("2"); + RyaValue three = new RyaType("3"); + RyaResource subj1 = new RyaIRI(litdupsNS, "subj1"); + RyaResource subj2 = new RyaIRI(litdupsNS, "subj2"); + RyaResource subj3 = new RyaIRI(litdupsNS, "subj3"); + RyaResource subj4 = new RyaIRI(litdupsNS, "subj4"); dao.add(new RyaStatement(subj1, pred1, one)); dao.add(new RyaStatement(subj1, pred1, two)); @@ -350,8 +353,8 @@ public void testSimpleIterativeJoinPredicateOnly2() throws Exception { //1 join - IterativeJoin ijoin = new IterativeJoin(dao.getQueryEngine()); - CloseableIteration join = ijoin.join(null, pred1, pred2); + IterativeJoin ijoin = new IterativeJoin<>(dao.getQueryEngine()); + CloseableIteration join = ijoin.join(conf, pred1, pred2); int count = 0; while (join.hasNext()) { diff --git a/sail/src/test/java/org/apache/rya/MergeJoinTest.java b/sail/src/test/java/org/apache/rya/MergeJoinTest.java index c06b777dd..8db7f4d44 100644 --- a/sail/src/test/java/org/apache/rya/MergeJoinTest.java +++ b/sail/src/test/java/org/apache/rya/MergeJoinTest.java @@ -19,21 +19,15 @@ * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.HashSet; -import java.util.Set; - import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.api.RdfCloudTripleStoreUtils.CustomEntry; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaValue; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.api.persist.query.join.MergeJoin; import org.eclipse.rdf4j.common.iteration.CloseableIteration; @@ -41,6 +35,13 @@ import org.junit.Before; import org.junit.Test; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * TODO: Move to rya.api when we have proper mock ryaDao * @@ -91,8 +92,8 @@ public void testSimpleMergeJoin() throws Exception { //1 join MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine()); - CloseableIteration join = mergeJoin.join(null, new CustomEntry(pred, one), - new CustomEntry(pred, two)); + CloseableIteration join = mergeJoin.join(conf, new CustomEntry(pred, one), + new CustomEntry(pred, two)); Set uris = new HashSet(); while (join.hasNext()) { @@ -128,7 +129,7 @@ public void testSimpleMergeJoinPredicateOnly() throws Exception { //1 join MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine()); - CloseableIteration join = mergeJoin.join(null, pred1, pred2); + CloseableIteration join = mergeJoin.join(conf, pred1, pred2); int count = 0; while (join.hasNext()) { @@ -180,7 +181,7 @@ public void testSimpleMergeJoinPredicateOnly2() throws Exception { //1 join MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine()); - CloseableIteration join = mergeJoin.join(null, pred1, pred2); + CloseableIteration join = mergeJoin.join(conf, pred1, pred2); int count = 0; while (join.hasNext()) { @@ -224,10 +225,10 @@ public void testSimpleMergeJoinMultiWay() throws Exception { //1 join MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine()); - CloseableIteration join = mergeJoin.join(null, new CustomEntry(pred, one), - new CustomEntry(pred, two), - new CustomEntry(pred, three), - new CustomEntry(pred, four) + CloseableIteration join = mergeJoin.join(conf, new CustomEntry(pred, one), + new CustomEntry(pred, two), + new CustomEntry(pred, three), + new CustomEntry(pred, four) ); Set uris = new HashSet(); @@ -275,10 +276,10 @@ public void testMergeJoinMultiWay() throws Exception { //1 join MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine()); - CloseableIteration join = mergeJoin.join(null, new CustomEntry(pred, one), - new CustomEntry(pred, two), - new CustomEntry(pred, three), - new CustomEntry(pred, four) + CloseableIteration join = mergeJoin.join(conf, new CustomEntry(pred, one), + new CustomEntry(pred, two), + new CustomEntry(pred, three), + new CustomEntry(pred, four) ); Set uris = new HashSet(); @@ -320,10 +321,10 @@ public void testMergeJoinMultiWayNone() throws Exception { //1 join MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine()); - CloseableIteration join = mergeJoin.join(null, new CustomEntry(pred, one), - new CustomEntry(pred, two), - new CustomEntry(pred, three), - new CustomEntry(pred, four) + CloseableIteration join = mergeJoin.join(conf, new CustomEntry(pred, one), + new CustomEntry(pred, two), + new CustomEntry(pred, three), + new CustomEntry(pred, four) ); assertFalse(join.hasNext()); @@ -357,10 +358,10 @@ public void testMergeJoinMultiWayNone2() throws Exception { //1 join MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine()); - CloseableIteration join = mergeJoin.join(null, new CustomEntry(pred, one), - new CustomEntry(pred, two), - new CustomEntry(pred, three), - new CustomEntry(pred, four) + CloseableIteration join = mergeJoin.join(conf, new CustomEntry(pred, one), + new CustomEntry(pred, two), + new CustomEntry(pred, three), + new CustomEntry(pred, four) ); assertFalse(join.hasNext()); diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java index c9ed7441a..a7f85dfc7 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java @@ -18,11 +18,6 @@ * specific language governing permissions and limitations * under the License. */ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Instance; @@ -31,9 +26,8 @@ import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection.StoreTripleSource; @@ -53,6 +47,12 @@ import org.junit.Before; import org.junit.Test; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + public class StatementPatternEvalTest { private static final ValueFactory VF = SimpleValueFactory.getInstance(); @@ -68,7 +68,7 @@ public void init() throws Exception { dao = new AccumuloRyaDAO(); dao.setConnector(conn); dao.init(); - eval = new ParallelEvaluationStrategyImpl(new StoreTripleSource(conf, dao), null, null, conf); + eval = new ParallelEvaluationStrategyImpl(new StoreTripleSource<>(conf, dao), null, null, conf); } @After @@ -87,15 +87,15 @@ public void simpleQueryWithoutBindingSets() List spList = StatementPatternCollector.process(pq.getTupleExpr()); RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); dao.add(statement1); RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); dao.add(statement2); RyaStatement statement3 = new RyaStatement(new RyaIRI("uri:Eric"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata()); dao.add(statement3); QueryBindingSet bsConstraint1 = new QueryBindingSet(); @@ -138,15 +138,15 @@ public void simpleQueryWithBindingSets() List spList = StatementPatternCollector.process(pq.getTupleExpr()); RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); dao.add(statement1); RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); dao.add(statement2); RyaStatement statement3 = new RyaStatement(new RyaIRI("uri:Eric"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata()); dao.add(statement3); QueryBindingSet bsConstraint1 = new QueryBindingSet(); @@ -192,15 +192,15 @@ public void simpleQueryWithBindingSetSameContext() List spList = StatementPatternCollector.process(pq.getTupleExpr()); RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); dao.add(statement1); RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); dao.add(statement2); RyaStatement statement3 = new RyaStatement(new RyaIRI("uri:Eric"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata()); dao.add(statement3); QueryBindingSet bsConstraint1 = new QueryBindingSet(); @@ -238,15 +238,15 @@ public void simpleQueryNoBindingSetConstantContext() List spList = StatementPatternCollector.process(pq.getTupleExpr()); RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); dao.add(statement1); RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); dao.add(statement2); RyaStatement statement3 = new RyaStatement(new RyaIRI("uri:Eric"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata()); dao.add(statement3); QueryBindingSet bsConstraint1 = new QueryBindingSet(); @@ -278,15 +278,15 @@ public void simpleQueryWithBindingSetConstantContext() List spList = StatementPatternCollector.process(pq.getTupleExpr()); RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); dao.add(statement1); RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); dao.add(statement2); RyaStatement statement3 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), - new RyaType("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); + new RyaIRI("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); dao.add(statement3); QueryBindingSet bsConstraint1 = new QueryBindingSet(); @@ -296,7 +296,7 @@ public void simpleQueryWithBindingSetConstantContext() List bsList = new ArrayList<>(); while (iteration.hasNext()) { - bsList.add(iteration.next()); + bsList.add(iteration.next()); // this causes a NullPointerException #1 of 2 https://github.com/apache/rya/pull/247/files } Assert.assertEquals(1, bsList.size()); @@ -309,7 +309,84 @@ public void simpleQueryWithBindingSetConstantContext() dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf); } - + @Test + public void simpleQueryWithBindingWithoutContext() + throws MalformedQueryException, QueryEvaluationException, RyaDAOException { + //query is used to build statement that will be evaluated + String query = "select ?x where{?x . }"; + SPARQLParser parser = new SPARQLParser(); + ParsedQuery pq = parser.parseQuery(query, null); + List spList = StatementPatternCollector.process(pq.getTupleExpr()); + + RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + dao.add(statement1); + + RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + dao.add(statement2); + + QueryBindingSet bsConstraint1 = new QueryBindingSet(); + bsConstraint1.addBinding("x", VF.createIRI("uri:Doug")); + + CloseableIteration iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1)); + + List bsList = new ArrayList<>(); + while (iteration.hasNext()) { + bsList.add(iteration.next()); + } + + Assert.assertEquals(1, bsList.size()); + + QueryBindingSet expected = new QueryBindingSet(); + expected.addBinding("x", VF.createIRI("uri:Doug")); + + Assert.assertEquals(expected, bsList.get(0)); + dao.delete(Arrays.asList(statement1, statement2).iterator(), conf); + } + + @Test + public void simpleQueryWithBindingSetWithContext() + throws MalformedQueryException, QueryEvaluationException, RyaDAOException { + //query is used to build statement that will be evaluated + String query = "select ?x ?c where{graph ?c {?x . }}"; + SPARQLParser parser = new SPARQLParser(); + ParsedQuery pq = parser.parseQuery(query, null); + List spList = StatementPatternCollector.process(pq.getTupleExpr()); + + RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + dao.add(statement1); + + RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), + new RyaIRI("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata()); + dao.add(statement2); + + RyaStatement statement3 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), + new RyaIRI("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata()); + dao.add(statement3); + + QueryBindingSet bsConstraint1 = new QueryBindingSet(); + bsConstraint1.addBinding("x", VF.createIRI("uri:Doug")); + bsConstraint1.addBinding("c", VF.createIRI("uri:context1")); + + CloseableIteration iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1)); + + List bsList = new ArrayList<>(); + while (iteration.hasNext()) { + bsList.add(iteration.next()); // this causes a NullPointerException #2 of 2 https://github.com/apache/rya/pull/247/files + } + + Assert.assertEquals(1, bsList.size()); + + QueryBindingSet expected = new QueryBindingSet(); + expected.addBinding("x", VF.createIRI("uri:Doug")); + expected.addBinding("c", VF.createIRI("uri:context1")); + + Assert.assertEquals(expected, bsList.get(0)); + dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf); + } + private static AccumuloRdfConfiguration getConf() { final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java index 9c08468af..2f7cc88e6 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java @@ -18,16 +18,7 @@ * under the License. */ -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; @@ -46,6 +37,14 @@ import org.junit.Assert; import org.junit.Test; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class AllValuesFromVisitorTest { private final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); private static final ValueFactory VF = SimpleValueFactory.getInstance(); @@ -108,10 +107,10 @@ public void testRewriteTypePattern() throws Exception { Assert.assertTrue(left instanceof StatementPattern); Assert.assertTrue(right instanceof StatementPattern); // Verify expected predicate/restriction pairs - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(parentsArePeople, OWL.ONPROPERTY, parent))); - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(relativesArePeople, OWL.ONPROPERTY, relative))); - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(relativesArePeople, OWL.ONPROPERTY, parent))); - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(parentsAreTallPeople, OWL.ONPROPERTY, parent))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(parentsArePeople, OWL.ONPROPERTY, parent))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(relativesArePeople, OWL.ONPROPERTY, relative))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(relativesArePeople, OWL.ONPROPERTY, parent))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(parentsAreTallPeople, OWL.ONPROPERTY, parent))); Assert.assertEquals(4, fsp.statements.size()); // Verify general pattern for matching instances of each pair: Join on unknown subject; left // triple states it belongs to the restriction while right triple relates it to the original diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java index 483d593c1..6273364bb 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java @@ -18,18 +18,7 @@ * under the License. */ -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; @@ -49,6 +38,16 @@ import org.junit.Assert; import org.junit.Test; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class HasValueVisitorTest { private final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); private static final ValueFactory VF = SimpleValueFactory.getInstance(); @@ -186,12 +185,12 @@ public void testRewriteValuePattern() throws Exception { // Verify FSP: should provide (type, value) pairs final List expectedStatements = new LinkedList<>(); final IRI fspPred = (IRI) fsp.getPredicateVar().getValue(); - expectedStatements.add(new NullableStatementImpl(chordate, fspPred, notochord)); - expectedStatements.add(new NullableStatementImpl(tunicate, fspPred, notochord)); - expectedStatements.add(new NullableStatementImpl(vertebrate, fspPred, notochord)); - expectedStatements.add(new NullableStatementImpl(mammal, fspPred, notochord)); - expectedStatements.add(new NullableStatementImpl(vertebrate, fspPred, skull)); - expectedStatements.add(new NullableStatementImpl(mammal, fspPred, skull)); + expectedStatements.add(VF.createStatement(chordate, fspPred, notochord)); + expectedStatements.add(VF.createStatement(tunicate, fspPred, notochord)); + expectedStatements.add(VF.createStatement(vertebrate, fspPred, notochord)); + expectedStatements.add(VF.createStatement(mammal, fspPred, notochord)); + expectedStatements.add(VF.createStatement(vertebrate, fspPred, skull)); + expectedStatements.add(VF.createStatement(mammal, fspPred, skull)); final List actualStatements = new LinkedList<>(fsp.statements); Assert.assertTrue(containsAll(expectedStatements, actualStatements)); diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java index 3ef9e96e0..f9884ee2d 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java @@ -18,13 +18,8 @@ */ package org.apache.rya.rdftriplestore.inference; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import com.google.common.collect.Sets; +import junit.framework.TestCase; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.accumulo.core.client.security.tokens.PasswordToken; @@ -44,16 +39,19 @@ import org.junit.Assert; import org.junit.Test; -import com.google.common.collect.Sets; - -import junit.framework.TestCase; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; public class InferenceEngineTest extends TestCase { private Connector connector; private AccumuloRyaDAO dao; private static final ValueFactory VF = SimpleValueFactory.getInstance(); private AccumuloRdfConfiguration conf; - private RdfCloudTripleStore store; + private RdfCloudTripleStore store; private InferenceEngine inferenceEngine; private SailRepository repository; private SailRepositoryConnection conn; @@ -67,11 +65,12 @@ public void setUp() throws Exception { conf = new AccumuloRdfConfiguration(); dao.setConf(conf); dao.init(); - store = new RdfCloudTripleStore(); + store = new RdfCloudTripleStore<>(); store.setConf(conf); store.setRyaDAO(dao); inferenceEngine = new InferenceEngine(); inferenceEngine.setRyaDAO(dao); + inferenceEngine.setConf(conf); store.setInferenceEngine(inferenceEngine); inferenceEngine.refreshGraph(); store.initialize(); diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java index b53f5ee21..fc69ebd18 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java @@ -18,19 +18,12 @@ * under the License. */ -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import junit.framework.TestCase; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; -import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.rdftriplestore.RdfCloudTripleStore; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Value; @@ -50,7 +43,15 @@ import org.junit.Assert; import org.junit.Test; -import junit.framework.TestCase; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.apache.rya.api.RdfCloudTripleStoreConstants.RTS_SUBJECT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.VERSION_RYA; public class InferenceIT extends TestCase { private final static String LUBM = "http://swat.cse.lehigh.edu/onto/univ-bench.owl#"; @@ -81,6 +82,7 @@ public void setUp() throws Exception { store.setRyaDAO(dao); inferenceEngine = new InferenceEngine(); inferenceEngine.setRyaDAO(dao); + inferenceEngine.setConf(conf); store.setInferenceEngine(inferenceEngine); inferenceEngine.refreshGraph(); store.initialize(); @@ -674,8 +676,8 @@ public void testReflexivePropertyQuery() throws Exception { everything.add(new ListBindingSet(varNames, eve, eve)); everything.add(new ListBindingSet(varNames, hasFamily, hasFamily)); everything.add(new ListBindingSet(varNames, rp, rp)); - everything.add(new ListBindingSet(varNames, RdfCloudTripleStoreConstants.RTS_SUBJECT, RdfCloudTripleStoreConstants.RTS_SUBJECT)); - everything.add(new ListBindingSet(varNames, RdfCloudTripleStoreConstants.VERSION, RdfCloudTripleStoreConstants.VERSION)); + everything.add(new ListBindingSet(varNames, RTS_SUBJECT, RTS_SUBJECT)); + everything.add(new ListBindingSet(varNames, VERSION_RYA, VERSION_RYA)); final String everythingQuery = "SELECT * { GRAPH {\n" + " ?x ?y .\n" + "} }"; diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/PropertyChainTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/PropertyChainTest.java index 7a6bc7922..fffd5d95c 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/PropertyChainTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/PropertyChainTest.java @@ -18,8 +18,7 @@ */ package org.apache.rya.rdftriplestore.inference; -import java.util.List; - +import junit.framework.TestCase; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.admin.SecurityOperations; @@ -40,7 +39,7 @@ import org.junit.Assert; import org.junit.Test; -import junit.framework.TestCase; +import java.util.List; public class PropertyChainTest extends TestCase { private String user = "user"; @@ -89,11 +88,12 @@ public void tearDown() throws Exception { @Test public void testGraphConfiguration() throws Exception { // build a connection - RdfCloudTripleStore store = new RdfCloudTripleStore(); + RdfCloudTripleStore store = new RdfCloudTripleStore<>(); store.setConf(conf); store.setRyaDAO(ryaDAO); InferenceEngine inferenceEngine = new InferenceEngine(); inferenceEngine.setRyaDAO(ryaDAO); + inferenceEngine.setConf(conf); store.setInferenceEngine(inferenceEngine); inferenceEngine.refreshGraph(); store.initialize(); diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/SomeValuesFromVisitorTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/SomeValuesFromVisitorTest.java index 603144e49..ca40eb42a 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/SomeValuesFromVisitorTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/SomeValuesFromVisitorTest.java @@ -18,15 +18,8 @@ * under the License. */ -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - +import com.google.common.collect.Sets; import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; @@ -45,7 +38,12 @@ import org.junit.Assert; import org.junit.Test; -import com.google.common.collect.Sets; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class SomeValuesFromVisitorTest { private static final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); @@ -111,11 +109,11 @@ public void testSomeValuesFrom() throws Exception { Assert.assertTrue(left instanceof StatementPattern); Assert.assertTrue(right instanceof StatementPattern); // Verify expected predicate/type pairs - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(takesCourse, OWL.SOMEVALUESFROM, course))); - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(takesCourse, OWL.SOMEVALUESFROM, gradCourse))); - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(headOf, OWL.SOMEVALUESFROM, department))); - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(headOf, OWL.SOMEVALUESFROM, organization))); - Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(worksFor, OWL.SOMEVALUESFROM, organization))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(takesCourse, OWL.SOMEVALUESFROM, course))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(takesCourse, OWL.SOMEVALUESFROM, gradCourse))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(headOf, OWL.SOMEVALUESFROM, department))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(headOf, OWL.SOMEVALUESFROM, organization))); + Assert.assertTrue(fsp.statements.contains(VF.createStatement(worksFor, OWL.SOMEVALUESFROM, organization))); Assert.assertEquals(5, fsp.statements.size()); // Verify pattern for matching instances of each pair: a Join of <_:x rdf:type ?t> and // where p and t are the predicate/type pair and s is the original subject diff --git a/sail/src/test/resources/log4j.xml b/sail/src/test/resources/log4j.xml new file mode 100644 index 000000000..ccf46ae73 --- /dev/null +++ b/sail/src/test/resources/log4j.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/accumulo/src/main/java/org/apache/rya/test/accumulo/RyaTestInstanceRule.java b/test/accumulo/src/main/java/org/apache/rya/test/accumulo/RyaTestInstanceRule.java index dd13a2851..1d6475d16 100644 --- a/test/accumulo/src/main/java/org/apache/rya/test/accumulo/RyaTestInstanceRule.java +++ b/test/accumulo/src/main/java/org/apache/rya/test/accumulo/RyaTestInstanceRule.java @@ -18,11 +18,11 @@ */ package org.apache.rya.test.accumulo; +import org.junit.rules.ExternalResource; + import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.rules.ExternalResource; - public class RyaTestInstanceRule extends ExternalResource { private static final AtomicInteger ryaInstanceNameCounter = new AtomicInteger(1); @@ -46,7 +46,7 @@ public static interface DoInstall { } /** - * Constructs an instance of {@link RyaTestInstnaceRule} where no extra steps need + * Constructs an instance of {@link RyaTestInstanceRule} where no extra steps need * to be performed within {@link #before()}. */ public RyaTestInstanceRule() { @@ -54,7 +54,7 @@ public RyaTestInstanceRule() { } /** - * Constructs an instance of {@link RyaTestInstnaceRule}. + * Constructs an instance of {@link RyaTestInstanceRule}. * * @param doInstall - Invoked within {@link #before()}. (not null) */ diff --git a/web/web.rya/src/test/java/org/apache/cloud/rdf/web/sail/RdfControllerTest.java b/web/web.rya/src/test/java/org/apache/cloud/rdf/web/sail/RdfControllerTest.java index 80227b168..8bcc5b4ac 100644 --- a/web/web.rya/src/test/java/org/apache/cloud/rdf/web/sail/RdfControllerTest.java +++ b/web/web.rya/src/test/java/org/apache/cloud/rdf/web/sail/RdfControllerTest.java @@ -19,14 +19,6 @@ * under the License. */ -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertTrue; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; - import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; @@ -49,6 +41,14 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.util.NestedServletException; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertTrue; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration("/controllerTest-context.xml") @@ -87,7 +87,7 @@ public void emptyQuery() throws Exception { } @Test - public void emptyQueryXMLFormat() throws Exception { + public void queryXMLFormat() throws Exception { this.mockMvc.perform(get("/queryrdf") .param("query", "SELECT * WHERE { ?s ?p ?o . }") .param("query.resultformat", "xml")) @@ -96,7 +96,7 @@ public void emptyQueryXMLFormat() throws Exception { } @Test - public void emptyQueryJSONFormat() throws Exception { + public void queryJSONFormat() throws Exception { this.mockMvc.perform(get("/queryrdf") .param("query", "SELECT * WHERE { ?s ?p ?o . }") .param("query.resultformat", "json")) @@ -105,7 +105,7 @@ public void emptyQueryJSONFormat() throws Exception { } @Test - public void emptyQueryNoFormat() throws Exception { + public void queryNoFormat() throws Exception { this.mockMvc.perform(get("/queryrdf") .param("query", "SELECT * WHERE { ?s ?p ?o . }")) .andExpect(status().isOk())