use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class RyaInputFormatTest method testInputFormat.
@Test
public void testInputFormat() throws Exception {
RyaStatement input = RyaStatement.builder().setSubject(new RyaURI("http://www.google.com")).setPredicate(new RyaURI("http://some_other_uri")).setObject(new RyaURI("http://www.yahoo.com")).setColumnVisibility(new byte[0]).setValue(new byte[0]).build();
apiImpl.add(input);
Job jobConf = Job.getInstance();
RyaInputFormat.setMockInstance(jobConf, instance.getInstanceName());
RyaInputFormat.setConnectorInfo(jobConf, username, password);
RyaInputFormat.setTableLayout(jobConf, TABLE_LAYOUT.SPO);
AccumuloInputFormat.setInputTableName(jobConf, table);
AccumuloInputFormat.setInputTableName(jobConf, table);
AccumuloInputFormat.setScanIsolation(jobConf, false);
AccumuloInputFormat.setLocalIterators(jobConf, false);
AccumuloInputFormat.setOfflineTableScan(jobConf, false);
RyaInputFormat inputFormat = new RyaInputFormat();
JobContext context = new JobContextImpl(jobConf.getConfiguration(), jobConf.getJobID());
List<InputSplit> splits = inputFormat.getSplits(context);
Assert.assertEquals(1, splits.size());
TaskAttemptContext taskAttemptContext = new TaskAttemptContextImpl(context.getConfiguration(), new TaskAttemptID(new TaskID(), 1));
RecordReader<Text, RyaStatementWritable> reader = inputFormat.createRecordReader(splits.get(0), taskAttemptContext);
RyaStatementRecordReader ryaStatementRecordReader = (RyaStatementRecordReader) reader;
ryaStatementRecordReader.initialize(splits.get(0), taskAttemptContext);
List<RyaStatement> results = new ArrayList<RyaStatement>();
while (ryaStatementRecordReader.nextKeyValue()) {
RyaStatementWritable writable = ryaStatementRecordReader.getCurrentValue();
RyaStatement value = writable.getRyaStatement();
Text text = ryaStatementRecordReader.getCurrentKey();
RyaStatement stmt = RyaStatement.builder().setSubject(value.getSubject()).setPredicate(value.getPredicate()).setObject(value.getObject()).setContext(value.getContext()).setQualifier(value.getQualifer()).setColumnVisibility(value.getColumnVisibility()).setValue(value.getValue()).build();
results.add(stmt);
System.out.println(text);
System.out.println(value);
}
Assert.assertTrue(results.size() == 2);
Assert.assertTrue(results.contains(input));
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class AccumuloRdfCountToolTest method testMR.
@Test
public void testMR() throws Exception {
RyaURI test1 = RdfToRyaConversions.convertURI(vf.createURI(litdupsNS, "test1"));
RyaURI pred1 = RdfToRyaConversions.convertURI(vf.createURI(litdupsNS, "pred1"));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(0))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(1))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(2))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(3))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(4))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(5))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(6))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(7))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(8))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(9))));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(10))));
AccumuloRdfCountTool.main(new String[] { "-Dac.mock=true", "-Dac.instance=" + instance, "-Dac.username=" + user, "-Dac.pwd=" + pwd, "-Drdf.tablePrefix=" + tablePrefix });
Map<String, Key> expectedValues = new HashMap<String, Key>();
String row = test1.getData();
expectedValues.put(row, new Key(new Text(row), RdfCloudTripleStoreConstants.SUBJECT_CF_TXT, RdfCloudTripleStoreConstants.EMPTY_TEXT));
row = pred1.getData();
expectedValues.put(row, new Key(new Text(row), RdfCloudTripleStoreConstants.PRED_CF_TXT, RdfCloudTripleStoreConstants.EMPTY_TEXT));
Scanner scanner = connector.createScanner(tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX, auths);
scanner.setRange(new Range());
int count = 0;
for (Map.Entry<Key, Value> entry : scanner) {
assertTrue(expectedValues.get(entry.getKey().getRow().toString()).equals(entry.getKey(), PartialKey.ROW_COLFAM_COLQUAL));
assertEquals(11, Long.parseLong(entry.getValue().toString()));
count++;
}
assertEquals(2, count);
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class AccumuloRdfCountToolTest method testContext.
@Test
public void testContext() throws Exception {
RyaURI test1 = RdfToRyaConversions.convertURI(vf.createURI(litdupsNS, "test1"));
RyaURI pred1 = RdfToRyaConversions.convertURI(vf.createURI(litdupsNS, "pred1"));
RyaURI cntxt = RdfToRyaConversions.convertURI(vf.createURI(litdupsNS, "cntxt"));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(0)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(1)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(2)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(3)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(4)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(5)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(6)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(7)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(8)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(9)), cntxt));
dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(vf.createLiteral(10)), cntxt));
AccumuloRdfCountTool.main(new String[] { "-Dac.mock=true", "-Dac.instance=" + instance, "-Dac.username=" + user, "-Dac.pwd=" + pwd, "-Drdf.tablePrefix=" + tablePrefix });
Map<String, Key> expectedValues = new HashMap<String, Key>();
String row = test1.getData();
expectedValues.put(row, new Key(new Text(row), RdfCloudTripleStoreConstants.SUBJECT_CF_TXT, new Text(cntxt.getData())));
row = pred1.getData();
expectedValues.put(row, new Key(new Text(row), RdfCloudTripleStoreConstants.PRED_CF_TXT, new Text(cntxt.getData())));
Scanner scanner = connector.createScanner(tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX, auths);
scanner.setRange(new Range());
int count = 0;
for (Map.Entry<Key, Value> entry : scanner) {
assertTrue(expectedValues.get(entry.getKey().getRow().toString()).equals(entry.getKey(), PartialKey.ROW_COLFAM_COLQUAL));
assertEquals(11, Long.parseLong(entry.getValue().toString()));
count++;
}
assertEquals(2, count);
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class Upgrade322ToolTest method testUpgrade.
public void testUpgrade() throws Exception {
Upgrade322Tool.main(new String[] { "-Dac.mock=true", "-Dac.instance=" + instance, "-Dac.username=" + user, "-Dac.pwd=" + pwd, "-Drdf.tablePrefix=" + tablePrefix });
final AccumuloRdfConfiguration configuration = new AccumuloRdfConfiguration();
configuration.setTablePrefix(tablePrefix);
final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
ryaDAO.setConnector(connector);
ryaDAO.setConf(configuration);
ryaDAO.init();
final AccumuloRyaQueryEngine queryEngine = ryaDAO.getQueryEngine();
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#booleanLit"), new RyaType(XMLSchema.BOOLEAN, "true")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#longLit"), new RyaType(XMLSchema.LONG, "10")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#intLit"), new RyaType(XMLSchema.INTEGER, "10")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#byteLit"), new RyaType(XMLSchema.BYTE, "10")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#doubleLit"), new RyaType(XMLSchema.DOUBLE, "10.0")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#dateLit"), new RyaType(XMLSchema.DATETIME, "2011-07-12T06:00:00.000Z")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#stringLit"), new RyaType("stringLit")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#uriLit"), new RyaURI("http://here/2010/tracked-data-provenance/ns" + "#objectuuid1")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("urn:org.apache.rya/2012/05#rts"), new RyaURI("urn:org.apache.rya/2012/05#version"), new RyaType("3.0.0")), queryEngine);
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class RyaDaoQueryWrapper method queryAll.
/**
* Handles all results of a query. Closes the query iterator when done.
* @param ryaStatement the {@link RyaStatement} to query for.
* (not {@code null})
* @param rdfStatementHandler the {@link RDFHandler} to use for handling
* each statement returned. (not {@code null})
* @throws QueryEvaluationException
*/
public void queryAll(final RyaStatement ryaStatement, final RDFHandler rdfStatementHandler) throws QueryEvaluationException {
checkNotNull(ryaStatement);
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
queryAll(statement, rdfStatementHandler);
}
Aggregations