/** * Create a Cell with specific row. Other fields defaulted. * @param row * @return Cell with passed row but all other fields are arbitrary * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. Use {@link CellBuilder} * instead */ @Deprecated public static Cell createCell(final byte[] row) { return createCell(row, HConstants.EMPTY_BYTE_ARRAY); }
/** * Marked as audience Private as of 1.2.0. * Creating a Cell with a memstoreTS/mvcc is an internal * implementation detail not for public use. * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. Use * {@link ExtendedCellBuilder} instead */ @InterfaceAudience.Private @Deprecated public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, final long timestamp, final byte type, final byte[] value, final long memstoreTS) { return createCell(row, family, qualifier, timestamp, type, value, null, memstoreTS); }
static Cell createCell(final byte [] keyRow) { return CellUtil.createCell(keyRow); }
static Cell createCell(final byte [] keyRow, final byte [] value) { return CellUtil.createCell(keyRow, value); }
/** * Create a Cell with specific row. Other fields defaulted. * @param row * @param family * @param qualifier * @return Cell with passed row but all other fields are arbitrary * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. * Use {@link CellBuilder} instead */ @Deprecated public static Cell createCell(final byte [] row, final byte [] family, final byte [] qualifier) { // See above in createCell(final byte [] row, final byte [] value) why we set type to Maximum. return createCell(row, family, qualifier, HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), HConstants.EMPTY_BYTE_ARRAY); }
/** * Create a Cell with specific row and value. Other fields are defaulted. * @param row * @param value * @return Cell with passed row and value but all other fields are arbitrary * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. Use {@link CellBuilder} * instead */ @Deprecated public static Cell createCell(final byte[] row, final byte[] value) { // An empty family + empty qualifier + Type.Minimum is used as flag to indicate last on row. // See the CellComparator and KeyValue comparator. Search for compareWithoutRow. // Lets not make a last-on-row key as default but at same time, if you are making a key // without specifying type, etc., flag it as weird by setting type to be Maximum. return createCell(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), value); }
/** * Marked as audience Private as of 1.2.0. * Creating a Cell with tags is an internal implementation detail not for public use. * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. Use * {@link ExtendedCellBuilder} instead */ @InterfaceAudience.Private @Deprecated public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, final long timestamp, Type type, final byte[] value, byte[] tags) { return createCell(row, family, qualifier, timestamp, type.getCode(), value, tags, 0); }
@Test public void testCollectFamilies() { byte[] family0 = Bytes.toBytes("family0"); byte[] family1 = Bytes.toBytes("family1"); byte[] family2 = Bytes.toBytes("family2"); List<Cell> cells = new ArrayList<>(); assertEquals(0, FSWALEntry.collectFamilies(cells).size()); cells.add(CellUtil.createCell(family0, family0, family0)); assertEquals(1, FSWALEntry.collectFamilies(cells).size()); cells.add(CellUtil.createCell(family1, family1, family1)); assertEquals(2, FSWALEntry.collectFamilies(cells).size()); cells.add(CellUtil.createCell(family0, family0, family0)); cells.add(CellUtil.createCell(family1, family1, family1)); assertEquals(2, FSWALEntry.collectFamilies(cells).size()); cells.add(CellUtil.createCell(family2, family2, family2)); assertEquals(3, FSWALEntry.collectFamilies(cells).size()); cells.add(CellUtil.createCell(WALEdit.METAFAMILY, WALEdit.METAFAMILY, WALEdit.METAFAMILY)); assertEquals(3, FSWALEntry.collectFamilies(cells).size()); } }
@Test public void testShortMidpointSameQual() { Cell left = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"), 11, KeyValue.Type.Maximum.getCode(), HConstants.EMPTY_BYTE_ARRAY); Cell right = CellUtil.createCell(Bytes.toBytes("a"), Bytes.toBytes("a"), Bytes.toBytes("a"), 9, KeyValue.Type.Maximum.getCode(), HConstants.EMPTY_BYTE_ARRAY); Cell mid = HFileWriterImpl.getMidpoint(CellComparatorImpl.COMPARATOR, left, right); assertTrue(PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, left, mid) <= 0); assertTrue(PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, mid, right) == 0); }
public static void doSmokeTest(FileSystem fs, Path path, String codec) throws Exception { Configuration conf = HBaseConfiguration.create(); HFileContext context = new HFileContextBuilder() .withCompression(HFileWriterImpl.compressionByName(codec)).build(); HFile.Writer writer = HFile.getWriterFactoryNoCache(conf) .withPath(fs, path) .withFileContext(context) .create(); // Write any-old Cell... final byte [] rowKey = Bytes.toBytes("compressiontestkey"); Cell c = CellUtil.createCell(rowKey, Bytes.toBytes("compressiontestval")); writer.append(c); writer.appendFileInfo(Bytes.toBytes("compressioninfokey"), Bytes.toBytes("compressioninfoval")); writer.close(); Cell cc = null; HFile.Reader reader = HFile.createReader(fs, path, CacheConfig.DISABLED, true, conf); try { reader.loadFileInfo(); HFileScanner scanner = reader.getScanner(false, true); scanner.seekTo(); // position to the start of file // Scanner does not do Cells yet. Do below for now till fixed. cc = scanner.getCell(); if (CellComparator.getInstance().compareRows(c, cc) != 0) { throw new Exception("Read back incorrect result: " + c.toString() + " vs " + cc.toString()); } } finally { reader.close(); } }
@Test public void testToString1() { String row = "test.row"; String family = "test.family"; String qualifier = "test.qualifier"; long timestamp = 42; KeyValue.Type type = KeyValue.Type.Put; String value = "test.value"; long seqId = 1042; Cell cell = CellUtil.createCell(Bytes.toBytes(row), Bytes.toBytes(family), Bytes.toBytes(qualifier), timestamp, type.getCode(), Bytes.toBytes(value), seqId); String nonVerbose = CellUtil.toString(cell, false); String verbose = CellUtil.toString(cell, true); System.out.println("nonVerbose=" + nonVerbose); System.out.println("verbose=" + verbose); Assert.assertEquals( String.format("%s/%s:%s/%d/%s/vlen=%s/seqid=%s", row, family, qualifier, timestamp, type.toString(), Bytes.toBytes(value).length, seqId), nonVerbose); Assert.assertEquals( String.format("%s/%s:%s/%d/%s/vlen=%s/seqid=%s/%s", row, family, qualifier, timestamp, type.toString(), Bytes.toBytes(value).length, seqId, value), verbose); // TODO: test with tags }
keys.add(k); byte[] v = Bytes.toBytes("value" + i); hfw.append(CellUtil.createCell(k, v)); scanner.seekTo(CellUtil.createCell(keys.get(i)));
COLUMN_FAMILY_BYTES); Cell originalCell = CellUtil.createCell(row, COLUMN_FAMILY_BYTES, qual1, System.currentTimeMillis(), KeyValue.Type.Put.getCode(), value1); final long originalSize = originalCell.getSerializedSize(); Cell addCell = CellUtil.createCell(row, COLUMN_FAMILY_BYTES, qual1, System.currentTimeMillis(), KeyValue.Type.Put.getCode(), Bytes.toBytes("xxxxxxxxxx")); final long addSize = addCell.getSerializedSize();
System.arraycopy(b, 0, rowkey, rowkey.length - b.length, b.length); keys.add(rowkey); hfw.append(CellUtil.createCell(rowkey)); scanner.seekTo(CellUtil.createCell(keys.get(i)));
private String createHFileForFamilies(byte[] family) throws IOException { HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(conf); // TODO We need a way to do this without creating files File hFileLocation = testFolder.newFile(); FSDataOutputStream out = new FSDataOutputStream(new FileOutputStream(hFileLocation), null); try { hFileFactory.withOutputStream(out); hFileFactory.withFileContext(new HFileContext()); HFile.Writer writer = hFileFactory.create(); try { writer.append(new KeyValue(CellUtil.createCell(randomBytes, family, randomBytes, 0L, KeyValue.Type.Put.getCode(), randomBytes))); } finally { writer.close(); } } finally { out.close(); } return hFileLocation.getAbsoluteFile().getAbsolutePath(); }
private String createHFileForFamilies(Path testPath, byte[] family, byte[] valueBytes) throws IOException { HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(TEST_UTIL.getConfiguration()); // TODO We need a way to do this without creating files Path testFile = new Path(testPath, TEST_UTIL.getRandomUUID().toString()); FSDataOutputStream out = TEST_UTIL.getTestFileSystem().create(testFile); try { hFileFactory.withOutputStream(out); hFileFactory.withFileContext(new HFileContext()); HFile.Writer writer = hFileFactory.create(); try { writer.append(new KeyValue(CellUtil.createCell(valueBytes, family, valueBytes, 0L, KeyValue.Type.Put.getCode(), valueBytes))); } finally { writer.close(); } } finally { out.close(); } return testFile.toString(); }
@Test public void testHeapSize() { Cell originalCell = CellUtil.createCell(Bytes.toBytes("row"), Bytes.toBytes("value")); final int fakeTagArrayLength = 10; Cell trCell = PrivateCellUtil.createCell(originalCell, new byte[fakeTagArrayLength]); // Get the heapSize before the internal tags array in trCell are nuked long trCellHeapSize = ((HeapSize)trCell).heapSize(); // Make another TagRewriteCell with the original TagRewriteCell // This happens on systems with more than one RegionObserver/Coproc loaded (such as // VisibilityController and AccessController) Cell trCell2 = PrivateCellUtil.createCell(trCell, new byte[fakeTagArrayLength]); assertTrue("TagRewriteCell containing a TagRewriteCell's heapsize should be " + "larger than a single TagRewriteCell's heapsize", trCellHeapSize < ((HeapSize)trCell2).heapSize()); assertTrue("TagRewriteCell should have had nulled out tags array", ((HeapSize)trCell).heapSize() < trCellHeapSize); } }
/** * Assert CellUtil makes Cell toStrings same way we do KeyValue toStrings. */ @Test public void testToString() { byte [] row = Bytes.toBytes("row"); long ts = 123L; // Make a KeyValue and a Cell and see if same toString result. KeyValue kv = new KeyValue(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, ts, KeyValue.Type.Minimum, HConstants.EMPTY_BYTE_ARRAY); Cell cell = CellUtil.createCell(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, ts, KeyValue.Type.Minimum.getCode(), HConstants.EMPTY_BYTE_ARRAY); String cellToString = CellUtil.getCellKeyAsString(cell); assertEquals(kv.toString(), cellToString); // Do another w/ non-null family. byte [] f = new byte [] {'f'}; byte [] q = new byte [] {'q'}; kv = new KeyValue(row, f, q, ts, KeyValue.Type.Minimum, HConstants.EMPTY_BYTE_ARRAY); cell = CellUtil.createCell(row, f, q, ts, KeyValue.Type.Minimum.getCode(), HConstants.EMPTY_BYTE_ARRAY); cellToString = CellUtil.getCellKeyAsString(cell); assertEquals(kv.toString(), cellToString); }
@Test public void testAppendWithCustomTimestamp() throws IOException { TableName TABLENAME = TableName.valueOf(name.getMethodName()); Table table = TEST_UTIL.createTable(TABLENAME, FAMILY); long timestamp = 999; Append append = new Append(ROW); append.add(CellUtil.createCell(ROW, FAMILY, QUALIFIER, timestamp, KeyValue.Type.Put.getCode(), Bytes.toBytes(100L))); Result r = table.append(append); assertEquals(1, r.size()); assertEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.get(new Get(ROW)); assertEquals(1, r.size()); assertEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.append(append); assertEquals(1, r.size()); assertNotEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.get(new Get(ROW)); assertEquals(1, r.size()); assertNotEquals(timestamp, r.rawCells()[0].getTimestamp()); } }
@Test public void testIncrementWithCustomTimestamp() throws IOException { TableName TABLENAME = TableName.valueOf(name.getMethodName()); Table table = TEST_UTIL.createTable(TABLENAME, FAMILY); long timestamp = 999; Increment increment = new Increment(ROW); increment.add(CellUtil.createCell(ROW, FAMILY, QUALIFIER, timestamp, KeyValue.Type.Put.getCode(), Bytes.toBytes(100L))); Result r = table.increment(increment); assertEquals(1, r.size()); assertEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.get(new Get(ROW)); assertEquals(1, r.size()); assertEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.increment(increment); assertEquals(1, r.size()); assertNotEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.get(new Get(ROW)); assertEquals(1, r.size()); assertNotEquals(timestamp, r.rawCells()[0].getTimestamp()); }