/** * Checks for existence of a value for the specified column (empty or not). * * @param family family name * @param qualifier column qualifier * * @return true if at least one value exists in the result, false if not */ public boolean containsColumn(byte [] family, byte [] qualifier) { Cell kv = getColumnLatestCell(family, qualifier); return kv != null; }
/** * Checks for existence of a value for the specified column (empty or not). * * @param family family name * @param foffset family offset * @param flength family length * @param qualifier column qualifier * @param qoffset qualifier offset * @param qlength qualifier length * * @return true if at least one value exists in the result, false if not */ public boolean containsColumn(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength) { return getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength) != null; }
/** * Get the latest version of the specified column. * Note: this call clones the value content of the hosting Cell. See * {@link #getValueAsByteBuffer(byte[], byte[])}, etc., or {@link #listCells()} if you would * avoid the cloning. * @param family family name * @param qualifier column qualifier * @return value of latest version of column, null if none found */ public byte[] getValue(byte [] family, byte [] qualifier) { Cell kv = getColumnLatestCell(family, qualifier); if (kv == null) { return null; } return CellUtil.cloneValue(kv); }
/** * Checks if the specified column contains an empty value (a zero-length byte array). * * @param family family name * @param foffset family offset * @param flength family length * @param qualifier column qualifier * @param qoffset qualifier offset * @param qlength qualifier length * * @return whether or not a latest value exists and is empty */ public boolean containsEmptyColumn(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength) { Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength); return (kv != null) && (kv.getValueLength() == 0); }
/** * Checks if the specified column contains a non-empty value (not a zero-length byte array). * * @param family family name * @param foffset family offset * @param flength family length * @param qualifier column qualifier * @param qoffset qualifier offset * @param qlength qualifier length * * @return whether or not a latest value exists and is not empty */ public boolean containsNonEmptyColumn(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength) { Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength); return (kv != null) && (kv.getValueLength() > 0); }
/** * Returns the value wrapped in a new <code>ByteBuffer</code>. * * @param family family name * @param qualifier column qualifier * * @return the latest version of the column, or <code>null</code> if none found */ public ByteBuffer getValueAsByteBuffer(byte [] family, byte [] qualifier) { Cell kv = getColumnLatestCell(family, 0, family.length, qualifier, 0, qualifier.length); if (kv == null) { return null; } return ByteBuffer.wrap(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()). asReadOnlyBuffer(); }
private static Optional<TableState> getTableState(Result r) throws IOException { Cell cell = r.getColumnLatestCell(getTableFamily(), getStateColumn()); if (cell == null) return Optional.empty(); try { return Optional.of(TableState.parseFrom( TableName.valueOf(r.getRow()), Arrays.copyOfRange(cell.getValueArray(), cell.getValueOffset(), cell.getValueOffset() + cell.getValueLength()))); } catch (DeserializationException e) { throw new IOException("Failed to parse table state from result: " + r, e); } }
private void consume(Result r, int nBytesToConsume) { Cell cell = r.getColumnLatestCell(CF, QN); byte mix = 0; byte[] valueArray = cell.getValueArray(); int n = Math.min(nBytesToConsume, cell.getValueLength()); for (int i = 0; i < n; i++) { mix ^= valueArray[i]; bytesRead++; } discard(mix); rowsRead++; }
/** * Returns the RegionInfo object from the column {@link HConstants#CATALOG_FAMILY} and * <code>qualifier</code> of the catalog table result. * @param r a Result object from the catalog table scan * @param qualifier Column family qualifier * @return An RegionInfo instance. */ private static Optional<RegionInfo> getHRegionInfo(final Result r, byte[] qualifier) { Cell cell = r.getColumnLatestCell(getCatalogFamily(), qualifier); if (cell == null) return Optional.empty(); return Optional.ofNullable(RegionInfo.parseFromOrNull(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); }
protected List<String> extractAuths(String user, List<Result> results) { List<String> auths = new ArrayList<>(); for (Result result : results) { Cell labelCell = result.getColumnLatestCell(LABELS_TABLE_FAMILY, LABEL_QUALIFIER); Cell userAuthCell = result.getColumnLatestCell(LABELS_TABLE_FAMILY, Bytes.toBytes(user)); if (userAuthCell != null) { auths.add(Bytes.toString(labelCell.getValueArray(), labelCell.getValueOffset(), labelCell.getValueLength())); } } return auths; }
/** * Pull the region state from a catalog table {@link Result}. * @param r Result to pull the region state from * @return the region state, or null if unknown. */ @VisibleForTesting public static State getRegionState(final Result r, int replicaId) { Cell cell = r.getColumnLatestCell(HConstants.CATALOG_FAMILY, getStateColumn(replicaId)); if (cell == null || cell.getValueLength() == 0) { return null; } return State.valueOf(Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); }
/** * Returns the RegionInfo object from the column {@link HConstants#CATALOG_FAMILY} and * <code>qualifier</code> of the catalog table result. * @param r a Result object from the catalog table scan * @param qualifier Column family qualifier * @return An RegionInfo instance or null. */ @Nullable private static RegionInfo getRegionInfo(final Result r, byte [] qualifier) { Cell cell = r.getColumnLatestCell(getCatalogFamily(), qualifier); if (cell == null) return null; return RegionInfo.parseFromOrNull(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); }
public void testBasicGetColumn() throws Exception { KeyValue [] kvs = genKVs(row, family, value, 1, 100); Arrays.sort(kvs, CellComparator.getInstance()); Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); List<Cell> ks = r.getColumnCells(family, qf); assertEquals(1, ks.size()); assertTrue(CellUtil.matchingQualifier(ks.get(0), qf)); assertEquals(ks.get(0), r.getColumnLatestCell(family, qf)); } }
/** * The latest seqnum that the server writing to meta observed when opening the region. * E.g. the seqNum when the result of {@link #getServerName(Result, int)} was written. * @param r Result to pull the seqNum from * @return SeqNum, or HConstants.NO_SEQNUM if there's no value written. */ private static long getSeqNumDuringOpen(final Result r, final int replicaId) { Cell cell = r.getColumnLatestCell(getCatalogFamily(), getSeqNumColumn(replicaId)); if (cell == null || cell.getValueLength() == 0) return HConstants.NO_SEQNUM; return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); }
/** * The latest seqnum that the server writing to meta observed when opening the region. * E.g. the seqNum when the result of {@link #getServerName(Result, int)} was written. * @param r Result to pull the seqNum from * @return SeqNum, or HConstants.NO_SEQNUM if there's no value written. */ private static long getSeqNumDuringOpen(final Result r, final int replicaId) { Cell cell = r.getColumnLatestCell(getCatalogFamily(), getSeqNumColumn(replicaId)); if (cell == null || cell.getValueLength() == 0) return HConstants.NO_SEQNUM; return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); }
@Test public void testReadFromCorruptMobFilesWithReadEmptyValueOnMobCellMiss() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); setUp(0, tableName); createRecordAndCorruptMobFile(tableName, row1, family, qf1, Bytes.toBytes("value1")); Get get = new Get(row1); get.setAttribute(MobConstants.EMPTY_VALUE_ON_MOBCELL_MISS, Bytes.toBytes(true)); Result result = table.get(get); Cell cell = result.getColumnLatestCell(family, qf1); Assert.assertEquals(0, cell.getValueLength()); }
private void loadNamespaceIntoCache() throws IOException { try (Table table = masterServices.getConnection().getTable(TableName.META_TABLE_NAME); ResultScanner scanner = table.getScanner(HConstants.NAMESPACE_FAMILY)) { for (Result result;;) { result = scanner.next(); if (result == null) { break; } Cell cell = result.getColumnLatestCell(HConstants.NAMESPACE_FAMILY, HConstants.NAMESPACE_COL_DESC_QUALIFIER); NamespaceDescriptor ns = ProtobufUtil .toNamespaceDescriptor(HBaseProtos.NamespaceDescriptor.parseFrom(CodedInputStream .newInstance(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()))); cache.put(ns.getName(), ns); } } }
public static void assertEmptyMetaLocation(Table meta, byte[] row, int replicaId) throws IOException { Get get = new Get(row); Result result = meta.get(get); Cell serverCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(replicaId)); Cell startCodeCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(replicaId)); assertNotNull(serverCell); assertNotNull(startCodeCell); assertEquals(0, serverCell.getValueLength()); assertEquals(0, startCodeCell.getValueLength()); }
static void verifyTestDataBatch(TableName tableName, int batchId) throws Exception { LOG.debug("Verifying test data batch " + batchId); Table table = TEST_UTIL.getConnection().getTable(tableName); for (int i = 0; i < NUM_ROWS_PER_BATCH; ++i) { Get get = new Get(getRowKey(batchId, i)); Result result = table.get(get); for (int j = 0; j < NUM_COLS_PER_ROW; ++j) { Cell kv = result.getColumnLatestCell(CF_BYTES, getQualifier(j)); if (kv == null) { continue; } assertTrue(CellUtil.matchingValue(kv, getValue(batchId, i, j))); } } table.close(); }
@Test public void testVisibilityLabelsWithGet() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL + "&!" + PRIVATE, SECRET + "&" + CONFIDENTIAL + "&" + PRIVATE)) { Get get = new Get(row1); get.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); Result result = table.get(get); assertTrue(!result.isEmpty()); Cell cell = result.getColumnLatestCell(fam, qual); assertTrue(Bytes.equals(value, 0, value.length, cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); } }