Java Code Examples for org.apache.hadoop.hbase.client.Result#raw()
The following examples show how to use
org.apache.hadoop.hbase.client.Result#raw() .
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 check out the related API usage on the sidebar.
Example 1
Source File: ExportHBaseTableToAvro.java From HBase-ToHDFS with Apache License 2.0 | 6 votes |
@Override public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException { KeyValue[] kvs = value.raw(); if (lastRowKey == null) { lastRowKey = row.get(); } else if (Bytes.compareTo(lastRowKey, row.get()) != 0){ writeLine(context); columnValueMap.clear(); } for (KeyValue kv : kvs) { String qualifier = Bytes.toString(kv.getQualifier()); byte[] val = kv.getValue(); columnValueMap.put(qualifier, val); } }
Example 2
Source File: Sequence.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
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(); }
Example 3
Source File: ExportHBaseTableToParquet.java From HBase-ToHDFS with Apache License 2.0 | 6 votes |
@Override public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException { KeyValue[] kvs = value.raw(); if (lastRowKey == null) { lastRowKey = row.get(); } else if (Bytes.compareTo(lastRowKey, row.get()) != 0) { writeLine(context, lastRowKey); columnValueMap.clear(); } for (KeyValue kv : kvs) { String qualifier = Bytes.toString(kv.getQualifier()); byte[] val = kv.getValue(); columnValueMap.put(qualifier, val); } }
Example 4
Source File: ExportHBaseTableToDelimiteredSeq.java From HBase-ToHDFS with Apache License 2.0 | 6 votes |
@Override public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException { KeyValue[] kvs = value.raw(); if (lastRowKey == null) { lastRowKey = row.get(); } else if (Bytes.compareTo(lastRowKey, row.get()) != 0){ writeLine(context,Bytes.toString(lastRowKey)); columnValueMap.clear(); } for (KeyValue kv: kvs) { String qualifier = Bytes.toString(kv.getQualifier()); byte[] val = kv.getValue(); columnValueMap.put(qualifier, val); } }
Example 5
Source File: ExportHBaseTableToDelimiteredTxt.java From HBase-ToHDFS with Apache License 2.0 | 6 votes |
@Override public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException { KeyValue[] kvs = value.raw(); if (lastRowKey == null) { lastRowKey = row.get(); } else if (Bytes.compareTo(lastRowKey, row.get()) != 0){ writeLine(Bytes.toString(lastRowKey)); columnValueMap.clear(); } for (KeyValue kv: kvs) { String qualifier = Bytes.toString(kv.getQualifier()); byte[] val = kv.getValue(); columnValueMap.put(qualifier, val); } }
Example 6
Source File: CIFHbaseAdapter.java From opensoc-streaming with Apache License 2.0 | 6 votes |
@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; }
Example 7
Source File: IndexedRegion.java From hbase-secondary-index with GNU General Public License v3.0 | 6 votes |
private SortedMap<byte[], byte[]> convertToValueMap(final Result result) { SortedMap<byte[], byte[]> currentColumnValues = new TreeMap<byte[], byte[]>( Bytes.BYTES_COMPARATOR); if (result == null || result.raw() == null) { return currentColumnValues; } List<KeyValue> list = result.list(); if (list != null) { for (KeyValue kv : result.list()) { currentColumnValues.put( KeyValue.makeColumn(kv.getFamily(), kv.getQualifier()), kv.getValue()); } } return currentColumnValues; }
Example 8
Source File: TestClientKeyValue.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
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())); } }
Example 9
Source File: HBaseGetOperator.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
@Override public void emitTuples() { try { Get get = operationGet(); Result result = getStore().getTable().get(get); KeyValue[] kvs = result.raw(); //T t = getTuple(kvs); //T t = getTuple(result); for (KeyValue kv : kvs) { T t = getTuple(kv); outputPort.emit(t); } } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }
Example 10
Source File: Sequence.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
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(); }
Example 11
Source File: ResultUtil.java From phoenix with Apache License 2.0 | 5 votes |
/** * Binary search for latest column value without allocating memory in the process * @param r * @param searchTerm */ @SuppressWarnings("deprecation") public static KeyValue getColumnLatest(Result r, KeyValue searchTerm) { KeyValue [] kvs = r.raw(); // side effect possibly. if (kvs == null || kvs.length == 0) { return null; } // pos === ( -(insertion point) - 1) int pos = Arrays.binarySearch(kvs, searchTerm, KeyValue.COMPARATOR); // never will exact match if (pos < 0) { pos = (pos+1) * -1; // pos is now insertion point } if (pos == kvs.length) { return null; // doesn't exist } KeyValue kv = kvs[pos]; if (Bytes.compareTo(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength(), searchTerm.getBuffer(), searchTerm.getFamilyOffset(), searchTerm.getFamilyLength()) != 0) { return null; } if (Bytes.compareTo(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength(), searchTerm.getBuffer(), searchTerm.getQualifierOffset(), searchTerm.getQualifierLength()) != 0) { return null; } return kv; }
Example 12
Source File: HBaseTestHelper.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
public static HBaseTuple getHBaseTuple(Result result) { HBaseTuple tuple = null; KeyValue[] kvs = result.raw(); for (KeyValue kv : kvs) { tuple = getHBaseTuple(kv); break; } return tuple; }
Example 13
Source File: HbResultConvertor.java From tddl5 with Apache License 2.0 | 5 votes |
public static Map<Integer, Object> convertResultToRow(Result result, Map<String, ColumnMeta> columnMap, Map<String, Integer> columnIndex, TablePhysicalSchema physicalSchema) { KeyValue[] kvs = result.raw(); Map<String, byte[]> rowMap = new HashMap<String, byte[]>(); byte[] rowKey = result.getRow(); Map<String, Object> rowKeyColumnValues = physicalSchema.getRowKeyGenerator().decodeRowKey(rowKey); for (KeyValue kv : kvs) { StringBuilder cfAndCol = new StringBuilder(); cfAndCol.append(new String(kv.getFamily())); cfAndCol.append(HbConstant.CF_COL_SEP); cfAndCol.append(new String(kv.getQualifier())); rowMap.put(cfAndCol.toString(), kv.getValue()); } // 应对hbase不固定的schema Map<Integer, Object> r = new TreeMap<Integer, Object>(); for (Map.Entry<String, byte[]> cv : rowMap.entrySet()) { String innerColumn = physicalSchema.getInnerColumn(cv.getKey()); // hbase中存在的列,但是map中没有配置,忽略 if (innerColumn == null) continue; r.put(columnIndex.get(innerColumn), changeType(cv.getValue(), columnMap.get(innerColumn), physicalSchema)); } for (String name : rowKeyColumnValues.keySet()) { r.put(columnIndex.get(name), rowKeyColumnValues.get(name)); } return r; }
Example 14
Source File: Sequence.java From phoenix with BSD 3-Clause "New" or "Revised" License | 5 votes |
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(); }
Example 15
Source File: ResultUtil.java From phoenix with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Binary search for latest column value without allocating memory in the process * @param r * @param searchTerm */ public static KeyValue getColumnLatest(Result r, KeyValue searchTerm) { KeyValue [] kvs = r.raw(); // side effect possibly. if (kvs == null || kvs.length == 0) { return null; } // pos === ( -(insertion point) - 1) int pos = Arrays.binarySearch(kvs, searchTerm, KeyValue.COMPARATOR); // never will exact match if (pos < 0) { pos = (pos+1) * -1; // pos is now insertion point } if (pos == kvs.length) { return null; // doesn't exist } KeyValue kv = kvs[pos]; if (Bytes.compareTo(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength(), searchTerm.getBuffer(), searchTerm.getFamilyOffset(), searchTerm.getFamilyLength()) != 0) { return null; } if (Bytes.compareTo(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength(), searchTerm.getBuffer(), searchTerm.getQualifierOffset(), searchTerm.getQualifierLength()) != 0) { return null; } return kv; }
Example 16
Source File: Sequence.java From phoenix with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example 17
Source File: Sequence.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static KeyValue getCurrentValueKV(Result r) { KeyValue[] kvs = r.raw(); assert(kvs.length == SEQUENCE_KEY_VALUES); return kvs[CURRENT_VALUE_INDEX]; }
Example 18
Source File: Sequence.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static KeyValue getIncrementByKV(Result r) { KeyValue[] kvs = r.raw(); assert(kvs.length == SEQUENCE_KEY_VALUES); return kvs[INCREMENT_BY_INDEX]; }
Example 19
Source File: Sequence.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static KeyValue getCacheSizeKV(Result r) { KeyValue[] kvs = r.raw(); assert(kvs.length == SEQUENCE_KEY_VALUES); return kvs[CACHE_SIZE_INDEX]; }
Example 20
Source File: Sequence.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
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); }