/** * Delete all columns of the specified family with a timestamp equal to * the specified timestamp. * @param family family name * @param timestamp version timestamp * @return this for invocation chaining */ public Delete addFamilyVersion(final byte [] family, final long timestamp) { List<Cell> list = getCellList(family); list.add(new KeyValue(row, family, null, timestamp, KeyValue.Type.DeleteFamilyVersion)); return this; }
static Cell[] getCells(final int howMany, final int valueSize) { Cell[] cells = new Cell[howMany]; byte[] value = new byte[valueSize]; for (int i = 0; i < howMany; i++) { byte[] index = Bytes.toBytes(i); KeyValue kv = new KeyValue(index, Bytes.toBytes("f"), index, value); cells[i] = kv; } return cells; }
@Test public void testCommonPrefixComparators() { KeyValue kv1 = new KeyValue(row1, fam1, qual1, 1L, Type.Put); KeyValue kv2 = new KeyValue(row1, fam_1_2, qual1, 1L, Type.Maximum); assertTrue((BufferedDataBlockEncoder.compareCommonFamilyPrefix(kv1, kv2, 4) < 0)); kv1 = new KeyValue(row1, fam1, qual1, 1L, Type.Put); kv2 = new KeyValue(row_1_0, fam_1_2, qual1, 1L, Type.Maximum); assertTrue((BufferedDataBlockEncoder.compareCommonRowPrefix(kv1, kv2, 4) < 0)); kv1 = new KeyValue(row1, fam1, qual2, 1L, Type.Put); kv2 = new KeyValue(row1, fam1, qual1, 1L, Type.Maximum); assertTrue((BufferedDataBlockEncoder.compareCommonQualifierPrefix(kv1, kv2, 4) > 0)); }
@Test public void testMetaComparatorTableKeysWithCommaOk() { CellComparator c = CellComparatorImpl.META_COMPARATOR; long now = System.currentTimeMillis(); // meta keys values are not quite right. A users can enter illegal values // from shell when scanning meta. KeyValue a = new KeyValue(Bytes.toBytes("table,key,with,commas1,1234"), now); KeyValue b = new KeyValue(Bytes.toBytes("table,key,with,commas2,0123"), now); assertTrue(c.compare(a, b) < 0); }
/** * Generate a list of KeyValues for testing based on given parameters * @param timestamps * @param numRows * @param qualifier * @param family * @return */ List<Cell> getKeyValueSet(long[] timestamps, int numRows, byte[] qualifier, byte[] family) { List<Cell> kvList = new ArrayList<>(); for (int i=1;i<=numRows;i++) { byte[] b = Bytes.toBytes(i); for (long timestamp: timestamps) { kvList.add(new KeyValue(b, family, qualifier, timestamp, b)); } } return kvList; }
/** * Test a corner case when the family qualifier is a prefix of the * column qualifier. */ @Test public void testColumnCompare_prefix() throws Exception { final byte [] a = Bytes.toBytes("aaa"); byte [] family1 = Bytes.toBytes("abc"); byte [] qualifier1 = Bytes.toBytes("def"); byte [] family2 = Bytes.toBytes("ab"); byte [] qualifier2 = Bytes.toBytes("def"); KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, KeyValue.Type.Put, a); assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2)); }
private void comparisons(final CellComparatorImpl c) { long now = System.currentTimeMillis(); assertTrue(c.compare(new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now), new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now)) == 0); assertTrue(c.compare(new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now), new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,2"), now)) < 0); assertTrue(c.compare(new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,2"), now), new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now)) > 0); }
/** * The more specific functionality tests are contained within the TestFilters class. This class is mainly for testing * serialization * * @param filter * @throws Exception */ private void basicFilterTests(ColumnPaginationFilter filter) throws Exception { KeyValue c = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1); assertTrue("basicFilter1", filter.filterCell(c) == Filter.ReturnCode.INCLUDE_AND_NEXT_COL); }
@Test public void testDeletedByDeleteFamily() { KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"), timestamp, KeyValue.Type.DeleteFamily); sdt.add(kv); timestamp -= 5; kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"), timestamp, KeyValue.Type.DeleteColumn); DeleteResult ret = sdt.isDeleted(kv); assertEquals(DeleteResult.FAMILY_DELETED, ret); }
/** * Delete the specified version of the specified column. * @param family family name * @param qualifier column qualifier * @param timestamp version timestamp * @return this for invocation chaining */ public Delete addColumn(byte [] family, byte [] qualifier, long timestamp) { if (timestamp < 0) { throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); } List<Cell> list = getCellList(family); KeyValue kv = new KeyValue(this.row, family, qualifier, timestamp, KeyValue.Type.Delete); list.add(kv); return this; }
private KeyValue createKV(int noOfTags) { byte[] row = Bytes.toBytes("myRow"); byte[] cf = Bytes.toBytes("myCF"); byte[] q = Bytes.toBytes("myQualifier"); byte[] value = Bytes.toBytes("myValue"); List<Tag> tags = new ArrayList<>(noOfTags); for (int i = 1; i <= noOfTags; i++) { tags.add(new ArrayBackedTag((byte) i, Bytes.toBytes("tagValue" + i))); } return new KeyValue(row, cf, q, HConstants.LATEST_TIMESTAMP, value, tags); }
@Test public void testCompareCells() { KeyValue kv1 = new KeyValue(row1, fam1, qual1, val); KeyValue kv2 = new KeyValue(row2, fam1, qual1, val); assertTrue((comparator.compare(kv1, kv2)) < 0); kv1 = new KeyValue(row1, fam2, qual1, val); kv2 = new KeyValue(row1, fam1, qual1, val); assertTrue((comparator.compareFamilies(kv1, kv2) > 0)); kv1 = new KeyValue(row1, fam1, qual1, 1L, val); kv2 = new KeyValue(row1, fam1, qual1, 2L, val); assertTrue((comparator.compare(kv1, kv2) > 0)); kv1 = new KeyValue(row1, fam1, qual1, 1L, Type.Put); kv2 = new KeyValue(row1, fam1, qual1, 1L, Type.Maximum); assertTrue((comparator.compare(kv1, kv2) > 0)); kv1 = new KeyValue(row1, fam1, qual1, 1L, Type.Put); kv2 = new KeyValue(row1, fam1, qual1, 1L, Type.Put); assertTrue((CellUtil.equals(kv1, kv2))); }
@Test public void testResult() throws Exception { // Initialize a result KeyValue[] kvs = new KeyValue[] { new KeyValue(Bytes.toBytes("test-row"), Bytes.toBytes("cfa"), Bytes.toBytes("col1"), Bytes.toBytes("cfacol1")), new KeyValue(Bytes.toBytes("test-row"), Bytes.toBytes("cfa"), Bytes.toBytes("col2"), Bytes.toBytes("cfacol2")) }; Result expected = Result.create(kvs); ResultWritable actual = copy(new ResultWritable(expected), new ResultWritable()); Assert.assertArrayEquals(expected.rawCells(), actual.getResult().rawCells()); }
private void metacomparisons(final CellComparatorImpl c) { long now = System.currentTimeMillis(); assertTrue(c.compare(new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now), new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now)) == 0); KeyValue a = new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now); KeyValue b = new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,2"), now); assertTrue(c.compare(a, b) < 0); assertTrue(c.compare(new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,2"), now), new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now)) > 0); }
private void check(final byte [] row, final byte [] family, byte [] qualifier, final long timestamp, final byte [] value) { KeyValue kv = new KeyValue(row, family, qualifier, timestamp, value); assertTrue(Bytes.compareTo(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(), row, 0, row.length) == 0); assertTrue(CellUtil.matchingColumn(kv, family, qualifier)); // Call toString to make sure it works. LOG.info(kv.toString()); }
@Test public void testDeletedByDeleteColumn() { KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"), timestamp, KeyValue.Type.DeleteColumn); sdt.add(kv); timestamp -= 5; kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"), timestamp, KeyValue.Type.DeleteColumn); DeleteResult ret = sdt.isDeleted(kv); assertEquals(DeleteResult.COLUMN_DELETED, ret); }
/** * Delete all versions of the specified column with a timestamp less than * or equal to the specified timestamp. * @param family family name * @param qualifier column qualifier * @param timestamp maximum version timestamp * @return this for invocation chaining */ public Delete addColumns(final byte [] family, final byte [] qualifier, final long timestamp) { if (timestamp < 0) { throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); } List<Cell> list = getCellList(family); list.add(new KeyValue(this.row, family, qualifier, timestamp, KeyValue.Type.DeleteColumn)); return this; }
@Override public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<Cell> result) throws IOException { if (get.getAttribute("count") != null) { result.clear(); // order is important! result.add(new KeyValue(count, count, delete, Bytes.toBytes(nDelete))); result.add(new KeyValue(count, count, put, Bytes.toBytes(nCount))); c.bypass(); } } }