Search in sources :

Example 21 with MongoDBRdfConfiguration

use of org.apache.rya.mongodb.MongoDBRdfConfiguration in project incubator-rya by apache.

the class RyaSailFactory method getRyaSail.

private static Sail getRyaSail(final Configuration config) throws InferenceEngineException, RyaDAOException, AccumuloException, AccumuloSecurityException, SailException {
    final RdfCloudTripleStore store = new RdfCloudTripleStore();
    final RyaDAO<?> dao;
    final RdfCloudTripleStoreConfiguration rdfConfig;
    final String user;
    final String pswd;
    // XXX Should(?) be MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX inside the if below. RYA-135
    final String ryaInstance = config.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
    Objects.requireNonNull(ryaInstance, "RyaInstance or table prefix is missing from configuration." + RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
    if (ConfigUtils.getUseMongo(config)) {
        // Get a reference to a Mongo DB configuration object.
        final MongoDBRdfConfiguration mongoConfig = (config instanceof MongoDBRdfConfiguration) ? (MongoDBRdfConfiguration) config : new MongoDBRdfConfiguration(config);
        // Instantiate a Mongo client and Mongo DAO.
        dao = getMongoDAO(mongoConfig);
        // Then use the DAO's newly-created stateful conf in place of the original
        rdfConfig = dao.getConf();
    } else {
        rdfConfig = new AccumuloRdfConfiguration(config);
        user = rdfConfig.get(ConfigUtils.CLOUDBASE_USER);
        pswd = rdfConfig.get(ConfigUtils.CLOUDBASE_PASSWORD);
        Objects.requireNonNull(user, "Accumulo user name is missing from configuration." + ConfigUtils.CLOUDBASE_USER);
        Objects.requireNonNull(pswd, "Accumulo user password is missing from configuration." + ConfigUtils.CLOUDBASE_PASSWORD);
        rdfConfig.setTableLayoutStrategy(new TablePrefixLayoutStrategy(ryaInstance));
        updateAccumuloConfig((AccumuloRdfConfiguration) rdfConfig, user, pswd, ryaInstance);
        dao = getAccumuloDAO((AccumuloRdfConfiguration) rdfConfig);
    }
    store.setRyaDAO(dao);
    rdfConfig.setTablePrefix(ryaInstance);
    if (rdfConfig.isInfer()) {
        final InferenceEngine inferenceEngine = new InferenceEngine();
        inferenceEngine.setConf(rdfConfig);
        inferenceEngine.setRyaDAO(dao);
        inferenceEngine.init();
        store.setInferenceEngine(inferenceEngine);
    }
    store.initialize();
    return store;
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) InferenceEngine(org.apache.rya.rdftriplestore.inference.InferenceEngine) TablePrefixLayoutStrategy(org.apache.rya.api.layout.TablePrefixLayoutStrategy) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 22 with MongoDBRdfConfiguration

use of org.apache.rya.mongodb.MongoDBRdfConfiguration in project incubator-rya by apache.

the class StatementMetadataExternalSetProviderTest method createMultipleMetadataNode.

@Test
public void createMultipleMetadataNode() throws MalformedQueryException {
    MongoDBRdfConfiguration conf = (MongoDBRdfConfiguration) getConf(true);
    Set<RyaURI> propertySet = new HashSet<>();
    propertySet.add(new RyaURI("http://createdBy"));
    propertySet.add(new RyaURI("http://createdOn"));
    conf.setStatementMetadataProperties(propertySet);
    StatementMetadataExternalSetProvider metaProvider = new StatementMetadataExternalSetProvider(conf);
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    ParsedQuery pq3 = parser.parseQuery(query3, null);
    ParsedQuery pq1 = parser.parseQuery(query, null);
    List<QueryModelNode> patterns = new ArrayList<>();
    List<StatementMetadataNode<?>> expected = new ArrayList<>();
    Set<StatementPattern> sp1 = StatementMetadataTestUtils.getMetadataStatementPatterns(pq1.getTupleExpr(), propertySet);
    Set<StatementPattern> sp3 = StatementMetadataTestUtils.getMetadataStatementPatterns(pq3.getTupleExpr(), propertySet);
    // added extra blankNode into query3 to make blankNode names line up with query2.  Need to remove it now so that
    // StatementMetadataNode doesn't blow up because all subjects aren't the same.
    removePatternWithGivenSubject("-anon-1", sp3);
    patterns.addAll(StatementPatternCollector.process(pq2.getTupleExpr()));
    JoinSegment<StatementMetadataNode<?>> segment = new JoinSegment<>(new HashSet<>(patterns), patterns, new HashMap<ValueExpr, Filter>());
    List<StatementMetadataNode<?>> extSets = metaProvider.getExternalSets(segment);
    expected.add(new StatementMetadataNode<>(sp1, conf));
    expected.add(new StatementMetadataNode<>(sp3, conf));
    Assert.assertEquals(expected, extSets);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) JoinSegment(org.apache.rya.indexing.external.matching.JoinSegment) StatementMetadataExternalSetProvider(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataExternalSetProvider) RyaURI(org.apache.rya.api.domain.RyaURI) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) StatementPattern(org.openrdf.query.algebra.StatementPattern) Filter(org.openrdf.query.algebra.Filter) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with MongoDBRdfConfiguration

