use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class ConstructQueryResultUpdater method updateConstructQueryResults.
/**
* Updates the Construct Query results by applying the {@link ConnstructGraph} to
* create a {@link RyaSubGraph} and then writing the subgraph to {@link FluoQueryColumns#CONSTRUCT_STATEMENTS}.
* @param tx - transaction used to write the subgraph
* @param bs - BindingSet that the ConstructProjection expands into a subgraph
* @param metadata - metadata that the ConstructProjection is extracted from
*/
public void updateConstructQueryResults(TransactionBase tx, VisibilityBindingSet bs, ConstructQueryMetadata metadata) {
String nodeId = metadata.getNodeId();
VariableOrder varOrder = metadata.getVariableOrder();
Column column = FluoQueryColumns.CONSTRUCT_STATEMENTS;
ConstructGraph graph = metadata.getConstructGraph();
String parentId = metadata.getParentNodeId();
// Create the Row Key for the emitted binding set. It does not contain visibilities.
final Bytes resultRow = makeRowKey(nodeId, varOrder, bs);
// If this is a new binding set, then emit it.
if (tx.get(resultRow, column) == null || varOrder.getVariableOrders().size() < bs.size()) {
Set<RyaStatement> statements = graph.createGraphFromBindingSet(bs);
RyaSubGraph subgraph = new RyaSubGraph(parentId, statements);
final Bytes nodeValueBytes = Bytes.of(serializer.toBytes(subgraph));
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Binding Set: " + subgraph + "\n");
tx.set(resultRow, column, nodeValueBytes);
}
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class JoinSelectMapperTest method testOutput.
@Test
public void testOutput() throws TripleRowResolverException, IOException {
RyaStatement rya = new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1"));
Text s = new Text(rya.getSubject().getData());
Text p = new Text(rya.getPredicate().getData());
Text o = new Text(rya.getObject().getData());
Text sp = new Text(rya.getSubject().getData() + DELIM + rya.getPredicate().getData());
Text so = new Text(rya.getSubject().getData() + DELIM + rya.getObject().getData());
Text po = new Text(rya.getPredicate().getData() + DELIM + rya.getObject().getData());
Text ps = new Text(rya.getPredicate().getData() + DELIM + rya.getSubject().getData());
Text op = new Text(rya.getObject().getData() + DELIM + rya.getPredicate().getData());
Text os = new Text(rya.getObject().getData() + DELIM + rya.getSubject().getData());
TripleEntry t1 = new TripleEntry(s, p, new Text("subject"), new Text("predicate"), new Text("object"));
TripleEntry t2 = new TripleEntry(p, o, new Text("predicate"), new Text("object"), new Text("subject"));
TripleEntry t3 = new TripleEntry(o, s, new Text("object"), new Text("subject"), new Text("predicate"));
TripleEntry t4 = new TripleEntry(o, new Text(""), new Text("object"), new Text(""), new Text("subjectpredicate"));
TripleEntry t5 = new TripleEntry(p, new Text(""), new Text("predicate"), new Text(""), new Text("objectsubject"));
TripleEntry t6 = new TripleEntry(s, new Text(""), new Text("subject"), new Text(""), new Text("predicateobject"));
TripleEntry t7 = new TripleEntry(s, new Text(""), new Text("subject"), new Text(""), new Text("objectpredicate"));
TripleEntry t8 = new TripleEntry(p, new Text(""), new Text("predicate"), new Text(""), new Text("subjectobject"));
TripleEntry t9 = new TripleEntry(o, new Text(""), new Text("object"), new Text(""), new Text("predicatesubject"));
TripleRowResolver trr = new WholeRowTripleResolver();
Map<TABLE_LAYOUT, TripleRow> map = trr.serialize(rya);
System.out.println(map);
TripleRow tr = map.get(TABLE_LAYOUT.SPO);
System.out.println("Triple row is" + tr);
System.out.println("ColumnV is " + tr.getTimestamp());
byte[] b = new byte[0];
Key key = new Key(tr.getRow(), tr.getColumnFamily(), tr.getColumnQualifier(), b, 1);
Value val = new Value(b);
new MapDriver<Key, Value, CompositeType, TripleCard>().withMapper(new JoinSelectSpoTableOutput.JoinSelectMapper()).withInput(key, val).withOutput(new CompositeType(o, new IntWritable(2)), new TripleCard(t1)).withOutput(new CompositeType(s, new IntWritable(2)), new TripleCard(t2)).withOutput(new CompositeType(p, new IntWritable(2)), new TripleCard(t3)).withOutput(new CompositeType(po, new IntWritable(2)), new TripleCard(t6)).withOutput(new CompositeType(so, new IntWritable(2)), new TripleCard(t5)).withOutput(new CompositeType(sp, new IntWritable(2)), new TripleCard(t4)).withOutput(new CompositeType(op, new IntWritable(2)), new TripleCard(t7)).withOutput(new CompositeType(os, new IntWritable(2)), new TripleCard(t8)).withOutput(new CompositeType(ps, new IntWritable(2)), new TripleCard(t9)).runTest();
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class JoinSelectStatisticsTest method testMap3.
@Test
public void testMap3() throws Exception {
init();
System.out.println("*************************Test3**************************** ");
BatchWriter bw_table1 = c.createBatchWriter("rya_spo", new BatchWriterConfig());
for (int i = 1; i < 3; i++) {
for (int j = 1; j < 3; j++) {
for (int k = 1; k < 3; k++) {
RyaStatement rs = new RyaStatement(new RyaURI(uri + i), new RyaURI(uri + (j)), new RyaType(uri + k));
Map<TABLE_LAYOUT, TripleRow> tripleRowMap = ryaContext.serializeTriple(rs);
TripleRow tripleRow = tripleRowMap.get(TABLE_LAYOUT.SPO);
Mutation m = JoinSelectStatsUtil.createMutation(tripleRow);
bw_table1.addMutation(m);
}
}
}
bw_table1.close();
BatchWriter bw_table2 = c.createBatchWriter("rya_prospects", new BatchWriterConfig());
for (int i = 1; i < 3; i++) {
int k = 1;
for (String s : cardList) {
Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + i));
m.put(new Text(), new Text(), new Value(new IntWritable(i + k).toString().getBytes()));
bw_table2.addMutation(m);
k++;
}
for (int j = 1; j < 3; j++) {
k = 1;
for (String s : aggCardList) {
Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + uri + j + DELIM + i));
m.put(new Text(), new Text(), new Value(new IntWritable(i + k + j).toString().getBytes()));
bw_table2.addMutation(m);
k++;
}
}
}
bw_table2.close();
Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[] { "" }));
Scanner scan = c.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("Join type is " + entry.getKey().getColumnFamily().toString());
System.out.println("Value is " + entry.getKey().getColumnQualifier().toString());
}
Scanner scan1 = c.createScanner("rya_selectivity", new Authorizations());
scan1.setRange(Range.prefix("subject" + DELIM + uri + 1));
int i = 0;
for (Map.Entry<Key, Value> entry : scan1) {
Key key = entry.getKey();
String s = key.getColumnFamily().toString();
int val = Integer.parseInt(key.getColumnQualifier().toString());
if (s.equals("predicatepredicate")) {
Assert.assertTrue(val == 14);
}
if (s.equals("objectobject")) {
Assert.assertTrue(val == 18);
}
if (s.equals("predicateobjectpredicateobject")) {
Assert.assertTrue(val == 28);
}
if (s.equals("predicateobjectsubjectpredicate")) {
Assert.assertTrue(val == 20);
}
if (s.equals("predicateobjectobjectsubject")) {
Assert.assertTrue(val == 16);
}
i++;
}
Assert.assertTrue(i == 12);
}
use of org.apache.rya.api.domain.RyaStatement 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.api.domain.RyaStatement 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);
}
Aggregations