Search in sources :

Example 1 with MapReduceExtendedCell

use of org.apache.hadoop.hbase.util.MapReduceExtendedCell in project hbase by apache.

the class TestImportExport method testKeyValueImporter.

/**
 * Test map method of Importer
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testKeyValueImporter() throws Throwable {
    CellImporter importer = new CellImporter();
    Configuration configuration = new Configuration();
    Context ctx = mock(Context.class);
    when(ctx.getConfiguration()).thenReturn(configuration);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ImmutableBytesWritable writer = (ImmutableBytesWritable) invocation.getArgument(0);
            MapReduceExtendedCell key = (MapReduceExtendedCell) invocation.getArgument(1);
            assertEquals("Key", Bytes.toString(writer.get()));
            assertEquals("row", Bytes.toString(CellUtil.cloneRow(key)));
            return null;
        }
    }).when(ctx).write(any(), any());
    importer.setup(ctx);
    Result value = mock(Result.class);
    KeyValue[] keys = { new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("qualifier"), Bytes.toBytes("value")), new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("qualifier"), Bytes.toBytes("value1")) };
    when(value.rawCells()).thenReturn(keys);
    importer.map(new ImmutableBytesWritable(Bytes.toBytes("Key")), value, ctx);
}
Also used : Context(org.apache.hadoop.mapreduce.Mapper.Context) ObserverContext(org.apache.hadoop.hbase.coprocessor.ObserverContext) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) MapReduceExtendedCell(org.apache.hadoop.hbase.util.MapReduceExtendedCell) KeyValue(org.apache.hadoop.hbase.KeyValue) Configuration(org.apache.hadoop.conf.Configuration) Result(org.apache.hadoop.hbase.client.Result) CellImporter(org.apache.hadoop.hbase.mapreduce.Import.CellImporter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 2 with MapReduceExtendedCell

use of org.apache.hadoop.hbase.util.MapReduceExtendedCell in project hbase by apache.

the class CellSortReducer method reduce.

protected void reduce(ImmutableBytesWritable row, Iterable<Cell> kvs, Reducer<ImmutableBytesWritable, Cell, ImmutableBytesWritable, Cell>.Context context) throws java.io.IOException, InterruptedException {
    TreeSet<Cell> map = new TreeSet<>(CellComparator.getInstance());
    for (Cell kv : kvs) {
        try {
            map.add(PrivateCellUtil.deepClone(kv));
        } catch (CloneNotSupportedException e) {
            throw new IOException(e);
        }
    }
    context.setStatus("Read " + map.getClass());
    int index = 0;
    for (Cell kv : map) {
        context.write(row, new MapReduceExtendedCell(kv));
        if (++index % 100 == 0)
            context.setStatus("Wrote " + index);
    }
}
Also used : MapReduceExtendedCell(org.apache.hadoop.hbase.util.MapReduceExtendedCell) TreeSet(java.util.TreeSet) IOException(java.io.IOException) MapReduceExtendedCell(org.apache.hadoop.hbase.util.MapReduceExtendedCell) Cell(org.apache.hadoop.hbase.Cell)

Example 3 with MapReduceExtendedCell

use of org.apache.hadoop.hbase.util.MapReduceExtendedCell in project hbase by apache.

the class TestWALPlayer method testWALKeyValueMapper.

private void testWALKeyValueMapper(final String tableConfigKey) throws Exception {
    Configuration configuration = new Configuration();
    configuration.set(tableConfigKey, "table");
    WALKeyValueMapper mapper = new WALKeyValueMapper();
    WALKey key = mock(WALKey.class);
    when(key.getTableName()).thenReturn(TableName.valueOf("table"));
    @SuppressWarnings("unchecked") Mapper<WALKey, WALEdit, ImmutableBytesWritable, Cell>.Context context = mock(Context.class);
    when(context.getConfiguration()).thenReturn(configuration);
    WALEdit value = mock(WALEdit.class);
    ArrayList<Cell> values = new ArrayList<>();
    KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("family"), null);
    values.add(kv1);
    when(value.getCells()).thenReturn(values);
    mapper.setup(context);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ImmutableBytesWritable writer = (ImmutableBytesWritable) invocation.getArgument(0);
            MapReduceExtendedCell key = (MapReduceExtendedCell) invocation.getArgument(1);
            assertEquals("row", Bytes.toString(writer.get()));
            assertEquals("row", Bytes.toString(CellUtil.cloneRow(key)));
            return null;
        }
    }).when(context).write(any(), any());
    mapper.map(key, value, context);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) MapReduceExtendedCell(org.apache.hadoop.hbase.util.MapReduceExtendedCell) Configuration(org.apache.hadoop.conf.Configuration) ArrayList(java.util.ArrayList) WALKey(org.apache.hadoop.hbase.wal.WALKey) Mapper(org.apache.hadoop.mapreduce.Mapper) WALKeyValueMapper(org.apache.hadoop.hbase.mapreduce.WALPlayer.WALKeyValueMapper) WALEdit(org.apache.hadoop.hbase.wal.WALEdit) WALKeyValueMapper(org.apache.hadoop.hbase.mapreduce.WALPlayer.WALKeyValueMapper) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Cell(org.apache.hadoop.hbase.Cell) MapReduceExtendedCell(org.apache.hadoop.hbase.util.MapReduceExtendedCell)

Aggregations

MapReduceExtendedCell (org.apache.hadoop.hbase.util.MapReduceExtendedCell)3 Configuration (org.apache.hadoop.conf.Configuration)2 Cell (org.apache.hadoop.hbase.Cell)2 KeyValue (org.apache.hadoop.hbase.KeyValue)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 Result (org.apache.hadoop.hbase.client.Result)1 ObserverContext (org.apache.hadoop.hbase.coprocessor.ObserverContext)1 CellImporter (org.apache.hadoop.hbase.mapreduce.Import.CellImporter)1 WALKeyValueMapper (org.apache.hadoop.hbase.mapreduce.WALPlayer.WALKeyValueMapper)1 WALEdit (org.apache.hadoop.hbase.wal.WALEdit)1 WALKey (org.apache.hadoop.hbase.wal.WALKey)1 Mapper (org.apache.hadoop.mapreduce.Mapper)1 Context (org.apache.hadoop.mapreduce.Mapper.Context)1 Test (org.junit.Test)1