org.apache.hadoop.hbase.util.Bytes.head()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(79)

本文整理了Java中org.apache.hadoop.hbase.util.Bytes.head()方法的一些代码示例,展示了Bytes.head()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.head()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.util.Bytes
类名称:Bytes
方法名:head

Bytes.head介绍

暂无

代码示例

代码示例来源:origin: apache/hbase

private static void setStartAndStopRows(Scan scan, byte[] startPrefixRow, byte[] lastPrefixRow) {
 scan.setStartRow(startPrefixRow);
 byte[] stopRow = Bytes.add(Bytes.head(lastPrefixRow, lastPrefixRow.length - 1),
   new byte[]{(byte) (lastPrefixRow[lastPrefixRow.length - 1] + 1)});
 scan.setStopRow(stopRow);
}

代码示例来源:origin: KylinOLAP/Kylin

public String readColumnString(TblColRef col, byte[] bytes, int bytesLen) {
  Dictionary<String> dict = getDictionary(col);
  if (dict == null) {
    bytes = Bytes.head(bytes, bytesLen);
    if (isNull(bytes)) {
      return null;
    }
    bytes = removeFixLenPad(bytes, 0);
    return Bytes.toString(bytes);
  } else {
    int id = BytesUtil.readUnsigned(bytes, 0, bytesLen);
    try {
      String value = dict.getValueFromId(id);
      return value;
    } catch (IllegalArgumentException e) {
      logger.error("Can't get dictionary value for column " + col.getName() + " (id = " + id + ")");
      return "";
    }
  }
}

代码示例来源:origin: sematext/HBaseHUT

public static byte[] getOriginalKey(byte[] hutRowKey) {
 return Bytes.head(hutRowKey, hutRowKey.length - Bytes.SIZEOF_LONG * 2);
}

代码示例来源:origin: KylinOLAP/Kylin

Text rowkey = result.get(0).getFirst();
byte[] key = rowkey.getBytes();
byte[] header = Bytes.head(key, 26);
byte[] sellerId = Bytes.tail(header, 18);
byte[] cuboidId = Bytes.head(header, 8);
byte[] restKey = Bytes.tail(key, rowkey.getLength() - 26);

代码示例来源:origin: KylinOLAP/Kylin

@Test
public void testMapperWithHeader() throws Exception {
  String cubeName = "test_kylin_cube_with_slr_1_new_segment";
  String segmentName = "20130331080000_20131212080000";
  mapDriver.getConfiguration().set(BatchConstants.CFG_CUBE_NAME, cubeName);
  mapDriver.getConfiguration().set(BatchConstants.CFG_CUBE_SEGMENT_NAME, segmentName);
  // mapDriver.getConfiguration().set(BatchConstants.CFG_METADATA_URL,
  // metadata);
  mapDriver.withInput(new Text("key"), new Text("2012-12-15118480Health & BeautyFragrancesWomenAuction15123456789132.33"));
  List<Pair<Text, Text>> result = mapDriver.run();
  CubeManager cubeMgr = CubeManager.getInstance(getTestConfig());
  CubeInstance cube = cubeMgr.getCube(cubeName);
  assertEquals(1, result.size());
  Text rowkey = result.get(0).getFirst();
  byte[] key = rowkey.getBytes();
  byte[] header = Bytes.head(key, 26);
  byte[] sellerId = Bytes.tail(header, 18);
  byte[] cuboidId = Bytes.head(header, 8);
  byte[] restKey = Bytes.tail(key, rowkey.getLength() - 26);
  RowKeyDecoder decoder = new RowKeyDecoder(cube.getFirstSegment());
  decoder.decode(key);
  assertEquals("[123456789, 2012-12-15, 11848, Health & Beauty, Fragrances, Women, Auction, 0, 15]", decoder.getValues().toString());
  assertTrue(Bytes.toString(sellerId).startsWith("123456789"));
  assertEquals(511, Bytes.toLong(cuboidId));
  assertEquals(22, restKey.length);
  verifyMeasures(cube.getDescriptor().getMeasures(), result.get(0).getSecond(), "132.33", "132.33", "132.33");
}

代码示例来源:origin: NGDATA/lilyproject

static private Pair<String, byte[]>  decode(byte[] key) {
  int sizeofInt = Bytes.SIZEOF_INT;
  int idLength = Bytes.toInt(key, key.length - sizeofInt, sizeofInt);
  String id = Bytes.toString(key, key.length - sizeofInt - idLength, idLength);
  byte[] blobKey = Bytes.head(key, key.length - sizeofInt - idLength);
  return new Pair<String, byte[]>(id, blobKey);
}

代码示例来源:origin: org.apache.pig/pig

