Java 类org.apache.hadoop.io.MapFile.Reader 实例源码

项目:hadoop-in-action    文件:LookupRecordByTemperature.java   
@Override
public int run(String[] args) throws Exception {
    if (args.length != 2) {
        JobBuilder.printUsage(this, "<path> <key>");
        return -1;
    }
    Path path = new Path(args[0]);
    IntWritable key = new IntWritable(Integer.parseInt(args[1]));

    Reader[] readers = MapFileOutputFormat.getReaders(path, getConf());
    Partitioner<IntWritable, Text> partitioner = new HashPartitioner<IntWritable, Text>();
    Text val = new Text();
    Writable entry = MapFileOutputFormat.getEntry(readers, partitioner,
            key, val);
    if (entry == null) {
        System.err.println("Key not found: " + key);
        return -1;
    }
    NcdcRecordParser parser = new NcdcRecordParser();
    parser.parse(val.toString());
    System.out.printf("%s\t%s\n", parser.getStationId(), parser.getYear());
    return 0;
}
项目:aliyun-oss-hadoop-fs    文件:TestMapFileOutputFormat.java   
@SuppressWarnings("static-access")
@Test
public void testPartitionerShouldNotBeCalledWhenOneReducerIsPresent()
    throws Exception {
  MapFileOutputFormat outputFormat = new MapFileOutputFormat();
  Reader reader = Mockito.mock(Reader.class);
  Reader[] readers = new Reader[]{reader};
  outputFormat.getEntry(readers, new MyPartitioner(), new Text(), new Text());
  assertTrue(!MyPartitioner.isGetPartitionCalled());
}
项目:aliyun-oss-hadoop-fs    文件:TestMapFileOutputFormat.java   
@SuppressWarnings("static-access")
@Test
public void testPartitionerShouldNotBeCalledWhenOneReducerIsPresent()
    throws Exception {
  MapFileOutputFormat outputFormat = new MapFileOutputFormat();
  Reader reader = Mockito.mock(Reader.class);
  Reader[] readers = new Reader[]{reader};
  outputFormat.getEntry(readers, new MyPartitioner(), new Text(), new Text());
  assertTrue(!MyPartitioner.isGetPartitionCalled());
}
项目:hadoop-in-action    文件:LookupRecordsByTemperature.java   
@Override
public int run(String[] args) throws Exception {
    if (args.length != 2) {
        JobBuilder.printUsage(this, "<path> <key>");
        return -1;
    }
    Path path = new Path(args[0]);
    IntWritable key = new IntWritable(Integer.parseInt(args[1]));

    Reader[] readers = MapFileOutputFormat.getReaders(path, getConf());
    Partitioner<IntWritable, Text> partitioner = new HashPartitioner<IntWritable, Text>();
    Text val = new Text();

    Reader reader = readers[partitioner.getPartition(key, val,
            readers.length)];
    Writable entry = reader.get(key, val);
    if (entry == null) {
        System.err.println("Key not found: " + key);
        return -1;
    }
    NcdcRecordParser parser = new NcdcRecordParser();
    IntWritable nextKey = new IntWritable();
    do {
        parser.parse(val.toString());
        System.out.printf("%s\t%s\n", parser.getStationId(),
                parser.getYear());
    } while (reader.next(nextKey, val) && key.equals(nextKey));
    return 0;
}
项目:mrgeo    文件:MapFileReaderBuilder.java   
public MapFileReaderBuilder()
{
  mapFileReader = mock(Reader.class);
  keyValueHelper = new KeyValueHelper();
}