private boolean hasOneMatchingQualifier(Cell c) { for (byte[] q : qualifiers) { if (CellUtil.matchingQualifier(c, q)) { return true; } } return false; }
public static boolean matchingColumn(final Cell left, final byte[] fam, final byte[] qual) { if (!matchingFamily(left, fam)) return false; return matchingQualifier(left, qual); }
public static boolean matchingColumn(final Cell left, final Cell right) { if (!matchingFamily(left, right)) return false; return matchingQualifier(left, right); }
/** * Finds if the qualifier part of the cell and the KV serialized * byte[] are equal * @param left * @param buf the serialized keyvalue format byte[] * @return true if the qualifier matches, false otherwise */ public static boolean matchingQualifier(final Cell left, final byte[] buf) { if (buf == null) { return left.getQualifierLength() == 0; } return matchingQualifier(left, buf, 0, buf.length); }
/** * Returns a list of all KeyValue objects with matching column family and qualifier. * * @param family column family * @param qualifier column qualifier * @return a list of KeyValue objects with the matching family and qualifier, * returns an empty list if one doesn't exist for the given family. */ public List<Cell> get(byte[] family, byte[] qualifier) { List<Cell> filteredList = new ArrayList<>(); for (Cell cell: getCellList(family)) { if (CellUtil.matchingQualifier(cell, qualifier)) { filteredList.add(cell); } } return filteredList; }
private boolean hasColumn(final List<Cell> kvs, final byte [] family, final byte [] qualifier) { for (Cell kv: kvs) { if (CellUtil.matchingFamily(kv, family) && CellUtil.matchingQualifier(kv, qualifier)) { return true; } } return false; }
private Cell getColumn(final List<Cell> kvs, final byte [] family, final byte [] qualifier) { for (Cell kv: kvs) { if (CellUtil.matchingFamily(kv, family) && CellUtil.matchingQualifier(kv, qualifier)) { return kv; } } return null; }
protected Pair<Map<String, Integer>, Map<String, List<Integer>>> extractLabelsAndAuths( List<List<Cell>> labelDetails) { Map<String, Integer> labels = new HashMap<>(); Map<String, List<Integer>> userAuths = new HashMap<>(); for (List<Cell> cells : labelDetails) { for (Cell cell : cells) { if (CellUtil.matchingQualifier(cell, LABEL_QUALIFIER)) { labels.put( Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()), PrivateCellUtil.getRowAsInt(cell)); } else { // These are user cells who has authorization for this label String user = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); List<Integer> auths = userAuths.get(user); if (auths == null) { auths = new ArrayList<>(); userAuths.put(user, auths); } auths.add(PrivateCellUtil.getRowAsInt(cell)); } } } return new Pair<>(labels, userAuths); }
/**************** equals ****************************/ public static boolean equals(Cell a, Cell b) { return matchingRows(a, b) && matchingFamily(a, b) && matchingQualifier(a, b) && matchingTimestamp(a, b) && PrivateCellUtil.matchingType(a, b); }
private void cleanUpHFileRefs(WALEdit edit) throws IOException { String peerId = source.getPeerId(); if (peerId.contains("-")) { // peerClusterZnode will be in the form peerId + "-" + rsZNode. // A peerId will not have "-" in its name, see HBASE-11394 peerId = peerId.split("-")[0]; } List<Cell> cells = edit.getCells(); int totalCells = cells.size(); for (int i = 0; i < totalCells; i++) { Cell cell = cells.get(i); if (CellUtil.matchingQualifier(cell, WALEdit.BULK_LOAD)) { BulkLoadDescriptor bld = WALEdit.getBulkLoadDescriptor(cell); List<StoreDescriptor> stores = bld.getStoresList(); int totalStores = stores.size(); for (int j = 0; j < totalStores; j++) { List<String> storeFileList = stores.get(j).getStoreFileList(); source.getSourceManager().cleanUpHFileRefs(peerId, storeFileList); source.getSourceMetrics().decrSizeOfHFileRefsQueue(storeFileList.size()); } } } }
/** * Checks if this permission grants access to perform the given action on * the given table and key value. * @param table the table on which the operation is being performed * @param kv the KeyValue on which the operation is being requested * @param action the action requested * @return <code>true</code> if the action is allowed over the given scope * by this permission, otherwise <code>false</code> */ public boolean implies(TableName table, KeyValue kv, Action action) { if (failCheckTable(table)) { return false; } if (family != null && !(CellUtil.matchingFamily(kv, family))) { return false; } if (qualifier != null && !(CellUtil.matchingQualifier(kv, qualifier))) { return false; } // check actions return super.implies(action); }
private static void verifyData(Cell kv, String expectedRow, String expectedCol, long expectedVersion) { assertTrue("RowCheck", CellUtil.matchingRows(kv, Bytes.toBytes(expectedRow))); assertTrue("ColumnCheck", CellUtil.matchingQualifier(kv, Bytes.toBytes(expectedCol))); assertEquals("TSCheck", expectedVersion, kv.getTimestamp()); assertTrue("ValueCheck", CellUtil.matchingValue(kv, genValue(expectedRow, expectedCol, expectedVersion))); }
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)); } }
public void testMultiVersionGetColumn() throws Exception { KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); 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(2, ks.size()); assertTrue(CellUtil.matchingQualifier(ks.get(0), qf)); assertEquals(200, ks.get(0).getTimestamp()); assertEquals(ks.get(0), r.getColumnLatestCell(family, qf)); } }
private void isExpectedRowWithoutTimestamps(final int rowIndex, List<Cell> kvs) { int i = 0; for (Cell kv : kvs) { byte[] expectedColname = makeQualifier(rowIndex, i++); assertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname)); // Value is column name as bytes. Usually result is // 100 bytes in size at least. This is the default size // for BytesWriteable. For comparison, convert bytes to // String and trim to remove trailing null bytes. assertTrue("Content", CellUtil.matchingValue(kv, expectedColname)); } }
private void isExpectedRowWithoutTimestamps(final int rowIndex, List<Cell> kvs) { int i = 0; for (Cell kv : kvs) { byte[] expectedColname = makeQualifier(rowIndex, i++); assertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname)); // Value is column name as bytes. Usually result is // 100 bytes in size at least. This is the default size // for BytesWriteable. For comparison, convert bytes to // String and trim to remove trailing null bytes. assertTrue("Content", CellUtil.matchingValue(kv, expectedColname)); } }
private Predicate<Cell> checkVersion(Cell firstCell, int version) { if (version == 0) { return c -> true; } else { if (row == null || !CellUtil.matchingRows(firstCell, row)) { row = CellUtil.cloneRow(firstCell); // reset qualifier as there is a row change qualifier = null; } return c -> { if (qualifier != null && CellUtil.matchingQualifier(c, qualifier)) { if (count >= version) { return true; } count++; return false; } else { // qualifier switch qualifier = CellUtil.cloneQualifier(c); count = 1; return false; } }; } }
private void verifyData(Region newReg, int startRow, int numRows, byte[] qf, byte[]... families) throws IOException { for (int i = startRow; i < startRow + numRows; i++) { byte[] row = Bytes.toBytes("" + i); Get get = new Get(row); for (byte[] family : families) { get.addColumn(family, qf); } Result result = newReg.get(get); Cell[] raw = result.rawCells(); assertEquals(families.length, result.size()); for (int j = 0; j < families.length; j++) { assertTrue(CellUtil.matchingRows(raw[j], row)); assertTrue(CellUtil.matchingFamily(raw[j], families[j])); assertTrue(CellUtil.matchingQualifier(raw[j], qf)); } } }
private void verifyRows(Table t, byte[] family, byte[] column) throws IOException { for (int i = 0; i < 10; i++) { byte[] row = Bytes.toBytes("row" + i); Get g = new Get(row).addFamily(family); Result r = t.get(g); Assert.assertNotNull(r); Assert.assertEquals(1, r.size()); Cell cell = r.rawCells()[0]; Assert.assertTrue(CellUtil.matchingQualifier(cell, column)); Assert.assertEquals(Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), row, 0, row.length), 0); } }
static void verifyData(HRegion newReg, int startRow, int numRows, byte[] qf, byte[]... families) throws IOException { for (int i = startRow; i < startRow + numRows; i++) { byte[] row = Bytes.toBytes("" + i); Get get = new Get(row); for (byte[] family : families) { get.addColumn(family, qf); } Result result = newReg.get(get); Cell[] raw = result.rawCells(); assertEquals(families.length, result.size()); for (int j = 0; j < families.length; j++) { assertTrue(CellUtil.matchingRows(raw[j], row)); assertTrue(CellUtil.matchingFamily(raw[j], families[j])); assertTrue(CellUtil.matchingQualifier(raw[j], qf)); } } }