Search in sources :

Example 16 with RdfCloudTripleStoreConfiguration

use of org.apache.rya.api.RdfCloudTripleStoreConfiguration in project incubator-rya by apache.

the class StatementMetadataOptimizerTest method getConf.

private static RdfCloudTripleStoreConfiguration getConf(boolean useMongo) {
    RdfCloudTripleStoreConfiguration conf;
    Set<RyaURI> propertySet = new HashSet<>(Arrays.asList(new RyaURI("http://createdBy"), new RyaURI("http://createdOn")));
    if (useMongo) {
        MongoDBRdfConfiguration mConf = new MongoDBRdfConfiguration();
        mConf.setBoolean("sc.useMongo", true);
        mConf.setMongoHostname("localhost");
        mConf.setMongoPort("27017");
        mConf.setMongoDBName("rya_");
        conf = mConf;
    } else {
        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, "");
    }
    conf.setStatementMetadataProperties(propertySet);
    return conf;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) HashSet(java.util.HashSet)

Example 17 with RdfCloudTripleStoreConfiguration

use of org.apache.rya.api.RdfCloudTripleStoreConfiguration 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 18 with RdfCloudTripleStoreConfiguration

use of org.apache.rya.api.RdfCloudTripleStoreConfiguration in project incubator-rya by apache.

the class RdfCloudTripleStoreSelectivityEvaluationStatisticsTest method testOptimizeQ1.

@Test
public void testOptimizeQ1() throws Exception {
    RdfEvalStatsDAO<RdfCloudTripleStoreConfiguration> res = new ProspectorServiceEvalStatsDAO(conn, arc);
    AccumuloSelectivityEvalDAO accc = new AccumuloSelectivityEvalDAO();
    accc.setConf(arc);
    accc.setRdfEvalDAO(res);
    accc.setConnector(conn);
    accc.init();
    BatchWriter bw1 = conn.createBatchWriter("rya_prospects", config);
    BatchWriter bw2 = conn.createBatchWriter("rya_selectivity", config);
    String s1 = "predicateobject" + DELIM + "http://www.w3.org/2000/01/rdf-schema#label" + DELIM + "uri:dog";
    String s2 = "predicateobject" + DELIM + "uri:barksAt" + DELIM + "uri:cat";
    String s3 = "predicateobject" + DELIM + "uri:peesOn" + DELIM + "uri:hydrant";
    List<Mutation> mList = new ArrayList<Mutation>();
    List<Mutation> mList2 = new ArrayList<Mutation>();
    List<String> sList = Arrays.asList("subjectobject", "subjectpredicate", "subjectsubject", "predicateobject", "predicatepredicate", "predicatesubject");
    Mutation m1, m2, m3, m4;
    m1 = new Mutation(s1 + DELIM + "1");
    m1.put(new Text("count"), new Text(""), new Value("1".getBytes()));
    m2 = new Mutation(s2 + DELIM + "2");
    m2.put(new Text("count"), new Text(""), new Value("2".getBytes()));
    m3 = new Mutation(s3 + DELIM + "3");
    m3.put(new Text("count"), new Text(""), new Value("3".getBytes()));
    mList.add(m1);
    mList.add(m2);
    mList.add(m3);
    bw1.addMutations(mList);
    bw1.close();
    // Scanner scan = conn.createScanner("rya_prospects", new Authorizations());
    // scan.setRange(new Range());
    // for (Map.Entry<Key, Value> entry : scan) {
    // System.out.println("Key row string is " + entry.getKey().getRow().toString());
    // System.out.println("Key is " + entry.getKey());
    // System.out.println("Value is " + (new String(entry.getValue().get())));
    // }
    m1 = new Mutation(s1);
    m2 = new Mutation(s2);
    m3 = new Mutation(s3);
    m4 = new Mutation(new Text("subjectpredicateobject" + DELIM + "FullTableCardinality"));
    m4.put(new Text("FullTableCardinality"), new Text("100"), EMPTY_VAL);
    int i = 2;
    int j = 3;
    int k = 4;
    Long count1;
    Long count2;
    Long count3;
    for (String s : sList) {
        count1 = (long) i;
        count2 = (long) j;
        count3 = (long) k;
        m1.put(new Text(s), new Text(count1.toString()), EMPTY_VAL);
        m2.put(new Text(s), new Text(count2.toString()), EMPTY_VAL);
        m3.put(new Text(s), new Text(count3.toString()), EMPTY_VAL);
        i = 2 * i;
        j = 2 * j;
        k = 2 * k;
    }
    mList2.add(m1);
    mList2.add(m2);
    mList2.add(m3);
    mList2.add(m4);
    bw2.addMutations(mList2);
    bw2.close();
    // scan = conn.createScanner("rya_selectivity", new Authorizations());
    // scan.setRange(new Range());
    // for (Map.Entry<Key, Value> entry : scan) {
    // System.out.println("Key row string is " + entry.getKey().getRow().toString());
    // System.out.println("Key is " + entry.getKey());
    // System.out.println("Value is " + (new String(entry.getKey().getColumnQualifier().toString())));
    // 
    // }
    TupleExpr te = getTupleExpr(q1);
    System.out.println(te);
    RdfCloudTripleStoreSelectivityEvaluationStatistics ars = new RdfCloudTripleStoreSelectivityEvaluationStatistics(arc, res, accc);
    double card = ars.getCardinality(te);
    Assert.assertEquals(6.3136, card, .0001);
}
Also used : ProspectorServiceEvalStatsDAO(org.apache.rya.prospector.service.ProspectorServiceEvalStatsDAO) ArrayList(java.util.ArrayList) AccumuloSelectivityEvalDAO(org.apache.rya.joinselect.AccumuloSelectivityEvalDAO) Text(org.apache.hadoop.io.Text) TupleExpr(org.openrdf.query.algebra.TupleExpr) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) Test(org.junit.Test)

