for (KeyValue kv : r.raw()) { result.put( Bytes.toString(kv.getQualifier()),
for (KeyValue kv : rr.raw()) { rowResult.put( Bytes.toString(kv.getQualifier()),
public static KeyValue getIncrementByKV(Result r) { KeyValue[] kvs = r.raw(); assert(kvs.length == SEQUENCE_KEY_VALUES); return kvs[INCREMENT_BY_INDEX]; }
public static KeyValue getCurrentValueKV(Result r) { KeyValue[] kvs = r.raw(); assert(kvs.length == SEQUENCE_KEY_VALUES); return kvs[CURRENT_VALUE_INDEX]; }
public static KeyValue getCacheSizeKV(Result r) { KeyValue[] kvs = r.raw(); assert(kvs.length == SEQUENCE_KEY_VALUES); return kvs[CACHE_SIZE_INDEX]; }
@Override public KeyValue getValue(int index) { return result.raw()[index]; }
public static Result replaceCurrentValueKV(Result r, KeyValue currentValueKV) { KeyValue[] kvs = r.raw(); List<KeyValue> newkvs = Lists.newArrayList(kvs); newkvs.set(CURRENT_VALUE_INDEX, currentValueKV); return new Result(newkvs); }
@SuppressWarnings({ "rawtypes", "deprecation" }) protected Map getCIFObject(String key) { LOGGER.debug("=======Pinging HBase For: {}", key); Get get = new Get(key.getBytes()); Result rs; Map output = new HashMap(); try { rs = table.get(get); for (KeyValue kv : rs.raw()) output.put(new String(kv.getQualifier()), "Y"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return output; }
static byte[] getRawBytes(Result r) { // Handle special case for when Result was instantiated via KeyValue array (no bytes in that case) versus returned from a scanner ImmutableBytesWritable rPtr = r.getBytes(); if (rPtr != null) return rPtr.get(); return r.raw()[0].getBuffer(); }
/** * Get the offset into the Result byte array to the key. * @param r * @return */ static int getKeyOffset(Result r) { // Special case for when Result was instantiated via KeyValue array (no bytes in that case) versus returned from a scanner return (r.getBytes() == null ? r.raw()[0].getOffset() : (r.getBytes().getOffset() + Bytes.SIZEOF_INT /* KV length in Result */)) + KeyValue.ROW_OFFSET /* key offset in KV */ + Bytes.SIZEOF_SHORT /* key length */; }
public long incrementValue(Result result, int factor) throws SQLException { // In this case, we don't definitely know the timestamp of the deleted sequence, // but we know anything older is likely deleted. Worse case, we remove a sequence // from the cache that we shouldn't have which will cause a gap in sequence values. // In that case, we might get an error that a curr value was done on a sequence // before a next val was. Not sure how to prevent that. if (result.raw().length == 1) { KeyValue errorKV = result.raw()[0]; int errorCode = PDataType.INTEGER.getCodec().decodeInt(errorKV.getBuffer(), errorKV.getValueOffset(), null); SQLExceptionCode code = SQLExceptionCode.fromErrorCode(errorCode); // TODO: We could have the server return the timestamps of the // delete markers and we could insert them here, but this seems // like overkill. // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) { // } throw new SQLExceptionInfo.Builder(code) .setSchemaName(key.getSchemaName()) .setTableName(key.getSequenceName()) .build().buildException(); } // If we found the sequence, we update our cache with the new value SequenceValue value = new SequenceValue(result); insertSequenceValue(value); long currentValue = value.currentValue; value.currentValue += factor * value.incrementBy; return currentValue; }
get.addColumn(TABLE_FAMILY_BYTES, INDEX_STATE_BYTES); Result currentResult = region.get(get); if (currentResult.raw().length == 0) { return new MetaDataMutationResult(MutationCode.TABLE_NOT_FOUND, EnvironmentEdgeManager.currentTimeMillis(), null); KeyValue currentStateKV = currentResult.raw()[0]; PIndexState currentState = PIndexState.fromSerializedValue(currentStateKV.getBuffer()[currentStateKV.getValueOffset()]);
private void assertNResult(Result result, byte[] row, byte[] family, byte[] qualifier, long[] stamps, byte[][] values, int start, int end) throws IOException { assertTrue( "Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(result.getRow()) + "]", equals(row, result.getRow())); int expectedResults = end - start + 1; assertEquals(expectedResults, result.size()); KeyValue[] keys = result.raw(); for (int i = 0; i < keys.length; i++) { byte[] value = values[end - i]; long ts = stamps[end - i]; KeyValue key = keys[i]; assertTrue("(" + i + ") Expected family [" + Bytes.toString(family) + "] " + "Got family [" + Bytes.toString(key.getFamily()) + "]", equals(family, key.getFamily())); assertTrue("(" + i + ") Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier [" + Bytes.toString(key.getQualifier()) + "]", equals(qualifier, key.getQualifier())); assertTrue("Expected ts [" + ts + "] " + "Got ts [" + key.getTimestamp() + "]", ts == key.getTimestamp()); assertTrue("(" + i + ") Expected value [" + Bytes.toString(value) + "] " + "Got value [" + Bytes.toString(key.getValue()) + "]", equals(value, key.getValue())); } }
KeyValue [] kvs = r.raw(); // side effect possibly. if (kvs == null || kvs.length == 0) { return null;
switch (op) { case RETURN_SEQUENCE: KeyValue currentValueKV = result.raw()[0]; long expectedValue = PDataType.LONG.getCodec().decodeLong(append.getAttribute(CURRENT_VALUE_ATTRIB), 0, null); long value = PDataType.LONG.getCodec().decodeLong(currentValueKV.getBuffer(), currentValueKV.getValueOffset(), null);
public long createSequence(Result result) throws SQLException { KeyValue statusKV = result.raw()[0]; long timestamp = statusKV.getTimestamp(); int statusCode = PDataType.INTEGER.getCodec().decodeInt(statusKV.getBuffer(), statusKV.getValueOffset(), null); if (statusCode == 0) { // Success - add sequence value and return timestamp SequenceValue value = new SequenceValue(timestamp); insertSequenceValue(value); return timestamp; } SQLExceptionCode code = SQLExceptionCode.fromErrorCode(statusCode); throw new SQLExceptionInfo.Builder(code) .setSchemaName(key.getSchemaName()) .setTableName(key.getSequenceName()) .build().buildException(); }
public long dropSequence(Result result) throws SQLException { KeyValue statusKV = result.raw()[0]; long timestamp = statusKV.getTimestamp(); int statusCode = PDataType.INTEGER.getCodec().decodeInt(statusKV.getBuffer(), statusKV.getValueOffset(), null); SQLExceptionCode code = statusCode == 0 ? null : SQLExceptionCode.fromErrorCode(statusCode); if (code == null) { // Insert delete marker so that point-in-time sequences work insertSequenceValue(new SequenceValue(timestamp, true)); return timestamp; } // TODO: We could have the server return the timestamps of the // delete markers and we could insert them here, but this seems // like overkill. // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) { // } throw new SQLExceptionInfo.Builder(code) .setSchemaName(key.getSchemaName()) .setTableName(key.getSequenceName()) .build().buildException(); } }
public boolean returnValue(Result result) throws SQLException { KeyValue statusKV = result.raw()[0]; if (statusKV.getValueLength() == 0) { // No error, but unable to return sequence values return false; } long timestamp = statusKV.getTimestamp(); int statusCode = PDataType.INTEGER.getCodec().decodeInt(statusKV.getBuffer(), statusKV.getValueOffset(), null); if (statusCode == SUCCESS) { // Success - update nextValue down to currentValue SequenceValue value = findSequenceValue(timestamp); if (value == null) { throw new EmptySequenceCacheException(key.getSchemaName(),key.getSequenceName()); } value.nextValue = value.currentValue; return true; } SQLExceptionCode code = SQLExceptionCode.fromErrorCode(statusCode); // TODO: We could have the server return the timestamps of the // delete markers and we could insert them here, but this seems // like overkill. // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) { // } throw new SQLExceptionInfo.Builder(code) .setSchemaName(key.getSchemaName()) .setTableName(key.getSequenceName()) .build().buildException(); }
public static HBaseTuple getHBaseTuple(Result result) { HBaseTuple tuple = null; KeyValue[] kvs = result.raw(); for (KeyValue kv : kvs) { tuple = getHBaseTuple(kv); break; } return tuple; }
private static void checkRow(Configuration configuration, byte[] expectedTableName, List<ParsedColumnFamilyModel> expectedColumnFamilies, ParsedColumnFamilyModel parsedColumnFamilyModel, ParsedRowModel parsedRowModel) throws IOException, Error { HTable table = new HTable(configuration, expectedTableName); Get get = new Get(parsedRowModel.getKeyInBytes()); get.addFamily(Bytes.toBytes(parsedColumnFamilyModel.getName())); Result result = table.get(get); checkRowName(parsedRowModel, result); KeyValue[] raws = result.raw(); checkNumberOfColumns(expectedColumnFamilies, parsedColumnFamilyModel, raws, parsedRowModel); checkRowValues(raws, parsedRowModel); }