Java Code Examples for org.apache.hadoop.hbase.KeyValue#getValue()

The following examples show how to use org.apache.hadoop.hbase.KeyValue#getValue() . These examples are extracted from open source projects. 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
@Override
public void map(ImmutableBytesWritable row, Result value, Context context)
    throws InterruptedException, IOException {
  
  KeyValue[] kvs = value.raw();
  
  if (lastRowKey == null) {
    lastRowKey = row.get();
  } else if (Bytes.compareTo(lastRowKey, row.get()) != 0){
    writeLine(Bytes.toString(lastRowKey));
    columnValueMap.clear();
  }
  for (KeyValue kv: kvs) {
    String qualifier = Bytes.toString(kv.getQualifier());
    byte[] val = kv.getValue();
    columnValueMap.put(qualifier, val);
  }
}
 
Example 2
@Override
public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException {

  KeyValue[] kvs = value.raw();

  if (lastRowKey == null) {
    lastRowKey = row.get();
  } else if (Bytes.compareTo(lastRowKey, row.get()) != 0){
    writeLine(context);
    columnValueMap.clear();
  }
  for (KeyValue kv : kvs) {
    String qualifier = Bytes.toString(kv.getQualifier());
    byte[] val = kv.getValue();
    columnValueMap.put(qualifier, val);
  }
}
 
Example 3
@Override
public void map(ImmutableBytesWritable row, Result value, Context context)
    throws InterruptedException, IOException {
  
  KeyValue[] kvs = value.raw();
  
  if (lastRowKey == null) {
    lastRowKey = row.get();
  } else if (Bytes.compareTo(lastRowKey, row.get()) != 0){
    writeLine(context,Bytes.toString(lastRowKey));
    columnValueMap.clear();
  }
  for (KeyValue kv: kvs) {
    String qualifier = Bytes.toString(kv.getQualifier());
    byte[] val = kv.getValue();
    columnValueMap.put(qualifier, val);
  }
}
 
Example 4
@Override
public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException {

  KeyValue[] kvs = value.raw();

  if (lastRowKey == null) {
    lastRowKey = row.get();
  } else if (Bytes.compareTo(lastRowKey, row.get()) != 0) {
    writeLine(context, lastRowKey);
    columnValueMap.clear();
  }
  for (KeyValue kv : kvs) {
    String qualifier = Bytes.toString(kv.getQualifier());
    byte[] val = kv.getValue();
    columnValueMap.put(qualifier, val);
  }
}
 
Example 5
@Override
@SuppressWarnings("rawtypes")
public void postPut(final ObserverContext e, final Put put,
		final WALEdit edit, final boolean writeToWAL) throws IOException {

	byte[][] colkey = KeyValue.parseColumn(Bytes.toBytes(inputColumn));
	if (colkey.length > 1) {
		List kvList = put.get(colkey[0], colkey[1]);
		Iterator kvl = kvList.iterator();

		while (kvl.hasNext()) {
			KeyValue kv = (KeyValue) kvl.next();
			Put indexPut = new Put(kv.getValue());
			colkey = KeyValue.parseColumn(Bytes.toBytes(indexColumn));
			indexPut.add(colkey[0], colkey[1], kv.getRow());
			table.put(indexPut);
		}
	}
}
 
Example 6
Source Project: Eagle   File: HBaseInternalLogHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param ed
 * @param r
 * @param qualifiers if null, return all qualifiers defined in ed
 * @return
 */
