rowkey倒置时间戳

import org.apache.hadoop.hbase.util.Bytes;

//填入station_id和时间戳,返回逆序时间戳和station_id生成的rowkey
public class RowKeyConverter {

	// station_id长度
  private static final int STATION_ID_LENGTH = 12;

  /**
   * @return A row key whose format is: <station_id> <reverse_order_timestamp>
   */
  public static byte[] makeObservationRowKey(String stationId,
      long observationTime) {
    byte[] row = new byte[STATION_ID_LENGTH + Bytes.SIZEOF_LONG];
    Bytes.putBytes(row, 0, Bytes.toBytes(stationId), 0, STATION_ID_LENGTH);
    long reverseOrderTimestamp = Long.MAX_VALUE - observationTime;
    //将reverseOrderTimestamp转换成byte放入row的STATION_ID_LENGTH位置后
    Bytes.putLong(row, STATION_ID_LENGTH, reverseOrderTimestamp);
    return row;
  }
  public static void main(String[] args) {
  	for(int i=100;i>0;i--) {
  		long time=System.currentTimeMillis();
    	byte[] rowKey=makeObservationRowKey("123412341234",time);
    	for (byte b : rowKey) {
  			System.out.print(b);
  		}
    	System.out.println();
  	}
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值