Java Code Examples for org.apache.hadoop.hbase.util.Bytes#toInt()

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#toInt() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: hbase   File: TestWALEntrySinkFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AsyncTable<AdvancedScanResultConsumer> getTable(TableName tableName) {
  return new DummyAsyncTable<AdvancedScanResultConsumer>() {

    @Override
    public <T> CompletableFuture<List<T>> batchAll(List<? extends Row> actions) {
      List<T> list = new ArrayList<>(actions.size());
      for (Row action : actions) {
        // Row is the index of the loop above where we make WALEntry and Cells.
        int row = Bytes.toInt(action.getRow());
        assertTrue("" + row, row > BOUNDARY);
        UNFILTERED.incrementAndGet();
        list.add(null);
      }
      return CompletableFuture.completedFuture(list);
    }
  };
}
 
Example 2
Source Project: xxhadoop   File: HBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testScan() throws IOException {
	Connection connection = admin.getConnection();
	Table table = connection.getTable(TableName.valueOf("tbl_girls"));
	
	Scan scan = new Scan(Bytes.toBytes("0001"), Bytes.toBytes("0004"));
	// RowKeyFilter
	Filter filter = new PrefixFilter(Bytes.toBytes("000"));
	scan.setFilter(filter);
	
	Filter filter2 = new RowFilter(CompareOp.EQUAL, new SubstringComparator("000"));
	scan.setFilter(filter2);
	
	//BinaryComparator binaryComparator = new BinaryComparator(Bytes.toBytes(29));		
	Filter filter3 = new SingleColumnValueFilter(Bytes.toBytes("base_info"), Bytes.toBytes("age"), CompareOp.GREATER, Bytes.toBytes(29));
	scan.setFilter(filter3);
	
	ResultScanner resultScanner = table.getScanner(scan);
	for (Result result : resultScanner) {
		LOGGER.info(result.toString());
		int value = Bytes.toInt(result.getValue(Bytes.toBytes("base_info"), Bytes.toBytes("age")));
		LOGGER.info(String.valueOf(value));
	}
}
 
Example 3
Source Project: hbase   File: ResultSerialization.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Result deserialize(Result mutation) throws IOException {
  int totalBuffer = in.readInt();
  if (totalBuffer == 0) {
    return Result.EMPTY_RESULT;
  }
  byte[] buf = new byte[totalBuffer];
  readChunked(in, buf, 0, totalBuffer);
  List<Cell> kvs = new ArrayList<>();
  int offset = 0;
  while (offset < totalBuffer) {
    int keyLength = Bytes.toInt(buf, offset);
    offset += Bytes.SIZEOF_INT;
    kvs.add(new KeyValue(buf, offset, keyLength));
    offset += keyLength;
  }
  return Result.create(kvs);
}
 
Example 4
Source Project: phoenix   File: PTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int decode(byte[] bytes, int offset, int length) {
    if (length != 4) {
        throw new InvalidQualifierBytesException(4, length);
    }
    return Bytes.toInt(bytes, offset, length);
}
 
Example 5
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
int getRegionCountForTime(HTableInterface stateTable, long time) throws IOException {
  Get get = new Get(makeTimeRegionCountKey(Bytes.toBytes(getInvertedTime(time))));
  get.addColumn(FAMILY, REGION_TIME_COL);
  Result result = stateTable.get(get);
  byte[] value = result.getValue(FAMILY, REGION_TIME_COL);
  return value == null ? -1 : Bytes.toInt(value);
}
 
Example 6
Source Project: phoenix   File: ScanUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static int getClientVersion(Scan scan) {
    int clientVersion = UNKNOWN_CLIENT_VERSION;
    byte[] clientVersionBytes = scan.getAttribute(BaseScannerRegionObserver.CLIENT_VERSION);
    if (clientVersionBytes != null) {
        clientVersion = Bytes.toInt(clientVersionBytes);
    }
    return clientVersion;
}
 