public static InternalLog parse(EntityDefinition ed, Result r, byte[][] qualifiers) {
	final byte[] row = r.getRow();
	// skip the first 4 bytes : prefix
	final int offset = (ed.getPartitions() == null) ? (4) : (4 + ed.getPartitions().length * 4);
	long timestamp = ByteUtil.bytesToLong(row, offset);
	// reverse timestamp
	timestamp = Long.MAX_VALUE - timestamp;
	final byte[] family = ed.getColumnFamily().getBytes();
	final Map<String, byte[]> allQualifierValues = new HashMap<String, byte[]>();

	if (qualifiers != null) {
		int count = qualifiers.length;
		final byte[][] values = new byte[count][];
		for (int i = 0; i < count; i++) {
			// TODO if returned value is null, it means no this column for this row, so why set null to the object?
			values[i] = r.getValue(family, qualifiers[i]);
			allQualifierValues.put(new String(qualifiers[i]), values[i]);
		}
	}else{
		// return all qualifiers
		for(KeyValue kv:r.list()){
			byte[] qualifier = kv.getQualifier();
			byte[] value = kv.getValue();
			allQualifierValues.put(new String(qualifier),value);
		}
	}
	final InternalLog log = buildObject(ed, row, timestamp, allQualifierValues);
	return log;
}
 
Example 7
Source Project: eagle   File: HBaseInternalLogHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param ed
 * @param r
 * @param qualifiers if null, return all qualifiers defined in ed
 * @return
 */
public static InternalLog parse(EntityDefinition ed, Result r, byte[][] qualifiers) {
    final byte[] row = r.getRow();
    // skip the first 4 bytes : prefix
    final int offset = (ed.getPartitions() == null) ? (4) : (4 + ed.getPartitions().length * 4);
    long timestamp = ByteUtil.bytesToLong(row, offset);
    // reverse timestamp
    timestamp = Long.MAX_VALUE - timestamp;
    final byte[] family = ed.getColumnFamily().getBytes();
    final Map<String, byte[]> allQualifierValues = new HashMap<String, byte[]>();

    if (qualifiers != null) {
        int count = qualifiers.length;
        final byte[][] values = new byte[count][];
        for (int i = 0; i < count; i++) {
            // TODO if returned value is null, it means no this column for this row, so why set null to
            // the object?
            values[i] = r.getValue(family, qualifiers[i]);
            allQualifierValues.put(new String(qualifiers[i]), values[i]);
        }
    } else {
        // return all qualifiers
        for (KeyValue kv : r.list()) {
            byte[] qualifier = kv.getQualifier();
            byte[] value = kv.getValue();
            allQualifierValues.put(new String(qualifier), value);
        }
    }
    final InternalLog log = buildObject(ed, row, timestamp, allQualifierValues);
    return log;
}
 
Example 8
@Override
public long getCommittedWindowId(String appId, int operatorId)
{
  byte[] value = null;
  try {
    String columnKey = appId + "_" + operatorId + "_" + lastWindowColumnName;
    lastWindowColumnBytes = Bytes.toBytes(columnKey);
    Get get = new Get(rowBytes);
    get.addColumn(columnFamilyBytes, lastWindowColumnBytes);
    Result result = null;
    result = table.get(get);

    for (KeyValue kv : result.raw()) {
      if (kv.matchingQualifier(lastWindowColumnBytes)) {
        value = kv.getValue();
        break;
      }
    }
  } catch (IOException ex) {
    logger.error("Could not load window id ", ex);
    DTThrowable.rethrow(ex);
  }
  if (value != null) {
    long longval = Bytes.toLong(value);
    return longval;
  } else {
    return -1;
  }
}
 
Example 9
Source Project: hiped2   File: ImportMapReduce.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void map(ImmutableBytesWritable row, Result columns,
    Mapper.Context context)
throws IOException, InterruptedException {
  for (KeyValue kv : columns.list()) {
    byte[] value = kv.getValue();

    Stock stock = stockReader.decode(value);

    outputKey.set(stock.getSymbol().toString());
    outputValue.set(stock.getClose());
    context.write(outputKey, outputValue);
  }
}
 
Example 10
private static byte[] getMutationKVByteValue(Mutation headerRow, byte[] key) {
    KeyValue kv = getMutationKeyValue(headerRow, key);
    // FIXME: byte copy
    return kv == null ? ByteUtil.EMPTY_BYTE_ARRAY : kv.getValue();
}