/** * hbaseのsc_item_dataのrow-keyを生成する * * @param shopID 店舗ID * @param itemID 商品ID * @return row-key */ public static byte[] encodeRowkey(int shopID, int itemID) { if (shopID == -1 || itemID == -1) { return new byte[0]; } // row key: shop_id + item_id byte[] bshopid = ByteArray.toByte32Radix(shopID, SIZE_OF_SHOP_ID_32); byte[] bitemid = ByteArray.toByte32Radix(itemID, SIZE_OF_ITEM_ID_32); byte[] rowKey = ByteArray.concatenate(bshopid, bitemid); return rowKey; }
/** * row keyを文字列にdecode * * @param rowkey row key * @return 10進のshop_id-item_id */ public static String decodeRowkey(byte[] rowkey) { int srcOffset = 0; byte[] bShopID = new byte[SIZE_OF_SHOP_ID_32]; System.arraycopy(rowkey, srcOffset, bShopID, 0, SIZE_OF_SHOP_ID_32); srcOffset += SIZE_OF_SHOP_ID_32; byte[] bItemID = new byte[SIZE_OF_ITEM_ID_32]; System.arraycopy(rowkey, srcOffset, bItemID, 0, SIZE_OF_ITEM_ID_32); long shopID = ByteArray.toDecimal(bShopID); long itemID = ByteArray.toDecimal(bItemID); return String.format("%d-%d", shopID, itemID); }