use of org.apache.rya.accumulo.mr.RyaInputFormat.RyaStatementRecordReader 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));
}
Aggregations