use of org.apache.rya.mongodb.MongoDBRdfConfiguration in project incubator-rya by apache.

the class StatementMetadataExternalSetProviderTest method getConf.

private static Configuration getConf(boolean useMongo) {
    if (useMongo) {
        MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration();
        conf.setBoolean("sc.useMongo", true);
        conf.setMongoHostname("localhost");
        conf.setMongoPort("27017");
        conf.setMongoDBName("rya_");
        return conf;
    } else {
        AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
        conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
        conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");
        conf.set(ConfigUtils.CLOUDBASE_USER, "root");
        conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "");
        conf.set(ConfigUtils.CLOUDBASE_INSTANCE, "instance");
        conf.set(ConfigUtils.CLOUDBASE_AUTHS, "");
        return conf;
    }
}
Also used : MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 24 with MongoDBRdfConfiguration

use of org.apache.rya.mongodb.MongoDBRdfConfiguration in project incubator-rya by apache.

the class StatementMetadataExternalSetProviderTest method createSingleMongoMetadataNode.

@Test
public void createSingleMongoMetadataNode() throws MalformedQueryException {
    MongoDBRdfConfiguration conf = (MongoDBRdfConfiguration) getConf(true);
    Set<RyaURI> propertySet = new HashSet<>();
    propertySet.add(new RyaURI("http://createdBy"));
    conf.setStatementMetadataProperties(propertySet);
    StatementMetadataExternalSetProvider metaProvider = new StatementMetadataExternalSetProvider(conf);
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<QueryModelNode> patterns = new ArrayList<>();
    List<StatementMetadataNode<?>> expected = new ArrayList<>();
    Set<StatementPattern> sp = StatementMetadataTestUtils.getMetadataStatementPatterns(pq.getTupleExpr(), propertySet);
    patterns.addAll(StatementPatternCollector.process(pq.getTupleExpr()));
    JoinSegment<StatementMetadataNode<?>> segment = new JoinSegment<>(new HashSet<>(patterns), patterns, new HashMap<ValueExpr, Filter>());
    List<StatementMetadataNode<?>> extSets = metaProvider.getExternalSets(segment);
    expected.add(new StatementMetadataNode<>(sp, conf));
    Assert.assertEquals(expected, extSets);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) JoinSegment(org.apache.rya.indexing.external.matching.JoinSegment) StatementMetadataExternalSetProvider(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataExternalSetProvider) RyaURI(org.apache.rya.api.domain.RyaURI) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) StatementPattern(org.openrdf.query.algebra.StatementPattern) Filter(org.openrdf.query.algebra.Filter) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MongoDBRdfConfiguration (org.apache.rya.mongodb.MongoDBRdfConfiguration)24 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 ParsedQuery (org.openrdf.query.parser.ParsedQuery)9 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)9 Sail (org.openrdf.sail.Sail)9 RyaURI (org.apache.rya.api.domain.RyaURI)8 LiteralImpl (org.openrdf.model.impl.LiteralImpl)7 SailRepository (org.openrdf.repository.sail.SailRepository)7 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)6 MongoDBRyaDAO (org.apache.rya.mongodb.MongoDBRyaDAO)6 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)6 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)6 StatementPattern (org.openrdf.query.algebra.StatementPattern)6 RyaStatement (org.apache.rya.api.domain.RyaStatement)5 RyaType (org.apache.rya.api.domain.RyaType)5 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)5 HashSet (java.util.HashSet)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)4