@Override
public Integer bytesToInteger(byte[] b) throws IOException {
  if (Bytes.SIZEOF_INT > b.length){
    return Bytes.toInt(Bytes.padHead(b, Bytes.SIZEOF_INT - b.length));
  } else {
    return Bytes.toInt(Bytes.head(b, Bytes.SIZEOF_INT));
  }
}

代码示例来源:origin: org.apache.pig/pig

@Override
public Long bytesToLong(byte[] b) throws IOException {
  if (Bytes.SIZEOF_LONG > b.length){
    return Bytes.toLong(Bytes.padHead(b, Bytes.SIZEOF_LONG - b.length));
  } else {
    return Bytes.toLong(Bytes.head(b, Bytes.SIZEOF_LONG));
  }
}

代码示例来源:origin: org.apache.pig/pig

@Override
public Float bytesToFloat(byte[] b) throws IOException {
  if (Bytes.SIZEOF_FLOAT > b.length){
    return Bytes.toFloat(Bytes.padHead(b, Bytes.SIZEOF_FLOAT - b.length));
  } else {
    return Bytes.toFloat(Bytes.head(b, Bytes.SIZEOF_FLOAT));
  }
}

代码示例来源:origin: org.apache.hbase/hbase-mapreduce

private static void setStartAndStopRows(Scan scan, byte[] startPrefixRow, byte[] lastPrefixRow) {
 scan.setStartRow(startPrefixRow);
 byte[] stopRow = Bytes.add(Bytes.head(lastPrefixRow, lastPrefixRow.length - 1),
   new byte[]{(byte) (lastPrefixRow[lastPrefixRow.length - 1] + 1)});
 scan.setStopRow(stopRow);
}

代码示例来源:origin: org.apache.pig/pig

@Override
public Boolean bytesToBoolean(byte[] b) throws IOException {
  if (Bytes.SIZEOF_BOOLEAN > b.length) {
    return Bytes.toBoolean(Bytes.padHead(b, Bytes.SIZEOF_BOOLEAN - b.length));
  } else {
    return Bytes.toBoolean(Bytes.head(b, Bytes.SIZEOF_BOOLEAN));
  }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-mapreduce

private static void setStartAndStopRows(Scan scan, byte[] startPrefixRow, byte[] lastPrefixRow) {
 scan.setStartRow(startPrefixRow);
 byte[] stopRow = Bytes.add(Bytes.head(lastPrefixRow, lastPrefixRow.length - 1),
   new byte[]{(byte) (lastPrefixRow[lastPrefixRow.length - 1] + 1)});
 scan.setStopRow(stopRow);
}

代码示例来源:origin: org.apache.pig/pig

@Override
public Double bytesToDouble(byte[] b) throws IOException {
  if (Bytes.SIZEOF_DOUBLE > b.length){
    return Bytes.toDouble(Bytes.padHead(b, Bytes.SIZEOF_DOUBLE - b.length));
  } else {
    return Bytes.toDouble(Bytes.head(b, Bytes.SIZEOF_DOUBLE));
  }
}

代码示例来源:origin: com.sitewhere/sitewhere-hbase

/**
 * Decodes an event id into a {@link KeyValue} that can be used to access
 * the data in HBase.
 * 
 * @param id
 * @return
 * @throws SiteWhereException
 */
public static byte[][] getDecodedEventId(String id) throws SiteWhereException {
int rowLength = HBaseSite.SITE_IDENTIFIER_LENGTH + 1 + HBaseDeviceAssignment.ASSIGNMENT_IDENTIFIER_LENGTH + 5;
try {
  byte[] decoded = Base58.decode(id);
  byte[] row = Bytes.head(decoded, rowLength);
  byte[] qual = Bytes.tail(decoded, decoded.length - rowLength);
  return new byte[][] { row, qual };
} catch (AddressFormatException e) {
  throw new SiteWhereException("Invalid event id: " + id);
}
}

代码示例来源:origin: XiaoMi/themis

public static Column getDataColumn(Column lockOrWriteColumn) {
 if (isCommitToSameFamily()) {
  if (isLockColumn(lockOrWriteColumn)) {
   return getDataColumnFromConstructedQualifier(lockOrWriteColumn);
  } else {
   byte[] qualifier = lockOrWriteColumn.getQualifier();
   if (isPutColumn(lockOrWriteColumn)) {
    return new Column(lockOrWriteColumn.getFamily(), Bytes.head(qualifier, qualifier.length
      - PUT_QUALIFIER_SUFFIX_BYTES.length));
   } else if (isDeleteColumn(lockOrWriteColumn)) {
    return new Column(lockOrWriteColumn.getFamily(), Bytes.head(qualifier, qualifier.length
      - DELETE_QUALIFIER_SUFFIX_BYTES.length));
   } else {
    return lockOrWriteColumn;
   }
  }
 } else {
  return getDataColumnFromConstructedQualifier(lockOrWriteColumn);
 }
}

相关文章

微信公众号

最新文章

更多