Example 19 with RdfCloudTripleStoreConfiguration

use of org.apache.rya.api.RdfCloudTripleStoreConfiguration in project incubator-rya by apache.

the class ReflexivePropertyVisitorTest method testReflexivePropertyDisabled.

@Test
public void testReflexivePropertyDisabled() throws Exception {
    // Disable inference
    final RdfCloudTripleStoreConfiguration disabledConf = conf.clone();
    disabledConf.setInferReflexiveProperty(false);
    // Define a reflexive property
    final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
    when(inferenceEngine.isReflexiveProperty(HAS_FAMILY)).thenReturn(true);
    // Construct a query, then make a copy and visit the copy
    final Projection query = new Projection(new StatementPattern(new Var("s", ALICE), new Var("p", HAS_FAMILY), new Var("o")), new ProjectionElemList(new ProjectionElem("s", "subject")));
    final Projection modifiedQuery = query.clone();
    modifiedQuery.visit(new ReflexivePropertyVisitor(disabledConf, inferenceEngine));
    // There should be no difference
    Assert.assertEquals(query, modifiedQuery);
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) Projection(org.openrdf.query.algebra.Projection) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 20 with RdfCloudTripleStoreConfiguration

use of org.apache.rya.api.RdfCloudTripleStoreConfiguration in project incubator-rya by apache.

the class AccumuloRyaQueryEngine method query.

