Java Code Examples for org.apache.hadoop.hbase.client.Result#getMap()

The following examples show how to use org.apache.hadoop.hbase.client.Result#getMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestMultithreadedTableMapper.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Pass the key, and reversed value to reduce
 *
 * @param key
 * @param value
 * @param context
 * @throws IOException
 */
@Override
public void map(ImmutableBytesWritable key, Result value,
    Context context)
        throws IOException, InterruptedException {
  if (value.size() != 1) {
    throw new IOException("There should only be one input column");
  }
  Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>
  cf = value.getMap();
  if(!cf.containsKey(INPUT_FAMILY)) {
    throw new IOException("Wrong input columns. Missing: '" +
        Bytes.toString(INPUT_FAMILY) + "'.");
  }
  // Get the original value and reverse it
  String originalValue = Bytes.toString(value.getValue(INPUT_FAMILY, INPUT_FAMILY));
  StringBuilder newValue = new StringBuilder(originalValue);
  newValue.reverse();
  // Now set the value to be collected
  Put outval = new Put(key.get());
  outval.addColumn(OUTPUT_FAMILY, null, Bytes.toBytes(newValue.toString()));
  context.write(key, outval);
}
 
Example 2
Source File: TestTableMapReduceBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Implements mapper logic for use across APIs.
 */
protected static Put map(ImmutableBytesWritable key, Result value) throws IOException {
  if (value.size() != 1) {
    throw new IOException("There should only be one input column");
  }
  Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>
    cf = value.getMap();
  if(!cf.containsKey(INPUT_FAMILY)) {
    throw new IOException("Wrong input columns. Missing: '" +
      Bytes.toString(INPUT_FAMILY) + "'.");
  }

  // Get the original value and reverse it

  String originalValue = Bytes.toString(value.getValue(INPUT_FAMILY, INPUT_FAMILY));
  StringBuilder newValue = new StringBuilder(originalValue);
  newValue.reverse();

  // Now set the value to be collected

  Put outval = new Put(key.get());
  outval.addColumn(OUTPUT_FAMILY, null, Bytes.toBytes(newValue.toString()));
  return outval;
}
 
Example 3
Source File: TestTableInputFormatScanBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Pass the key and value to reduce.
 *
 * @param key  The key, here "aaa", "aab" etc.
 * @param value  The value is the same as the key.
 * @param context  The task context.
 * @throws IOException When reading the rows fails.
 */
@Override
public void map(ImmutableBytesWritable key, Result value,
  Context context)
throws IOException, InterruptedException {
  if (value.size() != 2) {
    throw new IOException("There should be two input columns");
  }
  Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>
    cfMap = value.getMap();

  if (!cfMap.containsKey(INPUT_FAMILYS[0]) || !cfMap.containsKey(INPUT_FAMILYS[1])) {
    throw new IOException("Wrong input columns. Missing: '" +
      Bytes.toString(INPUT_FAMILYS[0]) + "' or '" + Bytes.toString(INPUT_FAMILYS[1]) + "'.");
  }

  String val0 = Bytes.toStringBinary(value.getValue(INPUT_FAMILYS[0], null));
  String val1 = Bytes.toStringBinary(value.getValue(INPUT_FAMILYS[1], null));
  LOG.info("map: key -> " + Bytes.toStringBinary(key.get()) +
           ", value -> (" + val0 + ", " + val1 + ")");
  context.write(key, key);
}
 
Example 4
Source File: TestTableMapReduce.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Pass the key, and reversed value to reduce
 *
 * @param key
 * @param value
 * @param context
 * @throws IOException
 */
@Override
public void map(ImmutableBytesWritable key, Result value,
  Context context)
throws IOException, InterruptedException {
  if (value.size() != 1) {
    throw new IOException("There should only be one input column");
  }
  Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>
    cf = value.getMap();
  if(!cf.containsKey(INPUT_FAMILY)) {
    throw new IOException("Wrong input columns. Missing: '" +
      Bytes.toString(INPUT_FAMILY) + "'.");
  }

  // Get the original value and reverse it
  String originalValue = Bytes.toString(value.getValue(INPUT_FAMILY, INPUT_FAMILY));
  StringBuilder newValue = new StringBuilder(originalValue);
  newValue.reverse();
  // Now set the value to be collected
  Put outval = new Put(key.get());
  outval.addColumn(OUTPUT_FAMILY, null, Bytes.toBytes(newValue.toString()));
  context.write(key, outval);
}
 
