/** {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public <T> T getComponentByIndex(int idx) { Preconditions.checkState(!mRowKeyFormat.getSalt().getSuppressKeyMaterialization(), "Cannot retrieve components as materialization is suppressed"); Preconditions.checkArgument(idx >= 0 && idx < mComponentValues.size()); return (T) mComponentValues.get(idx); }
/** * Get the hash size for a given row key format. * * @param rowKeyFormat Format of row keys of type RowKeyFormat or RowKeyFormat2. * @return The size of the hash prefix. */ public static int getHashSize(Object rowKeyFormat) { if (rowKeyFormat instanceof RowKeyFormat) { return ((RowKeyFormat) rowKeyFormat).getHashSize(); } else if (rowKeyFormat instanceof RowKeyFormat2) { RowKeyFormat2 format2 = (RowKeyFormat2) rowKeyFormat; if (null == format2.getSalt()) { throw new RuntimeException("This RowKeyFormat2 instance does not specify salt/hashing."); } else { return format2.getSalt().getHashSize(); } } else { throw new RuntimeException("Unsupported Row Key Format"); } } }
format.getSalt().getHashSize()); baos.write(hashed, 0, hashed.length); if (format.getSalt().getSuppressKeyMaterialization()) { return baos.toByteArray(); } else {
int pos = format.getSalt().getHashSize(); if (format.getSalt().getSuppressKeyMaterialization()) { if (pos < hbaseRowKey.length) { throw new EntityIdException("Extra bytes in key after hash when materialization is"
/** {@inheritDoc} */ @Override public List<Object> getComponents() { Preconditions.checkState(!mRowKeyFormat.getSalt().getSuppressKeyMaterialization(), "Cannot retrieve components as materialization is suppressed"); return Collections.unmodifiableList(mComponentValues); }
if (format.getSalt().getSuppressKeyMaterialization() && format.getRangeScanStartIndex() != format.getComponents().size()) { throw new InvalidLayoutException("Range scans are not supported if " if (format.getSalt().getHashSize() <= 0 || format.getSalt().getHashSize() > Hasher.HASH_SIZE_BYTES) { throw new InvalidLayoutException("Valid hash sizes are between 1 and " + Hasher.HASH_SIZE_BYTES);
/** * Gets a table's row-key hash resolution (in number of bytes) * for use in evenly spacing HBase row keys. * * @param tableLayout the layout of the table * @return the table's hash resolution. */ public static int getRowKeyResolution(TableLayoutDesc tableLayout) { // Get hashSize from layout. int hashSize = 16; // No assumptions make about the RKF. if (RowKeyFormat.class.equals(tableLayout.getKeysFormat().getClass())) { hashSize = ((RowKeyFormat) tableLayout.getKeysFormat()).getHashSize(); } else if (RowKeyFormat2.class.equals(tableLayout.getKeysFormat().getClass())) { RowKeyFormat2 format = (RowKeyFormat2) tableLayout.getKeysFormat(); if (null == format.getSalt()) { throw new IllegalArgumentException( "This table layout defines an entityId format without hashing enabled."); } hashSize = ((RowKeyFormat2) tableLayout.getKeysFormat()).getSalt().getHashSize(); } return hashSize; }
/** {@inheritDoc} */ @Override public String toString() { if (!mRowKeyFormat.getSalt().getSuppressKeyMaterialization()) { return Objects.toStringHelper(FormattedEntityId.class) .add("components", Joiner.on(",").join(mComponentValues)) .add("hbase", Bytes.toStringBinary(mHBaseRowKey)) .toString(); } else { return Objects.toStringHelper(FormattedEntityId.class) .addValue("components are suppressed") .add("hbase", Bytes.toStringBinary(mHBaseRowKey)) .toString(); } }
if (mRowKeyFormat.getSalt().getHashSize() > 0) { mRowKeyFormat.getSalt().getHashSize()); for (byte hashedByte : hashed) { regex.append(String.format("\\x%02x", hashedByte & 0xFF)); } else { regex.append(".{").append(mRowKeyFormat.getSalt().getHashSize()).append("}");
/** * Creates a new FormattedEntityId. * @param format Format of the row key as specified in the layout file. * @param hbaseRowKey Byte array containing the hbase row key. * @param fijiRowKey An ordered list of row key components. */ private FormattedEntityId(RowKeyFormat2 format, byte[] hbaseRowKey, List<Object> fijiRowKey) { mRowKeyFormat = Preconditions.checkNotNull(format); Preconditions.checkArgument(format.getEncoding() == RowKeyEncoding.FORMATTED); Preconditions.checkNotNull(format.getSalt(), "Formatted entityIds may not specify a null 'salt' field in RowKeyFormat2."); mHBaseRowKey = hbaseRowKey; if (format.getSalt().getSuppressKeyMaterialization()) { mComponentValues = null; } else { mComponentValues = fijiRowKey; } }
if (mRowKeyFormat.getSalt().getSuppressKeyMaterialization()) { return String.format("hbase=hex:%s", ByteArrayFormatter.toHex(mHBaseRowKey));
"FormattedEntityIdRowFilter only works with formatted entity IDs"); if (null != rowKeyFormat.getSalt()) { Preconditions.checkArgument(!rowKeyFormat.getSalt().getSuppressKeyMaterialization(), "FormattedEntityIdRowFilter only works with materialized keys");
case FORMATTED: final HashSpec hashSpec = ((RowKeyFormat2) keysFormat).getSalt(); if (!hashSpec.getSuppressKeyMaterialization()) { return new FijiRestEntityId(entityId.getComponents().toArray(), false); } else {
case FORMATTED: final HashSpec hashSpec = ((RowKeyFormat2) keysFormat).getSalt(); if (hashSpec.getSuppressKeyMaterialization()) { return new JsonEntityIdParser( String.format("hbase=%s", Bytes.toStringBinary(entityId.getHBaseRowKey())),