use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class RyaOutputFormatTest method testEntityIndexing.
@Test
public void testEntityIndexing() throws Exception {
final EntityCentricIndex entity = new EntityCentricIndex();
entity.setConf(conf);
final RyaStatement input = RyaStatement.builder().setSubject(new RyaURI(GRAPH + ":s")).setPredicate(new RyaURI(GRAPH + ":p")).setObject(new RyaURI(GRAPH + ":o")).build();
RyaOutputFormat.setCoreTablesEnabled(job, false);
RyaOutputFormat.setFreeTextEnabled(job, false);
RyaOutputFormat.setTemporalEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, true);
write(input);
entity.close();
final Set<Statement> expected = new HashSet<>();
final Set<Statement> inserted = new HashSet<>();
expected.add(RyaToRdfConversions.convertStatement(input));
final String table = EntityCentricIndex.getTableName(conf);
final Scanner scanner = connector.createScanner(table, new Authorizations(CV));
for (final Map.Entry<Key, Value> row : scanner) {
System.out.println(row);
inserted.add(RyaToRdfConversions.convertStatement(EntityCentricIndex.deserializeStatement(row.getKey(), row.getValue())));
}
Assert.assertEquals(expected, inserted);
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class RyaOutputFormatTest method write.
private void write(final RyaStatement... input) throws IOException, InterruptedException {
final RecordWriter<Writable, RyaStatementWritable> writer = new RyaOutputFormat.RyaRecordWriter(job.getConfiguration());
for (final RyaStatement rstmt : input) {
final RyaStatementWritable rsw = new RyaStatementWritable(rstmt, ryaContext);
writer.write(new Text("unused"), rsw);
}
writer.close(null);
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class RyaOutputFormatTest method testOutputFormat.
@Test
public void testOutputFormat() throws Exception {
final 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(CV.getBytes()).setValue(new byte[0]).setContext(new RyaURI(GRAPH)).build();
RyaOutputFormat.setCoreTablesEnabled(job, true);
RyaOutputFormat.setFreeTextEnabled(job, false);
RyaOutputFormat.setTemporalEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, false);
write(input);
TestUtils.verify(connector, conf, input);
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class RyaOutputFormatTest method testFreeTextIndexing.
@Test
public void testFreeTextIndexing() throws Exception {
final AccumuloFreeTextIndexer ft = new AccumuloFreeTextIndexer();
ft.setConf(conf);
final RyaStatement input = RyaStatement.builder().setSubject(new RyaURI(GRAPH + ":s")).setPredicate(new RyaURI(GRAPH + ":p")).setObject(new RyaType(XMLSchema.STRING, "one two three four five")).build();
RyaOutputFormat.setCoreTablesEnabled(job, false);
RyaOutputFormat.setFreeTextEnabled(job, true);
RyaOutputFormat.setTemporalEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, false);
write(input);
final Set<Statement> empty = new HashSet<>();
final Set<Statement> expected = new HashSet<>();
expected.add(RyaToRdfConversions.convertStatement(input));
Assert.assertEquals(expected, getSet(ft.queryText("one", new StatementConstraints())));
Assert.assertEquals(empty, getSet(ft.queryText("!two", new StatementConstraints())));
Assert.assertEquals(expected, getSet(ft.queryText("*r", new StatementConstraints())));
Assert.assertEquals(empty, getSet(ft.queryText("r*", new StatementConstraints())));
Assert.assertEquals(expected, getSet(ft.queryText("!r*", new StatementConstraints())));
Assert.assertEquals(expected, getSet(ft.queryText("t* & !s*", new StatementConstraints())));
ft.close();
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class GraphXInputFormatTest 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();
GraphXInputFormat.setMockInstance(jobConf, instance.getInstanceName());
GraphXInputFormat.setConnectorInfo(jobConf, username, password);
GraphXInputFormat.setInputTableName(jobConf, table);
GraphXInputFormat.setInputTableName(jobConf, table);
GraphXInputFormat.setScanIsolation(jobConf, false);
GraphXInputFormat.setLocalIterators(jobConf, false);
GraphXInputFormat.setOfflineTableScan(jobConf, false);
GraphXInputFormat inputFormat = new GraphXInputFormat();
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<Object, RyaTypeWritable> reader = inputFormat.createRecordReader(splits.get(0), taskAttemptContext);
RyaStatementRecordReader ryaStatementRecordReader = (RyaStatementRecordReader) reader;
ryaStatementRecordReader.initialize(splits.get(0), taskAttemptContext);
List<RyaType> results = new ArrayList<RyaType>();
System.out.println("before while");
while (ryaStatementRecordReader.nextKeyValue()) {
System.out.println("in while");
RyaTypeWritable writable = ryaStatementRecordReader.getCurrentValue();
RyaType value = writable.getRyaType();
Object text = ryaStatementRecordReader.getCurrentKey();
RyaType type = new RyaType();
type.setData(value.getData());
type.setDataType(value.getDataType());
results.add(type);
System.out.println(value.getData());
System.out.println(value.getDataType());
System.out.println(results);
System.out.println(type);
System.out.println(text);
System.out.println(value);
}
System.out.println("after while");
System.out.println(results.size());
System.out.println(results);
// Assert.assertTrue(results.size() == 2);
// Assert.assertTrue(results.contains(input));
}
Aggregations