use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class MergeJoinTest method testMergeJoinMultiWayNone.
@Test
public void testMergeJoinMultiWayNone() throws Exception {
// add data
RyaURI pred = new RyaURI(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");
RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
dao.add(new RyaStatement(subj1, pred, one));
dao.add(new RyaStatement(subj1, pred, three));
dao.add(new RyaStatement(subj1, pred, four));
dao.add(new RyaStatement(subj2, pred, zero));
dao.add(new RyaStatement(subj2, pred, one));
dao.add(new RyaStatement(subj2, pred, four));
dao.add(new RyaStatement(subj3, pred, two));
dao.add(new RyaStatement(subj3, pred, four));
dao.add(new RyaStatement(subj4, pred, one));
dao.add(new RyaStatement(subj4, pred, two));
dao.add(new RyaStatement(subj4, pred, three));
// 1 join
MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
CloseableIteration<RyaURI, RyaDAOException> join = mergeJoin.join(null, new CustomEntry<RyaURI, RyaType>(pred, one), new CustomEntry<RyaURI, RyaType>(pred, two), new CustomEntry<RyaURI, RyaType>(pred, three), new CustomEntry<RyaURI, RyaType>(pred, four));
assertFalse(join.hasNext());
join.close();
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class MergeJoinTest method testMergeJoinMultiWay.
@Test
public void testMergeJoinMultiWay() throws Exception {
// add data
RyaURI pred = new RyaURI(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");
RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
dao.add(new RyaStatement(subj1, pred, one));
dao.add(new RyaStatement(subj1, pred, two));
dao.add(new RyaStatement(subj1, pred, three));
dao.add(new RyaStatement(subj1, pred, four));
dao.add(new RyaStatement(subj2, pred, zero));
dao.add(new RyaStatement(subj2, pred, one));
dao.add(new RyaStatement(subj2, pred, two));
dao.add(new RyaStatement(subj2, pred, three));
dao.add(new RyaStatement(subj2, pred, four));
dao.add(new RyaStatement(subj3, pred, one));
dao.add(new RyaStatement(subj3, pred, two));
dao.add(new RyaStatement(subj3, pred, four));
dao.add(new RyaStatement(subj4, pred, one));
dao.add(new RyaStatement(subj4, pred, two));
dao.add(new RyaStatement(subj4, pred, three));
dao.add(new RyaStatement(subj4, pred, four));
// 1 join
MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
CloseableIteration<RyaURI, RyaDAOException> join = mergeJoin.join(null, new CustomEntry<RyaURI, RyaType>(pred, one), new CustomEntry<RyaURI, RyaType>(pred, two), new CustomEntry<RyaURI, RyaType>(pred, three), new CustomEntry<RyaURI, RyaType>(pred, four));
Set<RyaURI> uris = new HashSet<RyaURI>();
while (join.hasNext()) {
uris.add(join.next());
}
assertTrue(uris.contains(subj1));
assertTrue(uris.contains(subj2));
assertTrue(uris.contains(subj4));
join.close();
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class StatementPatternStorage method addInferredRanges.
protected void addInferredRanges(String tablePrefix, Job job) throws IOException {
logger.info("Adding inferences to statement pattern[subject:" + subject_value + ", predicate:" + predicate_value + ", object:" + object_value + "]");
// inference engine
AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
InferenceEngine inferenceEngine = new InferenceEngine();
try {
AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(job.getConfiguration());
rdfConf.setTablePrefix(tablePrefix);
ryaDAO.setConf(rdfConf);
try {
if (!mock) {
ryaDAO.setConnector(new ZooKeeperInstance(inst, zookeepers).getConnector(user, userP.getBytes(StandardCharsets.UTF_8)));
} else {
ryaDAO.setConnector(new MockInstance(inst).getConnector(user, userP.getBytes(StandardCharsets.UTF_8)));
}
} catch (Exception e) {
throw new IOException(e);
}
ryaDAO.init();
inferenceEngine.setConf(rdfConf);
inferenceEngine.setRyaDAO(ryaDAO);
inferenceEngine.setSchedule(false);
inferenceEngine.init();
// is it subclassof or subpropertyof
if (RDF.TYPE.equals(predicate_value)) {
// try subclassof
Collection<URI> parents = inferenceEngine.findParents(inferenceEngine.getSubClassOfGraph(), (URI) object_value);
if (parents != null && parents.size() > 0) {
// add all relationships
for (URI parent : parents) {
Map.Entry<TABLE_LAYOUT, Range> temp = createRange(subject_value, predicate_value, parent);
Range range = temp.getValue();
if (logger.isDebugEnabled()) {
logger.debug("Found subClassOf relationship [type:" + object_value + " is subClassOf:" + parent + "]");
}
addRange(range);
}
}
} else if (predicate_value != null) {
// subpropertyof check
Set<URI> parents = inferenceEngine.findParents(inferenceEngine.getSubPropertyOfGraph(), (URI) predicate_value);
for (URI parent : parents) {
Map.Entry<TABLE_LAYOUT, Range> temp = createRange(subject_value, parent, object_value);
Range range = temp.getValue();
if (logger.isDebugEnabled()) {
logger.debug("Found subPropertyOf relationship [type:" + predicate_value + " is subPropertyOf:" + parent + "]");
}
addRange(range);
}
}
} catch (Exception e) {
logger.error("Exception in adding inferred ranges", e);
throw new IOException(e);
} finally {
if (inferenceEngine != null) {
try {
inferenceEngine.destroy();
} catch (InferenceEngineException e) {
logger.error("Exception closing InferenceEngine", e);
}
}
if (ryaDAO != null) {
try {
ryaDAO.destroy();
} catch (RyaDAOException e) {
logger.error("Exception closing ryadao", e);
}
}
}
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class HashJoinTest method testMergeJoinMultiWayNone.
@Test
public void testMergeJoinMultiWayNone() throws Exception {
// add data
RyaURI pred = new RyaURI(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");
RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
dao.add(new RyaStatement(subj1, pred, one));
dao.add(new RyaStatement(subj1, pred, three));
dao.add(new RyaStatement(subj1, pred, four));
dao.add(new RyaStatement(subj2, pred, zero));
dao.add(new RyaStatement(subj2, pred, one));
dao.add(new RyaStatement(subj2, pred, four));
dao.add(new RyaStatement(subj3, pred, two));
dao.add(new RyaStatement(subj3, pred, four));
dao.add(new RyaStatement(subj4, pred, one));
dao.add(new RyaStatement(subj4, pred, two));
dao.add(new RyaStatement(subj4, pred, three));
// 1 join
HashJoin hjoin = new HashJoin(dao.getQueryEngine());
CloseableIteration<RyaURI, RyaDAOException> join = hjoin.join(null, new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, one), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, two), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, three), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, four));
assertFalse(join.hasNext());
join.close();
}
use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.
the class NewQueryCommand method execute.
@Override
public void execute(final Connector accumulo, final String ryaTablePrefix, final RyaSailRepository rya, final FluoClient fluo, final String[] args) throws ArgumentsException, ExecutionException, UnsupportedQueryException {
checkNotNull(accumulo);
checkNotNull(fluo);
checkNotNull(args);
log.trace("Executing the New Query Command...");
// Parse the command line arguments.
final Parameters params = new Parameters();
try {
new JCommander(params, args);
} catch (final ParameterException e) {
throw new ArgumentsException("Could not create a new query because of invalid command line parameters.", e);
}
// Load the request from the file into memory.
log.trace("Loading the query found in file '" + params.queryRequestFile + "' into the client app.");
ParsedQueryRequest request = null;
try {
final Path requestFile = Paths.get(params.queryRequestFile);
final String requestText = IOUtils.toString(Files.newInputStream(requestFile));
request = ParsedQueryRequest.parse(requestText);
} catch (final IOException e) {
throw new ExecutionException("Could not load the query request into memory.", e);
}
// Load the query into the Fluo app.
log.trace("SPARQL Query: " + request.getQuery());
log.trace("Var Orders: " + request.getVarOrders());
log.trace("Loading these values into the Fluo app.");
final CreateFluoPcj createPcj = new CreateFluoPcj();
try {
// Create the PCJ in Rya.
final String sparql = request.getQuery();
final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumulo, ryaTablePrefix);
final String pcjId = pcjStorage.createPcj(sparql);
// Tell the Fluo PCJ Updater app to maintain the PCJ.
createPcj.withRyaIntegration(pcjId, pcjStorage, fluo, accumulo, ryaTablePrefix);
} catch (MalformedQueryException | PcjException | RyaDAOException e) {
throw new ExecutionException("Could not create and load historic matches into the the Fluo app for the query.", e);
}
log.trace("Finished executing the New Query Command.");
}
Aggregations