Example 7
Source Project: phoenix   File: PTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int decode(byte[] bytes) {
    if (bytes.length != 4) {
        throw new InvalidQualifierBytesException(4, bytes.length);
    }
    return Bytes.toInt(bytes);
}
 
Example 8
Source Project: DataLink   File: MultiVersionTask.java    License: Apache License 2.0 5 votes vote down vote up
private Column convertBytesToAssignType(ColumnType columnType, byte[] byteArray) throws UnsupportedEncodingException {
    Column column;
    switch (columnType) {
        case BOOLEAN:
            column = new BoolColumn(byteArray == null ? null : Bytes.toBoolean(byteArray));
            break;
        case SHORT:
            column = new LongColumn(byteArray == null ? null : String.valueOf(Bytes.toShort(byteArray)));
            break;
        case INT:
            column = new LongColumn(byteArray == null ? null : Bytes.toInt(byteArray));
            break;
        case LONG:
            column = new LongColumn(byteArray == null ? null : Bytes.toLong(byteArray));
            break;
        case BYTES:
            column = new BytesColumn(byteArray);
            break;
        case FLOAT:
            column = new DoubleColumn(byteArray == null ? null : Bytes.toFloat(byteArray));
            break;
        case DOUBLE:
            column = new DoubleColumn(byteArray == null ? null : Bytes.toDouble(byteArray));
            break;
        case STRING:
            column = new StringColumn(byteArray == null ? null : new String(byteArray, super.encoding));
            break;
        case BINARY_STRING:
            column = new StringColumn(byteArray == null ? null : Bytes.toStringBinary(byteArray));
            break;

        default:
            throw DataXException.asDataXException(HbaseReaderErrorCode.ILLEGAL_VALUE, "Hbasereader 不支持您配置的列类型:" + columnType);
    }

    return column;
}
 
Example 9
Source Project: phoenix   File: PArrayDataType.java    License: Apache License 2.0 5 votes vote down vote up
private static int getOffset(byte[] bytes, int arrayIndex, boolean useShort, int indexOffset) {
    int offset;
    if (useShort) {
        offset = indexOffset + (Bytes.SIZEOF_SHORT * arrayIndex);
        return Bytes.toShort(bytes, offset, Bytes.SIZEOF_SHORT) + Short.MAX_VALUE;
    } else {
        offset = indexOffset + (Bytes.SIZEOF_INT * arrayIndex);
        return Bytes.toInt(bytes, offset, Bytes.SIZEOF_INT);
    }
}
 
Example 10
Source Project: phoenix   File: ChunkedResultIterator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Prefix region start key to last key to form actual row key in case of local index scan.
 */
private void addRegionStartKeyToLaskKey() {
    byte[] offsetBytes = scan.getAttribute(STARTKEY_OFFSET);
    if (offsetBytes != null) {
        int startKeyOffset = Bytes.toInt(offsetBytes);
        byte[] actualLastkey =
                new byte[startKeyOffset + lastKey.getLength() - lastKey.getOffset()];
        System.arraycopy(scan.getStartRow(), 0, actualLastkey, 0, startKeyOffset);
        System.arraycopy(lastKey.get(), lastKey.getOffset(), actualLastkey,
            startKeyOffset, lastKey.getLength());
        lastKey.set(actualLastkey);
    }
}
 
Example 11
Source Project: phoenix   File: PArrayDataType.java    License: Apache License 2.0 5 votes vote down vote up
public static int getArrayLength(ImmutableBytesWritable ptr, PDataType baseType, Integer maxLength) {
      byte[] bytes = ptr.get();
      if (ptr.getLength() == 0) {
          return 0;
      }
      if (baseType.isFixedWidth()) {
          int elemLength = maxLength == null ? baseType.getByteSize() : maxLength;
          return (ptr.getLength() / elemLength);
      }
      // In case where the number of elements is greater than SHORT.MAX_VALUE we do negate the number of
      // elements. So it is always better to return the absolute value
return (Bytes.toInt(bytes, (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT))));
  }
 
