下面列出了org.apache.hadoop.hbase.client.Result#getMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
/**
* 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;
}
/**
* 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);
}
/**
* 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);
}
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;
}
}
}
@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));
}
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);
}
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;
}
}
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;
}
}