LuceneSegmentRecordReader extends RecordReader<Text, NullWritable> { @Override public void initialize(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException { LuceneSegmentInputSplit inputSplit = (LuceneSegmentInputSplit) split; Configuration configuration = context.getConfiguration(); LuceneStorageConfiguration lucene2SeqConfiguration = new LuceneStorageConfiguration(configuration); SegmentCommitInfo segmentInfo = inputSplit.getSegment(configuration); segmentReader = new SegmentReader(segmentInfo, USE_TERM_INFO, IOContext.READ); IndexSearcher searcher = new IndexSearcher(segmentReader); String idField = lucene2SeqConfiguration.getIdField(); LuceneIndexHelper.fieldShouldExistInIndex(segmentReader, idField); for (String field : lucene2SeqConfiguration.getFields()) { LuceneIndexHelper.fieldShouldExistInIndex(segmentReader, field); } Weight weight = lucene2SeqConfiguration.getQuery().createWeight(searcher); scorer = weight.scorer(segmentReader.getContext(), false, false, null); if (scorer == null) { throw new IllegalArgumentException("Could not create query scorer for query: " + lucene2SeqConfiguration.getQuery()); } }  @Override void initialize(InputSplit split, TaskAttemptContext context); @Override boolean nextKeyValue(); @Override Text getCurrentKey(); @Override NullWritable getCurrentValue(); @Override float getProgress(); @Override void close(); static final int USE_TERM_INFO; }
@Test(expected = IllegalArgumentException.class) public void testNonExistingIdField() throws Exception { configuration = new LuceneStorageConfiguration(getConfiguration(), asList(getIndexPath1()), new Path("output"), "nonExistingId", asList(FIELD)).serialize(); SegmentCommitInfo segmentInfo = segmentInfos.iterator().next(); LuceneSegmentInputSplit inputSplit = new LuceneSegmentInputSplit(getIndexPath1(), segmentInfo.info.name, segmentInfo.sizeInBytes()); TaskAttemptContext context = getTaskAttemptContext(configuration, new TaskAttemptID()); recordReader.initialize(inputSplit, context); }
@Test(expected = IllegalArgumentException.class) public void testNonExistingField() throws Exception { configuration = new LuceneStorageConfiguration(getConfiguration(), asList(getIndexPath1()), new Path("output"), ID_FIELD, asList("nonExistingField")).serialize(); SegmentCommitInfo segmentInfo = segmentInfos.iterator().next(); LuceneSegmentInputSplit inputSplit = new LuceneSegmentInputSplit(getIndexPath1(), segmentInfo.info.name, segmentInfo.sizeInBytes()); TaskAttemptContext context = getTaskAttemptContext(configuration, new TaskAttemptID()); recordReader.initialize(inputSplit, context); }