Search in sources :

Example 1 with MongoPcjDocuments

use of org.apache.rya.indexing.pcj.storage.mongo.MongoPcjDocuments in project incubator-rya by apache.

the class MongoPcjIndexSetProvider method getIndices.

@Override
protected List<ExternalTupleSet> getIndices() throws PcjIndexSetException {
    try {
        final StatefulMongoDBRdfConfiguration mongoConf = (StatefulMongoDBRdfConfiguration) conf;
        final MongoClient client = mongoConf.getMongoClient();
        final MongoPcjDocuments pcjDocs = new MongoPcjDocuments(client, mongoConf.getRyaInstanceName());
        List<String> documents = null;
        documents = mongoConf.getPcjTables();
        // this maps associates pcj document name with pcj sparql query
        final Map<String, String> indexDocuments = Maps.newLinkedHashMap();
        try (final PrecomputedJoinStorage storage = new MongoPcjStorage(client, mongoConf.getRyaInstanceName())) {
            final boolean docsProvided = documents != null && !documents.isEmpty();
            if (docsProvided) {
                // if tables provided, associate table name with sparql
                for (final String doc : documents) {
                    indexDocuments.put(doc, storage.getPcjMetadata(doc).getSparql());
                }
            } else if (hasRyaDetails()) {
                // If this is a newer install of Rya, and it has PCJ Details, then
                // use those.
                final List<String> ids = storage.listPcjs();
                for (final String pcjId : ids) {
                    indexDocuments.put(pcjId, storage.getPcjMetadata(pcjId).getSparql());
                }
            } else {
                // Otherwise figure it out by getting document IDs.
                documents = pcjDocs.listPcjDocuments();
                for (final String pcjId : documents) {
                    if (pcjId.startsWith("INDEX")) {
                        indexDocuments.put(pcjId, pcjDocs.getPcjMetadata(pcjId).getSparql());
                    }
                }
            }
        }
        final List<ExternalTupleSet> index = Lists.newArrayList();
        if (indexDocuments.isEmpty()) {
            log.info("No Index found");
        } else {
            for (final String pcjID : indexDocuments.keySet()) {
                final String indexSparqlString = indexDocuments.get(pcjID);
                index.add(new MongoPcjQueryNode(indexSparqlString, pcjID, pcjDocs));
            }
        }
        return index;
    } catch (final PCJStorageException | MalformedQueryException e) {
        throw new PcjIndexSetException("Failed to get indicies for this PCJ index.", e);
    }
}
Also used : StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoPcjDocuments(org.apache.rya.indexing.pcj.storage.mongo.MongoPcjDocuments) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) MongoPcjStorage(org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage) MongoClient(com.mongodb.MongoClient) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.openrdf.query.MalformedQueryException) List(java.util.List) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 2 with MongoPcjDocuments

use of org.apache.rya.indexing.pcj.storage.mongo.MongoPcjDocuments in project incubator-rya by apache.

the class PcjIntegrationTestingUtil method createAndPopulatePcj.

/**
 * Creates a new PCJ Table in Accumulo and populates it by scanning an
 * instance of Rya for historic matches.
 * <p>
 * If any portion of this operation fails along the way, the partially
 * create PCJ table will be left in Accumulo.
 *
 * @param ryaConn - Connects to the Rya that will be scanned. (not null)
 * @param mongoClient - Connects to the mongoDB that hosts the PCJ results. (not null)
 * @param pcjName - The name of the PCJ table that will be created. (not null)
 * @param sparql - The SPARQL query whose results will be loaded into the table. (not null)
 * @throws PcjException The PCJ table could not be create or the values from Rya were
 *         not able to be loaded into it.
 */
public static void createAndPopulatePcj(final RepositoryConnection ryaConn, final MongoClient mongoClient, final String pcjName, final String instanceName, final String sparql) throws PcjException {
    checkNotNull(ryaConn);
    checkNotNull(mongoClient);
    checkNotNull(pcjName);
    checkNotNull(instanceName);
    checkNotNull(sparql);
    final MongoPcjDocuments pcj = new MongoPcjDocuments(mongoClient, instanceName);
    pcj.createPcj(pcjName, sparql);
    // Load historic matches from Rya into the PCJ table.
    populatePcj(pcj, pcjName, ryaConn);
}
Also used : MongoPcjDocuments(org.apache.rya.indexing.pcj.storage.mongo.MongoPcjDocuments)

Aggregations

MongoPcjDocuments (org.apache.rya.indexing.pcj.storage.mongo.MongoPcjDocuments)2 MongoClient (com.mongodb.MongoClient)1 List (java.util.List)1 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)1 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)1 PCJStorageException (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)1 MongoPcjStorage (org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage)1 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1