use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class RyaDirectExample method createPCJ.
// private static void testDeleteGeoData(final SailRepositoryConnection conn)
// throws Exception {
// // Delete all stored points
// final String sparqlDelete = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
// + "DELETE {\n" //
// + " ?feature a geo:Feature . "//
// + " ?feature geo:hasGeometry ?point . "//
// + " ?point a geo:Point . "//
// + " ?point geo:asWKT ?wkt . "//
// + "}\n" + "WHERE { \n" + " ?feature a geo:Feature . "//
// + " ?feature geo:hasGeometry ?point . "//
// + " ?point a geo:Point . "//
// + " ?point geo:asWKT ?wkt . "//
// + "}";//
//
// final Update deleteUpdate = conn.prepareUpdate(QueryLanguage.SPARQL,
// sparqlDelete);
// deleteUpdate.execute();
//
// String queryString;
// TupleQuery tupleQuery;
// CountingResultHandler tupleHandler;
//
// // Find all stored points
// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
// + "SELECT ?feature ?point ?wkt " //
// + "{" //
// + " ?feature a geo:Feature . "//
// + " ?feature geo:hasGeometry ?point . "//
// + " ?point a geo:Point . "//
// + " ?point geo:asWKT ?wkt . "//
// + "}";//
// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
// tupleHandler = new CountingResultHandler();
// tupleQuery.evaluate(tupleHandler);
// log.info("Result count : " + tupleHandler.getCount());
// Validate.isTrue(tupleHandler.getCount() == 0);
// }
private static void createPCJ(final Configuration conf) throws RepositoryException, AccumuloException, AccumuloSecurityException, TableExistsException, PcjException, InferenceEngineException, NumberFormatException, UnknownHostException, SailException, TableNotFoundException {
final Configuration config = new AccumuloRdfConfiguration(conf);
config.set(ConfigUtils.USE_PCJ, "false");
SailRepository repository = null;
SailRepositoryConnection conn = null;
try {
final Sail extSail = RyaSailFactory.getInstance(config);
repository = new SailRepository(extSail);
conn = repository.getConnection();
final String queryString1 = //
"" + //
"SELECT ?e ?c ?l ?o " + //
"{" + //
" ?c a ?e . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e <uri:talksTo> ?o . " + //
"}";
final String queryString2 = //
"" + //
"SELECT ?e ?c ?l ?o " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e <uri:talksTo> ?o . " + //
"}";
URI obj, subclass, talksTo;
final URI person = new URIImpl("urn:people:alice");
final URI feature = new URIImpl("urn:feature");
final URI sub = new URIImpl("uri:entity");
subclass = new URIImpl("uri:class");
obj = new URIImpl("uri:obj");
talksTo = new URIImpl("uri:talksTo");
conn.add(person, RDF.TYPE, sub);
conn.add(feature, RDF.TYPE, sub);
conn.add(sub, RDF.TYPE, subclass);
conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
conn.add(sub, talksTo, obj);
final String tablename1 = RYA_TABLE_PREFIX + "INDEX_1";
final String tablename2 = RYA_TABLE_PREFIX + "INDEX_2";
final Connector accCon = new MockInstance(INSTANCE).getConnector("root", new PasswordToken("".getBytes(StandardCharsets.UTF_8)));
new PcjTables().createAndPopulatePcj(conn, accCon, tablename1, queryString1, new String[] { "e", "c", "l", "o" }, Optional.<PcjVarOrderFactory>absent());
new PcjTables().createAndPopulatePcj(conn, accCon, tablename2, queryString2, new String[] { "e", "c", "l", "o" }, Optional.<PcjVarOrderFactory>absent());
} catch (final RyaDAOException e) {
throw new Error("While creating PCJ tables.", e);
} finally {
closeQuietly(conn);
closeQuietly(repository);
}
}
use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class JoinSelectStatisticsTest method init.
@Before
public void init() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
MockInstance mockInstance = new MockInstance(INSTANCE_NAME);
c = mockInstance.getConnector("root", new PasswordToken(""));
if (c.tableOperations().exists("rya_prospects")) {
c.tableOperations().delete("rya_prospects");
}
if (c.tableOperations().exists("rya_selectivity")) {
c.tableOperations().delete("rya_selectivity");
}
if (c.tableOperations().exists("rya_spo")) {
c.tableOperations().delete("rya_spo");
}
c.tableOperations().create("rya_spo");
c.tableOperations().create("rya_prospects");
c.tableOperations().create("rya_selectivity");
ryaContext = RyaTripleContext.getInstance(new AccumuloRdfConfiguration(getConfig()));
}
use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class ProspectorServiceEvalStatsDAOTest method testNoAuthsCount.
@Test
public void testNoAuthsCount() throws Exception {
// Load some data into a mock Accumulo and run the Prospector MapReduce job.
final Instance mock = new MockInstance("accumulo");
final Connector connector = mock.getConnector("user", new PasswordToken("pass"));
final String outtable = "rya_prospects";
if (connector.tableOperations().exists(outtable)) {
connector.tableOperations().delete(outtable);
}
connector.tableOperations().create(outtable);
connector.securityOperations().createUser("user", "pass".getBytes(), new Authorizations("U", "FOUO"));
final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
ryaDAO.setConnector(connector);
ryaDAO.init();
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1")));
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2")));
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12")));
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12")));
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12")));
final String confFile = "stats_cluster_config.xml";
final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString());
final String[] args = { confPath.toString() };
ToolRunner.run(new Prospector(), args);
ryaDAO.destroy();
final Configuration conf = new Configuration();
conf.addResource(confPath);
final AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(conf);
final ProspectorServiceEvalStatsDAO evalDao = new ProspectorServiceEvalStatsDAO(connector, rdfConf);
evalDao.init();
// Get the cardinality of the 'urn:gem#pred' predicate.
List<Value> values = new ArrayList<Value>();
values.add(new URIImpl("urn:gem#pred"));
double count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.PREDICATE, values);
assertEquals(4.0, count, 0.001);
// Get the cardinality of the 'mydata1' object.
values = new ArrayList<Value>();
values.add(new LiteralImpl("mydata1"));
count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values);
assertEquals(1.0, count, 0.001);
// Get the cardinality of the 'mydata3' object.
values = new ArrayList<Value>();
values.add(new LiteralImpl("mydata3"));
count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values);
assertEquals(-1.0, count, 0.001);
}
use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class ProspectorServiceEvalStatsDAOTest method testCount.
@Test
public void testCount() throws Exception {
// Load some data into a mock Accumulo and run the Prospector MapReduce job.
final Instance mock = new MockInstance("accumulo");
final Connector connector = mock.getConnector("user", new PasswordToken("pass"));
final String outtable = "rya_prospects";
if (connector.tableOperations().exists(outtable)) {
connector.tableOperations().delete(outtable);
}
connector.tableOperations().create(outtable);
final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
ryaDAO.setConnector(connector);
ryaDAO.init();
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1")));
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2")));
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12")));
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12")));
ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12")));
final String confFile = "stats_cluster_config.xml";
final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString());
final String[] args = { confPath.toString() };
ToolRunner.run(new Prospector(), args);
ryaDAO.destroy();
final Configuration conf = new Configuration();
conf.addResource(confPath);
final AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(conf);
rdfConf.setAuths("U", "FOUO");
final ProspectorServiceEvalStatsDAO evalDao = new ProspectorServiceEvalStatsDAO(connector, rdfConf);
evalDao.init();
// Get the cardinality of the 'urn:gem#pred' predicate.
List<Value> values = new ArrayList<Value>();
values.add(new URIImpl("urn:gem#pred"));
double count = evalDao.getCardinality(rdfConf, CARDINALITY_OF.PREDICATE, values);
assertEquals(4.0, count, 0.001);
// Get the cardinality of the 'mydata1' object.
values = new ArrayList<Value>();
values.add(new LiteralImpl("mydata1"));
count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values);
assertEquals(1.0, count, 0.001);
// Get the cardinality of the 'mydata3' object.
values = new ArrayList<Value>();
values.add(new LiteralImpl("mydata3"));
count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values);
assertEquals(-1.0, count, 0.001);
}
use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class AccumuloSelectivityEvalDAOTest method init.
@Before
public void init() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
mock = new MockInstance("accumulo");
PasswordToken pToken = new PasswordToken("pass".getBytes());
conn = mock.getConnector("user", pToken);
config = new BatchWriterConfig();
config.setMaxMemory(1000);
config.setMaxLatency(1000, TimeUnit.SECONDS);
config.setMaxWriteThreads(10);
if (conn.tableOperations().exists("rya_prospects")) {
conn.tableOperations().delete("rya_prospects");
}
if (conn.tableOperations().exists("rya_selectivity")) {
conn.tableOperations().delete("rya_selectivity");
}
arc = new AccumuloRdfConfiguration();
res = new ProspectorServiceEvalStatsDAO(conn, arc);
arc.setTableLayoutStrategy(new TablePrefixLayoutStrategy());
arc.setMaxRangesForScanner(300);
}
Aggregations