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

The following examples show how to use org.apache.hadoop.hbase.KeyValue#getValue() . 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: ExportHBaseTableToDelimiteredTxt.java    From HBase-ToHDFS with Apache License 2.0 6 votes vote down vote up
@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
Source File: ExportHBaseTableToAvro.java    From HBase-ToHDFS with Apache License 2.0 6 votes vote down vote up
@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
Source File: ExportHBaseTableToDelimiteredSeq.java    From HBase-ToHDFS with Apache License 2.0 6 votes vote down vote up
@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
Source File: ExportHBaseTableToParquet.java    From HBase-ToHDFS with Apache License 2.0 6 votes vote down vote up
@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
Source File: IndexerDemo.java    From hbase-secondary-index with GNU General Public License v3.0 6 votes vote down vote up
@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 File: HBaseInternalLogHelper.java    From Eagle with 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 File: HBaseInternalLogHelper.java    From eagle with 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
Source File: HBaseWindowStore.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@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 File: ImportMapReduce.java    From hiped2 with 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
Source File: MetaDataUtil.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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();
}