org.apache.hadoop.hbase.CellBuilderType Java Examples
The following examples show how to use
org.apache.hadoop.hbase.CellBuilderType.
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: TestMutation.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testDeleteCopyConstructor() throws IOException { Delete origin = new Delete(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Type.Delete) .build()); origin.addColumn(family, Bytes.toBytes("q0")); origin.addColumns(family, Bytes.toBytes("q1")); origin.addFamily(family); origin.addColumns(family, Bytes.toBytes("q2"), 100); origin.addFamilyVersion(family, 1000); Delete clone = new Delete(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q3")); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
Example #2
Source File: TestHStore.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testNumberOfMemStoreScannersAfterFlush() throws IOException { long seqId = 100; long timestamp = System.currentTimeMillis(); Cell cell0 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family) .setQualifier(qf1).setTimestamp(timestamp).setType(Cell.Type.Put) .setValue(qf1).build(); PrivateCellUtil.setSequenceId(cell0, seqId); testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Collections.emptyList()); Cell cell1 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family) .setQualifier(qf2).setTimestamp(timestamp).setType(Cell.Type.Put) .setValue(qf1).build(); PrivateCellUtil.setSequenceId(cell1, seqId); testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Arrays.asList(cell1)); seqId = 101; timestamp = System.currentTimeMillis(); Cell cell2 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row2).setFamily(family) .setQualifier(qf2).setTimestamp(timestamp).setType(Cell.Type.Put) .setValue(qf1).build(); PrivateCellUtil.setSequenceId(cell2, seqId); testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Arrays.asList(cell1, cell2)); }
Example #3
Source File: TestHFile.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testShortMidpointSameQual() { Cell left = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(Bytes.toBytes("a")) .setFamily(Bytes.toBytes("a")) .setQualifier(Bytes.toBytes("a")) .setTimestamp(11) .setType(Type.Maximum.getCode()) .setValue(HConstants.EMPTY_BYTE_ARRAY) .build(); Cell right = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(Bytes.toBytes("a")) .setFamily(Bytes.toBytes("a")) .setQualifier(Bytes.toBytes("a")) .setTimestamp(9) .setType(Type.Maximum.getCode()) .setValue(HConstants.EMPTY_BYTE_ARRAY) .build(); Cell mid = HFileWriterImpl.getMidpoint(CellComparatorImpl.COMPARATOR, left, right); assertTrue(PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, left, mid) <= 0); assertTrue(PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, mid, right) == 0); }
Example #4
Source File: SyncTable.java From hbase with Apache License 2.0 | 6 votes |
private Cell checkAndResetTimestamp(Cell sourceCell){ if (ignoreTimestamp) { sourceCell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setType(sourceCell.getType()) .setRow(sourceCell.getRowArray(), sourceCell.getRowOffset(), sourceCell.getRowLength()) .setFamily(sourceCell.getFamilyArray(), sourceCell.getFamilyOffset(), sourceCell.getFamilyLength()) .setQualifier(sourceCell.getQualifierArray(), sourceCell.getQualifierOffset(), sourceCell.getQualifierLength()) .setTimestamp(System.currentTimeMillis()) .setValue(sourceCell.getValueArray(), sourceCell.getValueOffset(), sourceCell.getValueLength()).build(); } return sourceCell; }
Example #5
Source File: ProtobufUtil.java From hbase with Apache License 2.0 | 6 votes |
/** * Convert a protocol buffer Result to a client Result * * @param proto the protocol buffer Result to convert * @return the converted client Result */ public static Result toResult(final ClientProtos.Result proto) { if (proto.hasExists()) { if (proto.getStale()) { return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE_STALE :EMPTY_RESULT_EXISTS_FALSE_STALE; } return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE : EMPTY_RESULT_EXISTS_FALSE; } List<CellProtos.Cell> values = proto.getCellList(); if (values.isEmpty()){ return proto.getStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT; } List<Cell> cells = new ArrayList<>(values.size()); ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); for (CellProtos.Cell c : values) { cells.add(toCell(builder, c)); } return Result.create(cells, null, proto.getStale(), proto.getPartial()); }
Example #6
Source File: TestBulkLoad.java From hbase with Apache License 2.0 | 6 votes |
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 HFileContextBuilder().build()); HFile.Writer writer = hFileFactory.create(); try { writer.append(new KeyValue(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(randomBytes) .setFamily(family) .setQualifier(randomBytes) .setTimestamp(0L) .setType(KeyValue.Type.Put.getCode()) .setValue(randomBytes) .build())); } finally { writer.close(); } } finally { out.close(); } return hFileLocation.getAbsoluteFile().getAbsolutePath(); }
Example #7
Source File: TestProtobufUtil.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testToCell() { KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), new byte[30]); KeyValue kv2 = new KeyValue(Bytes.toBytes("bbb"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), new byte[30]); KeyValue kv3 = new KeyValue(Bytes.toBytes("ccc"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), new byte[30]); byte[] arr = new byte[kv1.getLength() + kv2.getLength() + kv3.getLength()]; System.arraycopy(kv1.getBuffer(), kv1.getOffset(), arr, 0, kv1.getLength()); System.arraycopy(kv2.getBuffer(), kv2.getOffset(), arr, kv1.getLength(), kv2.getLength()); System.arraycopy(kv3.getBuffer(), kv3.getOffset(), arr, kv1.getLength() + kv2.getLength(), kv3.getLength()); ByteBuffer dbb = ByteBuffer.allocateDirect(arr.length); dbb.put(arr); ByteBufferKeyValue offheapKV = new ByteBufferKeyValue(dbb, kv1.getLength(), kv2.getLength()); CellProtos.Cell cell = ProtobufUtil.toCell(offheapKV); Cell newOffheapKV = ProtobufUtil.toCell(ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY), cell); assertTrue(CellComparatorImpl.COMPARATOR.compare(offheapKV, newOffheapKV) == 0); }
Example #8
Source File: TestMutation.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testAppendCopyConstructor() throws IOException { Append origin = new Append(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Type.Put) .setValue(Bytes.toBytes(100)) .build()); origin.addColumn(family, Bytes.toBytes("q0"), Bytes.toBytes("value")); origin.setTimeRange(100, 1000); Append clone = new Append(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("value")); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
Example #9
Source File: TestMutation.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testIncrementCopyConstructor() throws IOException { Increment origin = new Increment(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(100)) .build()); origin.addColumn(family, Bytes.toBytes("q0"), 4); origin.setTimeRange(100, 1000); Increment clone = new Increment(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q1"), 3); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
Example #10
Source File: TestMutation.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testPutCopyConstructor() throws IOException { Put origin = new Put(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Cell.Type.Put) .setValue(Bytes.toBytes("value")) .build()); origin.addColumn(family, Bytes.toBytes("q0"), Bytes.toBytes("V-01")); origin.addColumn(family, Bytes.toBytes("q1"), 100, Bytes.toBytes("V-01")); Put clone = new Put(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q2"), Bytes.toBytes("V-02")); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
Example #11
Source File: DefaultVisibilityLabelServiceImpl.java From hbase with Apache License 2.0 | 6 votes |
protected void addSystemLabel(Region region, Map<String, Integer> labels, Map<String, List<Integer>> userAuths) throws IOException { if (!labels.containsKey(SYSTEM_LABEL)) { byte[] row = Bytes.toBytes(SYSTEM_LABEL_ORDINAL); Put p = new Put(row); p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(row) .setFamily(LABELS_TABLE_FAMILY) .setQualifier(LABEL_QUALIFIER) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(Bytes.toBytes(SYSTEM_LABEL)) .build()); region.put(p); labels.put(SYSTEM_LABEL, SYSTEM_LABEL_ORDINAL); } }
Example #12
Source File: MultiThreadedClientExample.java From hbase with Apache License 2.0 | 6 votes |
@Override public Boolean call() throws Exception { try (Table t = connection.getTable(tableName)) { byte[] value = Bytes.toBytes(Double.toString(ThreadLocalRandom.current().nextDouble())); byte[] rk = Bytes.toBytes(ThreadLocalRandom.current().nextLong()); Put p = new Put(rk); p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(rk) .setFamily(FAMILY) .setQualifier(QUAL) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(value) .build()); t.put(p); } return true; }
Example #13
Source File: FavoredNodeAssignmentHelper.java From hbase with Apache License 2.0 | 6 votes |
/** * Generates and returns a Put containing the region info for the catalog table and the servers * @return Put object */ private static Put makePutFromRegionInfo(RegionInfo regionInfo, List<ServerName> favoredNodeList) throws IOException { Put put = null; if (favoredNodeList != null) { long time = EnvironmentEdgeManager.currentTime(); put = MetaTableAccessor.makePutFromRegionInfo(regionInfo, time); byte[] favoredNodes = getFavoredNodes(favoredNodeList); put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(FAVOREDNODES_QUALIFIER) .setTimestamp(time) .setType(Type.Put) .setValue(favoredNodes) .build()); LOG.debug("Create the region {} with favored nodes {}", regionInfo.getRegionNameAsString(), favoredNodeList); } return put; }
Example #14
Source File: WriteHeavyIncrementObserver.java From hbase with Apache License 2.0 | 6 votes |
@Override public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment) throws IOException { byte[] row = increment.getRow(); Put put = new Put(row); long ts = getUniqueTimestamp(row); for (Map.Entry<byte[], List<Cell>> entry : increment.getFamilyCellMap().entrySet()) { for (Cell cell : entry.getValue()) { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row) .setFamily(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()) .setQualifier(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()) .setValue(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()) .setType(Cell.Type.Put).setTimestamp(ts).build()); } } c.getEnvironment().getRegion().put(put); c.bypass(); return Result.EMPTY_RESULT; }
Example #15
Source File: IndexedKeyValue.java From phoenix with Apache License 2.0 | 6 votes |
private static Cell adaptFirstCellFromMutation(Mutation m) { if (m != null && m.getFamilyCellMap() != null && m.getFamilyCellMap().firstEntry() != null && m.getFamilyCellMap().firstEntry().getValue() != null && m.getFamilyCellMap().firstEntry().getValue().get(0) != null) { //have to replace the column family with WALEdit.METAFAMILY to make sure //that IndexedKeyValues don't get replicated. The superclass KeyValue fields //like row, qualifier and value are placeholders to prevent NPEs // when using the KeyValue APIs. See PHOENIX-5188 / 5455 Cell mutationCell = m.getFamilyCellMap().firstEntry().getValue().get(0); CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); return builder.setFamily(WALEdit.METAFAMILY). setQualifier(mutationCell.getQualifierArray()). setRow(m.getRow()). setTimestamp(mutationCell.getTimestamp()). setValue(mutationCell.getValueArray()).setType(Cell.Type.Put).build(); } else { throw new IllegalArgumentException("Tried to create an IndexedKeyValue with a " + "Mutation with no Cells!"); } }
Example #16
Source File: HBCKMetaTableAccessor.java From hbase-operator-tools with Apache License 2.0 | 6 votes |
/** * Generates and returns a Put containing the region into for the catalog table */ public static Put makePutFromRegionInfo(RegionInfo region, long ts) throws IOException { Put put = new Put(region.getRegionName(), ts); //copied from MetaTableAccessor put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(HConstants.REGIONINFO_QUALIFIER) .setTimestamp(put.getTimestamp()) .setType(Cell.Type.Put) // Serialize the Default Replica HRI otherwise scan of hbase:meta // shows an info:regioninfo value with encoded name and region // name that differs from that of the hbase;meta row. .setValue(RegionInfo.toByteArray(RegionReplicaUtil.getRegionInfoForDefaultReplica(region))) .build()); return put; }
Example #17
Source File: TestIncrementsFromClientSide.java From hbase with Apache License 2.0 | 5 votes |
@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(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(ROW) .setFamily(FAMILY) .setQualifier(QUALIFIER) .setTimestamp(timestamp) .setType(KeyValue.Type.Put.getCode()) .setValue(Bytes.toBytes(100L)) .build()); 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()); }
Example #18
Source File: ThriftUtilities.java From hbase with Apache License 2.0 | 5 votes |
public static Result resultFromThrift(TResult in) { if (in == null) { return null; } if (!in.isSetColumnValues() || in.getColumnValues().isEmpty()){ return in.isStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT; } List<Cell> cells = new ArrayList<>(in.getColumnValues().size()); ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); for (TColumnValue columnValue : in.getColumnValues()) { cells.add(toCell(builder, in.getRow(), columnValue)); } return Result.create(cells, null, in.isStale(), in.isPartial()); }
Example #19
Source File: TestFlushLifeCycleTracker.java From hbase with Apache License 2.0 | 5 votes |
@Test public void test() throws IOException, InterruptedException { try (Table table = UTIL.getConnection().getTable(NAME)) { for (int i = 0; i < 100; i++) { byte[] row = Bytes.toBytes(i); table.put(new Put(row, true) .add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(row) .setFamily(CF) .setQualifier(QUALIFIER) .setTimestamp(HConstants.LATEST_TIMESTAMP) .setType(Type.Put) .setValue(Bytes.toBytes(i)) .build())); } } Tracker tracker = new Tracker(); TRACKER = tracker; region.requestFlush(tracker); tracker.await(); assertNull(tracker.reason); assertTrue(tracker.beforeExecutionCalled); assertTrue(tracker.afterExecutionCalled); // request flush on a region with empty memstore should still success tracker = new Tracker(); TRACKER = tracker; region.requestFlush(tracker); tracker.await(); assertNull(tracker.reason); assertTrue(tracker.beforeExecutionCalled); assertTrue(tracker.afterExecutionCalled); }
Example #20
Source File: TestTableReporter.java From hbase-operator-tools with Apache License 2.0 | 5 votes |
private List<Cell> makeCells(byte [] row, int columns, int versions) { List<Cell> cells = new ArrayList<Cell>(columns); for (int j = 0; j < columns; j++) { for (int k = versions; k > 0; k--) { Cell cell = CellBuilderFactory.create(CellBuilderType.DEEP_COPY). setRow(row).setFamily(CF). setQualifier(Bytes.toBytes(j)). setType(Cell.Type.Put). setTimestamp(k). setValue(row).build(); cells.add(cell); } } return cells; }
Example #21
Source File: TestFlushLifeCycleTracker.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testNotExecuted() throws IOException, InterruptedException { try (Table table = UTIL.getConnection().getTable(NAME)) { for (int i = 0; i < 100; i++) { byte[] row = Bytes.toBytes(i); table.put(new Put(row, true) .add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(row) .setFamily(CF) .setQualifier(QUALIFIER) .setTimestamp(HConstants.LATEST_TIMESTAMP) .setType(Type.Put) .setValue(Bytes.toBytes(i)) .build())); } } // here we may have overlap when calling the CP hooks so we do not assert on TRACKER Tracker tracker1 = new Tracker(); ARRIVE = new CountDownLatch(1); BLOCK = new CountDownLatch(1); region.requestFlush(tracker1); ARRIVE.await(); Tracker tracker2 = new Tracker(); region.requestFlush(tracker2); tracker2.await(); assertNotNull(tracker2.reason); assertFalse(tracker2.beforeExecutionCalled); assertFalse(tracker2.afterExecutionCalled); BLOCK.countDown(); tracker1.await(); assertNull(tracker1.reason); assertTrue(tracker1.beforeExecutionCalled); assertTrue(tracker1.afterExecutionCalled); }
Example #22
Source File: PhoenixKeyValueUtil.java From phoenix with Apache License 2.0 | 5 votes |
public static Cell newKeyValue(byte[] key, int keyOffset, int keyLength, byte[] cf, int cfOffset, int cfLength, byte[] cq, int cqOffset, int cqLength, long ts, byte[] value, int valueOffset, int valueLength,Type type) { return CellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(key, keyOffset, keyLength).setFamily(cf, cfOffset, cfLength) .setQualifier(cq, cqOffset, cqLength).setTimestamp(ts) .setValue(value, valueOffset, valueLength).setType(type).build(); }
Example #23
Source File: TestHRegionReplayEvents.java From hbase with Apache License 2.0 | 5 votes |
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 HFileContextBuilder().build()); HFile.Writer writer = hFileFactory.create(); try { writer.append(new KeyValue(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(valueBytes) .setFamily(family) .setQualifier(valueBytes) .setTimestamp(0L) .setType(KeyValue.Type.Put.getCode()) .setValue(valueBytes) .build())); } finally { writer.close(); } } finally { out.close(); } return testFile.toString(); }
Example #24
Source File: TestBulkLoadReplication.java From hbase with Apache License 2.0 | 5 votes |
private String createHFileForFamilies(byte[] row, byte[] value, Configuration clusterConfig) throws IOException { CellBuilder cellBuilder = CellBuilderFactory.create(CellBuilderType.DEEP_COPY); cellBuilder.setRow(row) .setFamily(TestReplicationBase.famName) .setQualifier(Bytes.toBytes("1")) .setValue(value) .setType(Cell.Type.Put); HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(clusterConfig); // 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 HFileContextBuilder().build()); HFile.Writer writer = hFileFactory.create(); try { writer.append(new KeyValue(cellBuilder.build())); } finally { writer.close(); } } finally { out.close(); } return hFileLocation.getAbsoluteFile().getAbsolutePath(); }
Example #25
Source File: TestHFile.java From hbase with Apache License 2.0 | 5 votes |
private Cell getCell(byte[] row, byte[] family, byte[] qualifier) { return ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(row) .setFamily(family) .setQualifier(qualifier) .setTimestamp(HConstants.LATEST_TIMESTAMP) .setType(KeyValue.Type.Maximum.getCode()) .setValue(HConstants.EMPTY_BYTE_ARRAY) .build(); }
Example #26
Source File: ProtobufUtil.java From hbase with Apache License 2.0 | 5 votes |
/** * Convert a protocol buffer Result to a client Result * * @param proto the protocol buffer Result to convert * @param scanner Optional cell scanner. * @return the converted client Result * @throws IOException */ public static Result toResult(final ClientProtos.Result proto, final CellScanner scanner) throws IOException { List<CellProtos.Cell> values = proto.getCellList(); if (proto.hasExists()) { if ((values != null && !values.isEmpty()) || (proto.hasAssociatedCellCount() && proto.getAssociatedCellCount() > 0)) { throw new IllegalArgumentException("bad proto: exists with cells is no allowed " + proto); } if (proto.getStale()) { return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE_STALE :EMPTY_RESULT_EXISTS_FALSE_STALE; } return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE : EMPTY_RESULT_EXISTS_FALSE; } // TODO: Unit test that has some Cells in scanner and some in the proto. List<Cell> cells = null; if (proto.hasAssociatedCellCount()) { int count = proto.getAssociatedCellCount(); cells = new ArrayList<>(count + values.size()); for (int i = 0; i < count; i++) { if (!scanner.advance()) throw new IOException("Failed get " + i + " of " + count); cells.add(scanner.current()); } } if (!values.isEmpty()){ if (cells == null) cells = new ArrayList<>(values.size()); ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); for (CellProtos.Cell c: values) { cells.add(toCell(builder, c)); } } return (cells == null || cells.isEmpty()) ? (proto.getStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT) : Result.create(cells, null, proto.getStale()); }
Example #27
Source File: CheckAndMutate.java From hbase with Apache License 2.0 | 5 votes |
@Override public CellBuilder getCellBuilder(CellBuilderType cellBuilderType) { if (action instanceof Mutation) { return ((Mutation) action).getCellBuilder(); } throw new UnsupportedOperationException(); }
Example #28
Source File: MultiThreadedClientExample.java From hbase with Apache License 2.0 | 5 votes |
@Override public Boolean call() throws Exception { // Table implements Closable so we use the try with resource structure here. // https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html try (Table t = connection.getTable(tableName)) { byte[] value = Bytes.toBytes(Double.toString(ThreadLocalRandom.current().nextDouble())); int rows = 30; // Array to put the batch ArrayList<Put> puts = new ArrayList<>(rows); for (int i = 0; i < 30; i++) { byte[] rk = Bytes.toBytes(ThreadLocalRandom.current().nextLong()); Put p = new Put(rk); p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(rk) .setFamily(FAMILY) .setQualifier(QUAL) .setTimestamp(p.getTimestamp()) .setType(Cell.Type.Put) .setValue(value) .build()); puts.add(p); } // now that we've assembled the batch it's time to push it to hbase. t.put(puts); } return true; }
Example #29
Source File: ValueRewritingObserver.java From hbase with Apache License 2.0 | 5 votes |
@Override public void start( @SuppressWarnings("rawtypes") CoprocessorEnvironment env) throws IOException { RegionCoprocessorEnvironment renv = (RegionCoprocessorEnvironment) env; sourceValue = Bytes.toBytes(renv.getConfiguration().get(ORIGINAL_VALUE_KEY)); replacedValue = Bytes.toBytes(renv.getConfiguration().get(REPLACED_VALUE_KEY)); comparator = new Bytes.ByteArrayComparator(); cellBuilder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); }
Example #30
Source File: HBCKMetaTableAccessor.java From hbase-operator-tools with Apache License 2.0 | 5 votes |
public static Put addLocation(Put p, ServerName sn, long openSeqNum, int replicaId) throws IOException { CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); return p.add(builder.clear() .setRow(p.getRow()) .setFamily(CATALOG_FAMILY) .setQualifier(getServerColumn(replicaId)) .setTimestamp(p.getTimestamp()) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(sn.getAddress().toString())) .build()) .add(builder.clear() .setRow(p.getRow()) .setFamily(CATALOG_FAMILY) .setQualifier(getStartCodeColumn(replicaId)) .setTimestamp(p.getTimestamp()) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(sn.getStartcode())) .build()) .add(builder.clear() .setRow(p.getRow()) .setFamily(CATALOG_FAMILY) .setQualifier(getSeqNumColumn(replicaId)) .setTimestamp(p.getTimestamp()) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(openSeqNum)) .build()); }