@Override
public CloseableIterable<RyaStatement> query(BatchRyaQuery ryaQuery) throws RyaDAOException {
    Preconditions.checkNotNull(ryaQuery);
    Iterable<RyaStatement> stmts = ryaQuery.getQueries();
    Preconditions.checkNotNull(stmts);
    // query configuration
    String[] auths = ryaQuery.getAuths();
    final Authorizations authorizations = auths != null ? new Authorizations(auths) : configuration.getAuthorizations();
    final Long ttl = ryaQuery.getTtl();
    Long currentTime = ryaQuery.getCurrentTime();
    Long maxResults = ryaQuery.getMaxResults();
    Integer batchSize = ryaQuery.getBatchSize();
    Integer numQueryThreads = ryaQuery.getNumQueryThreads();
    String regexSubject = ryaQuery.getRegexSubject();
    String regexPredicate = ryaQuery.getRegexPredicate();
    String regexObject = ryaQuery.getRegexObject();
    TableLayoutStrategy tableLayoutStrategy = configuration.getTableLayoutStrategy();
    int maxRanges = ryaQuery.getMaxRanges();
    // TODO: cannot span multiple tables here
    try {
        Collection<Range> ranges = new HashSet<Range>();
        TABLE_LAYOUT layout = null;
        RyaURI context = null;
        TriplePatternStrategy strategy = null;
        for (RyaStatement stmt : stmts) {
            // TODO: This will be overwritten
            context = stmt.getContext();
            strategy = ryaContext.retrieveStrategy(stmt);
            if (strategy == null) {
                throw new IllegalArgumentException("TriplePattern[" + stmt + "] not supported");
            }
            Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = 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();
            Range range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd()));
            ranges.add(range);
        }
        // no ranges
        if (layout == null || strategy == null)
            throw new IllegalArgumentException("No table layout specified, or no statements.");
        final TripleRowRegex tripleRowRegex = strategy.buildRegex(regexSubject, regexPredicate, regexObject, null, null);
        final String table = layoutToTable(layout, tableLayoutStrategy);
        boolean useBatchScanner = ranges.size() > maxRanges;
        FluentCloseableIterable<RyaStatement> results = null;
        if (useBatchScanner) {
            BatchScanner scanner = connector.createBatchScanner(table, authorizations, numQueryThreads);
            scanner.setRanges(ranges);
            fillScanner(scanner, context, null, ttl, null, tripleRowRegex, ryaQuery.getConf());
            results = FluentCloseableIterable.from(new ScannerBaseCloseableIterable(scanner)).transform(keyValueToRyaStatementFunctionMap.get(layout));
        } else {
            final RyaURI fcontext = context;
            final RdfCloudTripleStoreConfiguration fconf = ryaQuery.getConf();
            FluentIterable<RyaStatement> fluent = FluentIterable.from(ranges).transformAndConcat(new Function<Range, Iterable<Map.Entry<Key, Value>>>() {

                @Override
                public Iterable<Map.Entry<Key, Value>> apply(Range range) {
                    try {
                        Scanner scanner = connector.createScanner(table, authorizations);
                        scanner.setRange(range);
                        fillScanner(scanner, fcontext, null, ttl, null, tripleRowRegex, fconf);
                        return scanner;
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }).transform(keyValueToRyaStatementFunctionMap.get(layout));
            results = FluentCloseableIterable.from(CloseableIterables.wrap(fluent));
        }
        if (maxResults != null) {
            results = results.limit(maxResults.intValue());
        }
        return results;
    } catch (Exception e) {
        throw new RyaDAOException(e);
    }
}
Also used : BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) ByteRange(org.apache.rya.api.query.strategy.ByteRange) BatchScanner(org.apache.accumulo.core.client.BatchScanner) RyaStatement(org.apache.rya.api.domain.RyaStatement) Function(com.google.common.base.Function) TripleRowRegex(org.apache.rya.api.resolver.triple.TripleRowRegex) HashSet(java.util.HashSet) TableLayoutStrategy(org.apache.rya.api.layout.TableLayoutStrategy) Authorizations(org.apache.accumulo.core.security.Authorizations) TriplePatternStrategy(org.apache.rya.api.query.strategy.TriplePatternStrategy) Text(org.apache.hadoop.io.Text) RyaRange(org.apache.rya.api.domain.RyaRange) Range(org.apache.accumulo.core.data.Range) ByteRange(org.apache.rya.api.query.strategy.ByteRange) IOException(java.io.IOException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) RyaURI(org.apache.rya.api.domain.RyaURI) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RdfCloudTripleStoreConfiguration (org.apache.rya.api.RdfCloudTripleStoreConfiguration)20 Test (org.junit.Test)10 Map (java.util.Map)9 Text (org.apache.hadoop.io.Text)9 AccumuloSelectivityEvalDAO (org.apache.rya.joinselect.AccumuloSelectivityEvalDAO)9 ProspectorServiceEvalStatsDAO (org.apache.rya.prospector.service.ProspectorServiceEvalStatsDAO)9 ArrayList (java.util.ArrayList)8 BatchWriter (org.apache.accumulo.core.client.BatchWriter)8 Mutation (org.apache.accumulo.core.data.Mutation)8 Value (org.apache.accumulo.core.data.Value)8 Authorizations (org.apache.accumulo.core.security.Authorizations)8 TupleExpr (org.openrdf.query.algebra.TupleExpr)8 Scanner (org.apache.accumulo.core.client.Scanner)7 Range (org.apache.accumulo.core.data.Range)7 Key (org.apache.accumulo.core.data.Key)6 QueryJoinSelectOptimizer (org.apache.rya.rdftriplestore.evaluation.QueryJoinSelectOptimizer)6 RdfCloudTripleStoreSelectivityEvaluationStatistics (org.apache.rya.rdftriplestore.evaluation.RdfCloudTripleStoreSelectivityEvaluationStatistics)6 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)5 RyaURI (org.apache.rya.api.domain.RyaURI)4 HashSet (java.util.HashSet)3