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;
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations