/** * Set the new Bytes to the contents of the passed * <code>ibw</code>. * @param ibw the value to set this Bytes to. */ public Bytes(final Bytes ibw) { this(ibw.get(), ibw.getOffset(), ibw.getLength()); }
private <T> T getOrDefault(Bytes key, Function<byte[], T> function, T defaultValue) { Bytes value = values.get(key); if (value == null) { return defaultValue; } else { return function.apply(value.get()); } }
private <T> T getOrDefault(Bytes key, Function<String, T> function, T defaultValue) { Bytes value = values.get(key); if (value == null) { return defaultValue; } else { return function.apply(Bytes.toString(value.get(), value.getOffset(), value.getLength())); } }
@Override public String getValue(String key) { Bytes rval = values.get(new Bytes(Bytes.toBytes(key))); return rval == null ? null : Bytes.toString(rval.get(), rval.getOffset(), rval.getLength()); }
@Override public Iterator<Map.Entry<String,String>> iterator() { Map<String, String> ret = new HashMap<>(); for (Map.Entry<Bytes, Bytes> entry : map.entrySet()) { String key = Bytes.toString(entry.getKey().get()); String val = entry.getValue() == null ? null : Bytes.toString(entry.getValue().get()); ret.put(key, val); } return ret.entrySet().iterator(); }
/** * Getter for fetching an unmodifiable map. */ public Map<String, String> getConfiguration() { return delegatee.getValues().entrySet().stream() .collect(Collectors.toMap( e -> Bytes.toString(e.getKey().get(), e.getKey().getOffset(), e.getKey().getLength()), e -> Bytes.toString(e.getValue().get(), e.getValue().getOffset(), e.getValue().getLength()) )); }
@Override public byte[] getValue(byte[] key) { Bytes value = values.get(new Bytes(key)); return value == null ? null : value.get(); }
/** * Convert a protocol buffer Mutate to an Append * @param cellScanner * @param proto the protocol buffer Mutate to convert * @return the converted client Append * @throws IOException */ public static Append toAppend(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.APPEND : type.name(); Append append = toDelta((Bytes row) -> new Append(row.get(), row.getOffset(), row.getLength()), Append::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = toTimeRange(proto.getTimeRange()); append.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return append; }
/** * Return the list of attached co-processor represented by their name * className * * @return The list of co-processors classNames */ @Override public List<CoprocessorDescriptor> getCoprocessorDescriptors() { List<CoprocessorDescriptor> result = new ArrayList<>(); for (Map.Entry<Bytes, Bytes> e: getValues().entrySet()) { String key = Bytes.toString(e.getKey().get()).trim(); if (CP_HTD_ATTR_KEY_PATTERN.matcher(key).matches()) { toCoprocessorDescriptor(Bytes.toString(e.getValue().get()).trim()) .ifPresent(result::add); } } return result; }
/** * Convert a protocol buffer Mutate to an Append * @param cellScanner * @param proto the protocol buffer Mutate to convert * @return the converted client Append * @throws IOException */ public static Append toAppend(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.APPEND : type.name(); Append append = toDelta((Bytes row) -> new Append(row.get(), row.getOffset(), row.getLength()), Append::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = protoToTimeRange(proto.getTimeRange()); append.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return append; }
/** * Add coprocessor to values Map * @param specStr The Coprocessor specification all in in one String * @return Returns <code>this</code> */ private ModifyableTableDescriptor setCoprocessorToMap(final String specStr) { if (specStr == null) { return this; } // generate a coprocessor key int maxCoprocessorNumber = 0; Matcher keyMatcher; for (Map.Entry<Bytes, Bytes> e : this.values.entrySet()) { keyMatcher = CP_HTD_ATTR_KEY_PATTERN.matcher(Bytes.toString(e.getKey().get())); if (!keyMatcher.matches()) { continue; } maxCoprocessorNumber = Math.max(Integer.parseInt(keyMatcher.group(1)), maxCoprocessorNumber); } maxCoprocessorNumber++; String key = "coprocessor$" + Integer.toString(maxCoprocessorNumber); return setValue(new Bytes(Bytes.toBytes(key)), new Bytes(Bytes.toBytes(specStr))); }
/** * Convert a protocol buffer Mutate to an Increment * * @param proto the protocol buffer Mutate to convert * @return the converted client Increment * @throws IOException */ public static Increment toIncrement(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.INCREMENT : type.name(); Increment increment = toDelta((Bytes row) -> new Increment(row.get(), row.getOffset(), row.getLength()), Increment::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = protoToTimeRange(proto.getTimeRange()); increment.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return increment; }
/** * Remove all {@link Constraint Constraints} that have been added to the table * and turn off the constraint processing. * <p> * All {@link Configuration Configurations} and their associated * {@link Constraint} are removed. * * @param desc * {@link HTableDescriptor} to remove {@link Constraint Constraints} * from. */ public static void remove(HTableDescriptor desc) { // disable constraints disable(desc); // remove all the constraint settings List<Bytes> keys = new ArrayList<>(); // loop through all the key, values looking for constraints for (Map.Entry<Bytes, Bytes> e : desc .getValues().entrySet()) { String key = Bytes.toString((e.getKey().get())); String[] className = CONSTRAINT_HTD_ATTR_KEY_PATTERN.split(key); if (className.length == 2) { keys.add(e.getKey()); } } // now remove all the keys we found for (Bytes key : keys) { desc.remove(key); } }
/** * Convert a protocol buffer Mutate to an Increment * * @param proto the protocol buffer Mutate to convert * @return the converted client Increment * @throws IOException */ public static Increment toIncrement(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.INCREMENT : type.name(); Increment increment = toDelta((Bytes row) -> new Increment(row.get(), row.getOffset(), row.getLength()), Increment::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = toTimeRange(proto.getTimeRange()); increment.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return increment; }
/** * Constructor * @param htd the table descriptor */ public TableSchemaModel(HTableDescriptor htd) { setName(htd.getTableName().getNameAsString()); for (Map.Entry<Bytes, Bytes> e: htd.getValues().entrySet()) { addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } for (HColumnDescriptor hcd: htd.getFamilies()) { ColumnSchemaModel columnModel = new ColumnSchemaModel(); columnModel.setName(hcd.getNameAsString()); for (Map.Entry<Bytes, Bytes> e: hcd.getValues().entrySet()) { columnModel.addAttribute(Bytes.toString(e.getKey().get()), Bytes.toString(e.getValue().get())); } addColumnFamily(columnModel); } }
public static TTableDescriptor tableDescriptorFromHBase(TableDescriptor in) { TTableDescriptor out = new TTableDescriptor(); out.setTableName(tableNameFromHBase(in.getTableName())); Map<Bytes, Bytes> attributes = in.getValues(); for (Map.Entry<Bytes, Bytes> attribute : attributes.entrySet()) { out.putToAttributes(ByteBuffer.wrap(attribute.getKey().get()), ByteBuffer.wrap(attribute.getValue().get())); } for (ColumnFamilyDescriptor column : in.getColumnFamilies()) { out.addToColumns(columnFamilyDescriptorFromHBase(column)); } out.setDurability(durabilityFromHBase(in.getDurability())); return out; }
/** * Converts an ColumnFamilyDescriptor to ColumnFamilySchema * @param hcd the ColumnFamilySchema * @return Convert this instance to a the pb column family type */ public static ColumnFamilySchema toColumnFamilySchema(ColumnFamilyDescriptor hcd) { ColumnFamilySchema.Builder builder = ColumnFamilySchema.newBuilder(); builder.setName(UnsafeByteOperations.unsafeWrap(hcd.getName())); for (Map.Entry<Bytes, Bytes> e : hcd.getValues().entrySet()) { BytesBytesPair.Builder aBuilder = BytesBytesPair.newBuilder(); aBuilder.setFirst(UnsafeByteOperations.unsafeWrap(e.getKey().get())); aBuilder.setSecond(UnsafeByteOperations.unsafeWrap(e.getValue().get())); builder.addAttributes(aBuilder.build()); } for (Map.Entry<String, String> e : hcd.getConfiguration().entrySet()) { NameStringPair.Builder aBuilder = NameStringPair.newBuilder(); aBuilder.setName(e.getKey()); aBuilder.setValue(e.getValue()); builder.addConfiguration(aBuilder.build()); } return builder.build(); }
/** * Converts an TableDescriptor to TableSchema * @param htd the TableDescriptor * @return Convert the current {@link TableDescriptor} into a pb TableSchema instance. */ public static TableSchema toTableSchema(TableDescriptor htd) { TableSchema.Builder builder = TableSchema.newBuilder(); builder.setTableName(toProtoTableName(htd.getTableName())); for (Map.Entry<Bytes, Bytes> e : htd.getValues().entrySet()) { BytesBytesPair.Builder aBuilder = BytesBytesPair.newBuilder(); aBuilder.setFirst(UnsafeByteOperations.unsafeWrap(e.getKey().get())); aBuilder.setSecond(UnsafeByteOperations.unsafeWrap(e.getValue().get())); builder.addAttributes(aBuilder.build()); } for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) { builder.addColumnFamilies(toColumnFamilySchema(hcd)); } return builder.build(); }
public static TColumnFamilyDescriptor columnFamilyDescriptorFromHBase( ColumnFamilyDescriptor in) { TColumnFamilyDescriptor out = new TColumnFamilyDescriptor(); out.setName(in.getName()); for (Map.Entry<Bytes, Bytes> attribute : in.getValues().entrySet()) { out.putToAttributes(ByteBuffer.wrap(attribute.getKey().get()), ByteBuffer.wrap(attribute.getValue().get())); } for (Map.Entry<String, String> conf : in.getConfiguration().entrySet()) { out.putToConfiguration(conf.getKey(), conf.getValue()); } out.setBlockSize(in.getBlocksize()); out.setBloomnFilterType(bloomFilterFromHBase(in.getBloomFilterType())); out.setCompressionType(compressionAlgorithmFromHBase(in.getCompressionType())); out.setDfsReplication(in.getDFSReplication()); out.setDataBlockEncoding(dataBlockEncodingFromHBase(in.getDataBlockEncoding())); out.setKeepDeletedCells(keepDeletedCellsFromHBase(in.getKeepDeletedCells())); out.setMaxVersions(in.getMaxVersions()); out.setMinVersions(in.getMinVersions()); out.setScope(in.getScope()); out.setTimeToLive(in.getTimeToLive()); out.setBlockCacheEnabled(in.isBlockCacheEnabled()); out.setCacheBloomsOnWrite(in.isCacheBloomsOnWrite()); out.setCacheDataOnWrite(in.isCacheDataOnWrite()); out.setCacheIndexesOnWrite(in.isCacheIndexesOnWrite()); out.setCompressTags(in.isCompressTags()); out.setEvictBlocksOnClose(in.isEvictBlocksOnClose()); out.setInMemory(in.isInMemory()); return out; }