Example 5
Source File: HBaseManager.java    From hbase-secondary-index with GNU General Public License v3.0 6 votes vote down vote up
public void testQueryCommodity() throws Exception {

		System.out.println("Get Spin's commodity info");
		Get mathGet = new Get(new String("Spin").getBytes());
		mathGet.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("widgetname"));
		mathGet.setMaxVersions();
		Result rs = table.get(mathGet);

		NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> nMap = rs
				.getMap();
		NavigableMap<byte[], NavigableMap<Long, byte[]>> columnMap = nMap
				.get(Bytes.toBytes("widgetname"));
		NavigableMap<Long, byte[]> qualMap = columnMap.get(new byte[] {});

		if (qualMap.entrySet().size() > 0) {
			for (Map.Entry<Long, byte[]> m : qualMap.entrySet()) {
				System.out.println("Value:" + new String(m.getValue()));
				break;
			}
		}
	}
 
Example 6
Source File: HBaseBinaryRecordReader.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Entry> getCurrentValue() throws IOException, InterruptedException {
    Result result = (Result)reader.getCurrentValue();
    NavigableMap<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> nm = result.getMap();
    return new HBaseMapIterable(nm.get(edgestoreFamilyBytes));
    // return new HBaseMapIterable(reader.getCurrentValue().getMap().get(edgestoreFamilyBytes));
}
 
Example 7
Source File: MultiTableInputFormatTestBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void makeAssertions(ImmutableBytesWritable key, Result value) throws IOException {
  if (value.size() != 1) {
    throw new IOException("There should only be one input column");
  }
  Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> cf =
      value.getMap();
  if (!cf.containsKey(INPUT_FAMILY)) {
    throw new IOException("Wrong input columns. Missing: '" +
        Bytes.toString(INPUT_FAMILY) + "'.");
  }
  String val = Bytes.toStringBinary(value.getValue(INPUT_FAMILY, null));
  LOG.debug("map: key -> " + Bytes.toStringBinary(key.get()) +
      ", value -> " + val);
}
 
Example 8
Source File: HBaseRow.java    From geowave with Apache License 2.0 5 votes vote down vote up
public HBaseRow(final Result result, final int partitionKeyLength) {
  // TODO: GEOWAVE-1018 - can we do something more clever that lazily
  // parses only whats required by the getter (and caches anything else
  // that is parsed)?
  key = new GeoWaveKeyImpl(result.getRow(), partitionKeyLength);

  final NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowMapping =
      result.getMap();
  final List<GeoWaveValue> fieldValueList = new ArrayList();

  for (final Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> cfEntry : rowMapping.entrySet()) {
    for (final Entry<byte[], NavigableMap<Long, byte[]>> cqEntry : cfEntry.getValue().entrySet()) {
      for (final Entry<Long, byte[]> cqEntryValue : cqEntry.getValue().entrySet()) {
        final byte[] byteValue = cqEntryValue.getValue();
        final byte[] qualifier = cqEntry.getKey();

        fieldValueList.add(new GeoWaveValueImpl(qualifier, null, byteValue));
      }
    }
  }

  fieldValues = new GeoWaveValue[fieldValueList.size()];
  int i = 0;

  for (final GeoWaveValue gwValue : fieldValueList) {
    fieldValues[i++] = gwValue;
  }
}
 
Example 9
Source File: HBaseManager.java    From hbase-secondary-index with GNU General Public License v3.0 5 votes vote down vote up
public void testQueryRS() throws Exception {

		Scan scanner = new Scan();
		scanner.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("description"));
		scanner.setMaxVersions();
		ResultScanner rsScanner = table.getScanner(scanner);
		System.out.println(rsScanner.toString());
		Result rs = rsScanner.next();
		int count = 0;
		while (null != rs) {
			++count;
			System.out.println(rs.size());
			NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> nMap = rs
					.getMap();
			NavigableMap<byte[], NavigableMap<Long, byte[]>> columnMap = nMap
					.get(Bytes.toBytes("description"));
			NavigableMap<Long, byte[]> qualMap = columnMap.get(new byte[] {});

			if (qualMap.entrySet().size() > 0) {
				System.out.println("---------------------------");
				for (Map.Entry<Long, byte[]> m : qualMap.entrySet()) {
					System.out.println("Value:" + new String(m.getValue()));
				}
			}
			rs = rsScanner.next();
			if (count > 10)
				break;
		}
	}