本文整理了Java中org.apache.hadoop.hbase.util.Bytes.getBytes()
方法的一些代码示例,展示了Bytes.getBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.getBytes()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.util.Bytes
类名称:Bytes
方法名:getBytes
[英]Returns a new byte array, copied from the given buf, from the position (inclusive) to the limit (exclusive). The position and the other index parameters are not changed.
[中]
代码示例来源:origin: apache/hbase
private static TableName getTableName(ByteBuffer buffer) {
return TableName.valueOf(getBytes(buffer));
}
代码示例来源:origin: apache/hbase
/**
* Adds all the attributes into the Operation object
*/
private static void addAttributes(OperationWithAttributes op,
Map<ByteBuffer, ByteBuffer> attributes) {
if (attributes == null || attributes.isEmpty()) {
return;
}
for (Map.Entry<ByteBuffer, ByteBuffer> entry : attributes.entrySet()) {
String name = Bytes.toStringBinary(getBytes(entry.getKey()));
byte[] value = getBytes(entry.getValue());
op.setAttribute(name, value);
}
}
代码示例来源:origin: apache/hbase
protected Table getTable(final ByteBuffer tableName) throws IOException {
return getTable(Bytes.getBytes(tableName));
}
代码示例来源:origin: apache/hbase
/**
* Adds all the attributes into the Operation object
*/
private static void addAttributes(OperationWithAttributes op,
Map<ByteBuffer, ByteBuffer> attributes) {
if (attributes == null || attributes.isEmpty()) {
return;
}
for (Map.Entry<ByteBuffer, ByteBuffer> entry : attributes.entrySet()) {
String name = Bytes.toStringBinary(getBytes(entry.getKey()));
byte[] value = getBytes(entry.getValue());
op.setAttribute(name, value);
}
}
代码示例来源:origin: apache/hbase
@Override
public void majorCompact(ByteBuffer tableNameOrRegionName) throws IOError {
try {
try {
getAdmin().compactRegion(getBytes(tableNameOrRegionName));
} catch (IllegalArgumentException e) {
// Invalid region, try table
getAdmin().compact(TableName.valueOf(getBytes(tableNameOrRegionName)));
}
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
}
}
代码示例来源:origin: apache/hbase
@Override
public void compact(ByteBuffer tableNameOrRegionName) throws IOError {
try {
try {
getAdmin().compactRegion(getBytes(tableNameOrRegionName));
} catch (IllegalArgumentException e) {
// Invalid region, try table
getAdmin().compact(TableName.valueOf(getBytes(tableNameOrRegionName)));
}
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
}
}
代码示例来源:origin: apache/hbase
@Override
public List<TCell> getVer(ByteBuffer tableName, ByteBuffer row, ByteBuffer column,
int numVersions, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
byte [][] famAndQf = CellUtil.parseColumn(getBytes(column));
if(famAndQf.length == 1) {
return getVer(tableName, row, famAndQf[0], null, numVersions, attributes);
}
if (famAndQf.length == 2) {
return getVer(tableName, row, famAndQf[0], famAndQf[1], numVersions, attributes);
}
throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
}
代码示例来源:origin: apache/hbase
@Override
public List<TCell> getVerTs(ByteBuffer tableName, ByteBuffer row, ByteBuffer column,
long timestamp, int numVersions, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
byte [][] famAndQf = CellUtil.parseColumn(getBytes(column));
if (famAndQf.length == 1) {
return getVerTs(tableName, row, famAndQf[0], null, timestamp, numVersions, attributes);
}
if (famAndQf.length == 2) {
return getVerTs(tableName, row, famAndQf[0], famAndQf[1], timestamp, numVersions,
attributes);
}
throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
}
代码示例来源:origin: apache/hbase
@Override
public List<TCell> get(
ByteBuffer tableName, ByteBuffer row, ByteBuffer column,
Map<ByteBuffer, ByteBuffer> attributes)
throws IOError {
byte [][] famAndQf = CellUtil.parseColumn(getBytes(column));
if (famAndQf.length == 1) {
return get(tableName, row, famAndQf[0], null, attributes);
}
if (famAndQf.length == 2) {
return get(tableName, row, famAndQf[0], famAndQf[1], attributes);
}
throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
}
代码示例来源:origin: apache/hbase
/**
* From a {@link TAppend} create an {@link Append}.
* @param tappend the Thrift version of an append.
* @return an increment that the {@link TAppend} represented.
*/
public static Append appendFromThrift(TAppend tappend) {
Append append = new Append(tappend.getRow());
List<ByteBuffer> columns = tappend.getColumns();
List<ByteBuffer> values = tappend.getValues();
if (columns.size() != values.size()) {
throw new IllegalArgumentException(
"Sizes of columns and values in tappend object are not matching");
}
int length = columns.size();
for (int i = 0; i < length; i++) {
byte[][] famAndQf = CellUtil.parseColumn(getBytes(columns.get(i)));
append.addColumn(famAndQf[0], famAndQf[1], getBytes(values.get(i)));
}
return append;
}
}
代码示例来源:origin: apache/hbase
protected long atomicIncrement(ByteBuffer tableName, ByteBuffer row,
byte [] family, byte [] qualifier, long amount)
throws IOError, IllegalArgument, TException {
Table table = null;
try {
table = getTable(tableName);
return table.incrementColumnValue(
getBytes(row), family, qualifier, amount);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally {
closeTable(table);
}
}
代码示例来源:origin: apache/hbase
@Override
public long atomicIncrement(
ByteBuffer tableName, ByteBuffer row, ByteBuffer column, long amount)
throws IOError, IllegalArgument, TException {
byte [][] famAndQf = CellUtil.parseColumn(getBytes(column));
if(famAndQf.length == 1) {
return atomicIncrement(tableName, row, famAndQf[0], HConstants.EMPTY_BYTE_ARRAY, amount);
}
return atomicIncrement(tableName, row, famAndQf[0], famAndQf[1], amount);
}
代码示例来源:origin: apache/hbase
@Override
public void deleteAllRowTs(
ByteBuffer tableName, ByteBuffer row, long timestamp,
Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
Table table = null;
try {
table = getTable(tableName);
Delete delete = new Delete(getBytes(row), timestamp);
addAttributes(delete, attributes);
table.delete(delete);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally {
closeTable(table);
}
}
代码示例来源:origin: apache/hbase
@Override
public int scannerOpenWithStop(ByteBuffer tableName, ByteBuffer startRow,
ByteBuffer stopRow, List<ByteBuffer> columns,
Map<ByteBuffer, ByteBuffer> attributes)
throws IOError, TException {
Table table = null;
try {
table = getTable(tableName);
Scan scan = new Scan(getBytes(startRow), getBytes(stopRow));
addAttributes(scan, attributes);
if(columns != null && !columns.isEmpty()) {
for(ByteBuffer column : columns) {
byte [][] famQf = CellUtil.parseColumn(getBytes(column));
if(famQf.length == 1) {
scan.addFamily(famQf[0]);
} else {
scan.addColumn(famQf[0], famQf[1]);
}
}
}
return addScanner(table.getScanner(scan), false);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally{
closeTable(table);
}
}
代码示例来源:origin: apache/hbase
@Override
public void deleteAllTs(ByteBuffer tableName,
ByteBuffer row,
ByteBuffer column,
long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
Table table = null;
try {
table = getTable(tableName);
Delete delete = new Delete(getBytes(row));
addAttributes(delete, attributes);
byte [][] famAndQf = CellUtil.parseColumn(getBytes(column));
if (famAndQf.length == 1) {
delete.addFamily(famAndQf[0], timestamp);
} else {
delete.addColumns(famAndQf[0], famAndQf[1], timestamp);
}
table.delete(delete);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally {
closeTable(table);
}
}
代码示例来源:origin: apache/hbase
public void testGetBytesForByteBuffer() {
byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
ByteBuffer target = ByteBuffer.wrap(array);
target.position(2);
target.limit(7);
byte[] actual = Bytes.getBytes(target);
byte[] expected = { 2, 3, 4, 5, 6 };
assertTrue(Arrays.equals(expected, actual));
assertEquals(2, target.position());
assertEquals(7, target.limit());
}
代码示例来源:origin: apache/hbase
@Override
public int scannerOpenWithStopTs(ByteBuffer tableName, ByteBuffer startRow,
ByteBuffer stopRow, List<ByteBuffer> columns, long timestamp,
Map<ByteBuffer, ByteBuffer> attributes)
throws IOError, TException {
Table table = null;
try {
table = getTable(tableName);
Scan scan = new Scan(getBytes(startRow), getBytes(stopRow));
addAttributes(scan, attributes);
scan.setTimeRange(0, timestamp);
if (columns != null && !columns.isEmpty()) {
for (ByteBuffer column : columns) {
byte [][] famQf = CellUtil.parseColumn(getBytes(column));
if(famQf.length == 1) {
scan.addFamily(famQf[0]);
} else {
scan.addColumn(famQf[0], famQf[1]);
}
}
}
scan.setTimeRange(0, timestamp);
return addScanner(table.getScanner(scan), false);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally{
closeTable(table);
}
}
代码示例来源:origin: apache/hbase
@Override
public int scannerOpen(ByteBuffer tableName, ByteBuffer startRow,
List<ByteBuffer> columns,
Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
Table table = null;
try {
table = getTable(tableName);
Scan scan = new Scan(getBytes(startRow));
addAttributes(scan, attributes);
if(columns != null && !columns.isEmpty()) {
for(ByteBuffer column : columns) {
byte [][] famQf = CellUtil.parseColumn(getBytes(column));
if(famQf.length == 1) {
scan.addFamily(famQf[0]);
} else {
scan.addColumn(famQf[0], famQf[1]);
}
}
}
return addScanner(table.getScanner(scan), false);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally{
closeTable(table);
}
}
代码示例来源:origin: apache/hbase
@Override
public int scannerOpenTs(ByteBuffer tableName, ByteBuffer startRow,
List<ByteBuffer> columns, long timestamp,
Map<ByteBuffer, ByteBuffer> attributes) throws IOError, TException {
Table table = null;
try {
table = getTable(tableName);
Scan scan = new Scan(getBytes(startRow));
addAttributes(scan, attributes);
scan.setTimeRange(0, timestamp);
if (columns != null && !columns.isEmpty()) {
for (ByteBuffer column : columns) {
byte [][] famQf = CellUtil.parseColumn(getBytes(column));
if(famQf.length == 1) {
scan.addFamily(famQf[0]);
} else {
scan.addColumn(famQf[0], famQf[1]);
}
}
}
return addScanner(table.getScanner(scan), false);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally{
closeTable(table);
}
}
代码示例来源:origin: apache/hbase
/**
* This utility method creates a new Hbase HColumnDescriptor object based on a
* Thrift ColumnDescriptor "struct".
*
* @param in Thrift ColumnDescriptor object
* @return HColumnDescriptor
* @throws IllegalArgument if the column name is empty
*/
static public HColumnDescriptor colDescFromThrift(ColumnDescriptor in)
throws IllegalArgument {
Compression.Algorithm comp =
Compression.getCompressionAlgorithmByName(in.compression.toLowerCase(Locale.ROOT));
BloomType bt =
BloomType.valueOf(in.bloomFilterType);
if (in.name == null || !in.name.hasRemaining()) {
throw new IllegalArgument("column name is empty");
}
byte [] parsedName = CellUtil.parseColumn(Bytes.getBytes(in.name))[0];
HColumnDescriptor col = new HColumnDescriptor(parsedName)
.setMaxVersions(in.maxVersions)
.setCompressionType(comp)
.setInMemory(in.inMemory)
.setBlockCacheEnabled(in.blockCacheEnabled)
.setTimeToLive(in.timeToLive > 0 ? in.timeToLive : Integer.MAX_VALUE)
.setBloomFilterType(bt);
return col;
}
内容来源于网络,如有侵权,请联系作者删除!