org.apache.hadoop.hbase.CellBuilderFactory Java Examples
The following examples show how to use
org.apache.hadoop.hbase.CellBuilderFactory.
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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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()); }
Example #19
Source File: HBCKMetaTableAccessor.java From hbase-operator-tools with Apache License 2.0 | 5 votes |
private static void addRegionStateToPut(Put put, RegionState.State state) throws IOException { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(HConstants.STATE_QUALIFIER) .setTimestamp(put.getTimestamp()) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(state.name())) .build()); }
Example #20
Source File: TestHStore.java From hbase with Apache License 2.0 | 5 votes |
private Cell createCell(byte[] row, byte[] qualifier, long ts, long sequenceId, byte[] value) throws IOException { Cell c = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family) .setQualifier(qualifier).setTimestamp(ts).setType(Cell.Type.Put) .setValue(value).build(); PrivateCellUtil.setSequenceId(c, sequenceId); return c; }
Example #21
Source File: TestFsRegionsMetaRecoverer.java From hbase-operator-tools with Apache License 2.0 | 5 votes |
private Cell createCellForRegionInfo(RegionInfo info){ byte[] regionInfoValue = ProtobufUtil.prependPBMagic(ProtobufUtil.toRegionInfo(info) .toByteArray()); Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(info.getRegionName()) .setFamily(Bytes.toBytes("info")) .setQualifier(Bytes.toBytes("regioninfo")) .setType(Cell.Type.Put) .setValue(regionInfoValue) .build(); return cell; }
Example #22
Source File: TestFsRegionsMetaRecoverer.java From hbase-operator-tools with Apache License 2.0 | 5 votes |
private Cell createCellForTableState(TableName tableName){ Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(tableName.getName()) .setFamily(Bytes.toBytes("table")) .setQualifier(Bytes.toBytes("state")) .setType(Cell.Type.Put) .setValue(HBaseProtos.TableState.newBuilder() .setState(TableState.State.ENABLED.convert()).build().toByteArray()) .build(); return cell; }
Example #23
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 #24
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 #25
Source File: RowResource.java From hbase with Apache License 2.0 | 4 votes |
Response updateBinary(final byte[] message, final HttpHeaders headers, final boolean replace) { servlet.getMetrics().incrementRequests(1); if (servlet.isReadOnly()) { servlet.getMetrics().incrementFailedPutRequests(1); return Response.status(Response.Status.FORBIDDEN) .type(MIMETYPE_TEXT).entity("Forbidden" + CRLF) .build(); } Table table = null; try { byte[] row = rowspec.getRow(); byte[][] columns = rowspec.getColumns(); byte[] column = null; if (columns != null) { column = columns[0]; } long timestamp = HConstants.LATEST_TIMESTAMP; List<String> vals = headers.getRequestHeader("X-Row"); if (vals != null && !vals.isEmpty()) { row = Bytes.toBytes(vals.get(0)); } vals = headers.getRequestHeader("X-Column"); if (vals != null && !vals.isEmpty()) { column = Bytes.toBytes(vals.get(0)); } vals = headers.getRequestHeader("X-Timestamp"); if (vals != null && !vals.isEmpty()) { timestamp = Long.parseLong(vals.get(0)); } if (column == null) { servlet.getMetrics().incrementFailedPutRequests(1); return Response.status(Response.Status.BAD_REQUEST) .type(MIMETYPE_TEXT).entity("Bad request: Column found to be null." + CRLF) .build(); } Put put = new Put(row); byte parts[][] = CellUtil.parseColumn(column); if (parts.length != 2) { return Response.status(Response.Status.BAD_REQUEST) .type(MIMETYPE_TEXT).entity("Bad request" + CRLF) .build(); } put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(parts[0]) .setQualifier(parts[1]) .setTimestamp(timestamp) .setType(Type.Put) .setValue(message) .build()); table = servlet.getTable(tableResource.getName()); table.put(put); if (LOG.isTraceEnabled()) { LOG.trace("PUT " + put.toString()); } servlet.getMetrics().incrementSucessfulPutRequests(1); return Response.ok().build(); } catch (Exception e) { servlet.getMetrics().incrementFailedPutRequests(1); return processException(e); } finally { if (table != null) try { table.close(); } catch (IOException ioe) { LOG.debug("Exception received while closing the table", ioe); } } }
Example #26
Source File: PhoenixKeyValueUtil.java From phoenix with Apache License 2.0 | 4 votes |
public static Cell newKeyValue(byte[] key, int keyOffset, int keyLength, byte[] cf, byte[] cq, long ts, byte[] value, int valueOffset, int valueLength) { return CellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(key, keyOffset, keyLength).setFamily(cf).setQualifier(cq).setTimestamp(ts) .setType(Type.Put).setValue(value, valueOffset, valueLength).build(); }
Example #27
Source File: PhoenixKeyValueUtil.java From phoenix with Apache License 2.0 | 4 votes |
public static Cell newKeyValue(ImmutableBytesWritable key, byte[] cf, byte[] cq, long ts, byte[] value, int valueOffset, int valueLength) { return CellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(key.get(), key.getOffset(), key.getLength()).setFamily(cf).setQualifier(cq) .setTimestamp(ts).setType(Type.Put).setValue(value, valueOffset, valueLength) .build(); }
Example #28
Source File: PhoenixKeyValueUtil.java From phoenix with Apache License 2.0 | 4 votes |
public static Cell newKeyValue(byte[] key, byte[] cf, byte[] cq, long ts, byte[] value, int valueOffset, int valueLength) { return CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(key).setFamily(cf) .setQualifier(cq).setTimestamp(ts).setType(Type.Put) .setValue(value, valueOffset, valueLength).build(); }
Example #29
Source File: WriteHeavyIncrementObserver.java From hbase with Apache License 2.0 | 4 votes |
private Cell createCell(byte[] row, byte[] family, byte[] qualifier, long ts, long value) { return CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row) .setType(Cell.Type.Put).setFamily(family).setQualifier(qualifier) .setTimestamp(ts).setValue(Bytes.toBytes(value)).build(); }
Example #30
Source File: PermissionStorage.java From hbase with Apache License 2.0 | 4 votes |
/** * Stores a new user permission grant in the access control lists table. * @param conf the configuration * @param userPerm the details of the permission to be granted * @param t acl table instance. It is closed upon method return. * @throws IOException in the case of an error accessing the metadata table */ public static void addUserPermission(Configuration conf, UserPermission userPerm, Table t, boolean mergeExistingPermissions) throws IOException { Permission permission = userPerm.getPermission(); Permission.Action[] actions = permission.getActions(); byte[] rowKey = userPermissionRowKey(permission); Put p = new Put(rowKey); byte[] key = userPermissionKey(userPerm); if ((actions == null) || (actions.length == 0)) { String msg = "No actions associated with user '" + userPerm.getUser() + "'"; LOG.warn(msg); throw new IOException(msg); } Set<Permission.Action> actionSet = new TreeSet<Permission.Action>(); if(mergeExistingPermissions){ List<UserPermission> perms = getUserPermissions(conf, rowKey, null, null, null, false); UserPermission currentPerm = null; for (UserPermission perm : perms) { if (userPerm.equalsExceptActions(perm)) { currentPerm = perm; break; } } if (currentPerm != null && currentPerm.getPermission().getActions() != null){ actionSet.addAll(Arrays.asList(currentPerm.getPermission().getActions())); } } // merge current action with new action. actionSet.addAll(Arrays.asList(actions)); // serialize to byte array. byte[] value = new byte[actionSet.size()]; int index = 0; for (Permission.Action action : actionSet) { value[index++] = action.code(); } p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(p.getRow()) .setFamily(ACL_LIST_FAMILY) .setQualifier(key) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(value) .build()); if (LOG.isDebugEnabled()) { LOG.debug("Writing permission with rowKey " + Bytes.toString(rowKey) + " " + Bytes.toString(key) + ": " + Bytes.toStringBinary(value)); } try { t.put(p); } finally { t.close(); } }