Example 12
Source Project: hbase   File: TestSwitchToStreamRead.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ReturnCode filterCell(Cell c) throws IOException {
  if (Bytes.toInt(c.getRowArray(), c.getRowOffset()) == 999) {
    return ReturnCode.INCLUDE;
  } else {
    return ReturnCode.NEXT_COL;
  }
}
 
Example 13
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
int getRegionCountForTime(Table stateTable, long time) throws IOException {
  Get get = new Get(makeTimeRegionCountKey(Bytes.toBytes(getInvertedTime(time))));
  get.addColumn(FAMILY, REGION_TIME_COL);
  Result result = stateTable.get(get);
  byte[] value = result.getValue(FAMILY, REGION_TIME_COL);
  return value == null ? -1 : Bytes.toInt(value);
}
 
Example 14
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
int getRegionCountForTime(HTableInterface stateTable, long time) throws IOException {
  Get get = new Get(makeTimeRegionCountKey(Bytes.toBytes(getInvertedTime(time))));
  get.addColumn(FAMILY, REGION_TIME_COL);
  Result result = stateTable.get(get);
  byte[] value = result.getValue(FAMILY, REGION_TIME_COL);
  return value == null ? -1 : Bytes.toInt(value);
}
 
Example 15
Source Project: phoenix   File: EncodedColumnsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static Pair<Integer, Integer> getMinMaxQualifiersFromScan(Scan scan) {
    Integer minQ = null, maxQ = null;
    byte[] minQualifier = scan.getAttribute(BaseScannerRegionObserver.MIN_QUALIFIER);
    if (minQualifier != null) {
        minQ = Bytes.toInt(minQualifier);
    }
    byte[] maxQualifier = scan.getAttribute(BaseScannerRegionObserver.MAX_QUALIFIER);
    if (maxQualifier != null) {
        maxQ = Bytes.toInt(maxQualifier);
    }
    if (minQualifier == null) {
        return null;
    }
    return new Pair<>(minQ, maxQ);
}
 
Example 16
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
int getRegionCountForTime(Table stateTable, long time) throws IOException {
  Get get = new Get(makeTimeRegionCountKey(Bytes.toBytes(getInvertedTime(time))));
  get.addColumn(FAMILY, REGION_TIME_COL);
  Result result = stateTable.get(get);
  byte[] value = result.getValue(FAMILY, REGION_TIME_COL);
  return value == null ? -1 : Bytes.toInt(value);
}
 
Example 17
Source Project: phoenix   File: PTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int decode(byte[] bytes, int offset, int length) {
    if (length == 4) {
        return getReservedQualifier(bytes, offset, length);
    }
    if (length != 3) {
        throw new InvalidQualifierBytesException(3, length);
    }
    byte[] toReturn = new byte[4];
    toReturn[1] = bytes[offset];
    toReturn[2] = bytes[offset + 1];
    toReturn[3] = bytes[offset + 2];
    return Bytes.toInt(toReturn);
}
 
Example 18
Source Project: hbase   File: TestSwitchToStreamRead.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean filterRowKey(Cell cell) throws IOException {
  return Bytes.toInt(cell.getRowArray(), cell.getRowOffset()) != 999;
}
 
Example 19
Source Project: hbase   File: KeyValue.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return Value length
 */
@Override
public int getValueLength() {
  int vlength = Bytes.toInt(this.bytes, this.offset + Bytes.SIZEOF_INT);
  return vlength;
}
 
Example 20
/**
 * Read an integer from the preceding {@value Bytes#SIZEOF_INT} bytes
 * @param bytes array to read from
 * @param start start point, backwards from which to read. For example, if specifying "25", we
 *          would try to read an integer from 21 -> 25
 * @return an integer from the proceeding {@value Bytes#SIZEOF_INT} bytes, if it exists.
 */
private static int getPreviousInteger(byte[] bytes, int start) {
  return Bytes.toInt(bytes, start - Bytes.SIZEOF_INT);
}