/** * Return the ordered list of columns in the partition key for the table layout. * * @param layout to return partition key columns for. * @return the primary key columns for the layout. */ public static List<String> getPartitionKeyColumns(FijiTableLayout layout) { RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat(); switch (keyFormat.getEncoding()) { case RAW: return Lists.newArrayList(RAW_KEY_COL); case FORMATTED: return transformToColumns( keyFormat.getComponents().subList(0, keyFormat.getRangeScanStartIndex())); default: throw new IllegalArgumentException( String.format("Unknown row key encoding %s.", keyFormat.getEncoding())); } }
Preconditions.checkArgument(rowKeyFormat.getEncoding().equals(RowKeyEncoding.FORMATTED), "FormattedEntityIdRowFilter only works with formatted entity IDs"); if (null != rowKeyFormat.getSalt()) { Preconditions.checkArgument(!rowKeyFormat.getSalt().getSuppressKeyMaterialization(), "FormattedEntityIdRowFilter only works with materialized keys"); Preconditions.checkArgument(components.length <= rowKeyFormat.getComponents().size(), "More components given (%s) than are in the row key format specification (%s)", components.length, rowKeyFormat.getComponents().size()); if (components.length < rowKeyFormat.getComponents().size()) { mComponents = new Object[rowKeyFormat.getComponents().size()]; for (int i = 0; i < components.length; i++) { mComponents[i] = components[i];
/** * 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 (format.getEncoding() != RowKeyEncoding.RAW && format.getEncoding() != RowKeyEncoding.FORMATTED) { throw new InvalidLayoutException("RowKeyFormat2 only supports RAW or FORMATTED encoding." + "Found " + format.getEncoding().name()); if (format.getEncoding() == RowKeyEncoding.RAW) { return; if (format.getComponents().size() <= 0) { throw new InvalidLayoutException("At least 1 component is required in row key format."); if (format.getSalt() == null) { if (format.getNullableStartIndex() <= 0 || format.getNullableStartIndex() > format.getComponents().size()) { throw new InvalidLayoutException("Invalid index for nullable component. The second component" + " onwards can be set to null."); if (format.getRangeScanStartIndex() <= 0 || format.getRangeScanStartIndex() > format.getComponents().size()) { throw new InvalidLayoutException("Invalid range scan index. Range scans are supported " + "starting with the second component."); if (format.getSalt().getSuppressKeyMaterialization() && format.getRangeScanStartIndex() != format.getComponents().size()) { throw new InvalidLayoutException("Range scans are not supported if " + "suppress_key_materialization is true. Please set range_scan_start_index " for (RowKeyComponent component: format.getComponents()) {
int hashUpto = format.getRangeScanStartIndex() - 1; ByteArrayOutputStream tohash = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); format.getSalt().getHashSize()); baos.write(hashed, 0, hashed.length); if (format.getSalt().getSuppressKeyMaterialization()) { return baos.toByteArray(); } else { for (pos = 0; pos < hbaseKey.size(); pos++) { baos.write(hbaseKey.get(pos), 0, hbaseKey.get(pos).length); if (format.getComponents().get(pos).getType() == ComponentType.STRING || format.getComponents().get(pos) == null) {
/** * Construct a new Formatted Entity ID factory. * * @param format The row key format required for creating the factory. */ private FormattedEntityIdFactory(RowKeyFormat2 format) { Preconditions.checkNotNull(format); Preconditions.checkArgument(format.getEncoding() == RowKeyEncoding.FORMATTED); mRowKeyFormat = format; }
RowKeyFormat2 format) { Preconditions.checkNotNull(format); Preconditions.checkNotNull(format.getSalt()); Preconditions.checkNotNull(fijiRowKey); if (fijiRowKey.size() > format.getComponents().size()) { throw new EntityIdException("Too many components in fiji Row Key"); if (fijiRowKey.size() < format.getComponents().size()) { int krk = fijiRowKey.size(); int fgc = format.getComponents().size(); if (LOG.isDebugEnabled()) { LOG.debug( if (fijiRowKey.size() < format.getNullableStartIndex()) { throw new EntityIdException("Too few components in fiji Row key"); if (format.getNullableStartIndex() <= i) { hasSeenNull = true; continue; throw new EntityIdException("Unexpected null component in fiji row key." + String.format("Expected at least %d non-null components", format.getNullableStartIndex())); if (null == type || type != format.getComponents().get(i).getType()) { if (type == ComponentType.INTEGER && format.getComponents().get(i).getType() == ComponentType.LONG) { fijiRowKey.set(i, ((Integer) fijiRowKey.get(i)).longValue());
/** * Get the names and types of Entity ID columns in the Cassandra table. * * @param layout The table layout. * @return The names and types of Entity ID columns. */ private static LinkedHashMap<String, String> getEntityIdColumnTypes( final FijiTableLayout layout ) { LinkedHashMap<String, String> columns = Maps.newLinkedHashMap(); RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat(); switch (keyFormat.getEncoding()) { case RAW: { columns.put(RAW_KEY_COL, BYTES_TYPE); break; } case FORMATTED: { for (RowKeyComponent component : keyFormat.getComponents()) { columns.put( translateEntityIDComponentNameToColumnName(component.getName()), getCQLType(component.getType())); } break; } default: throw new IllegalArgumentException( String.format("Unknown row key encoding %s.", keyFormat.getEncoding())); } return columns; }
components[i] = null; } else if (null != rowKeyFormat2 && ComponentType.LONG == rowKeyFormat2.getComponents().get(i).getType()) { components[i] = ((Number) component).longValue(); } else {
/** {@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); }
keyFormat.getRangeScanStartIndex() != keyFormat.getComponents().size();
try { root.put(ROW_KEY_FORMAT_NODE, ToJson.toAvroJsonString(mRowKeyFormat, mRowKeyFormat.getSchema())); final ArrayNode components = root.putArray(COMPONENTS_NODE); for (int i = 0; i < mComponents.length; i++) { components.add(components.nullNode()); } else { switch (mRowKeyFormat.getComponents().get(i).getType()) { case INTEGER: components.add((Integer)component); default: throw new IllegalStateException("Unknown component type: " + mRowKeyFormat.getComponents().get(i).getType());
if (null != mRowKeyFormat.getSalt()) { if (mRowKeyFormat.getSalt().getHashSize() > 0) { getNonNullPrefixComponents(mComponents, mRowKeyFormat.getRangeScanStartIndex()); if (prefixComponents.length == mRowKeyFormat.getRangeScanStartIndex()) { ByteArrayOutputStream tohash = new ByteArrayOutputStream(); for (Object component : prefixComponents) { mRowKeyFormat.getSalt().getHashSize()); for (byte hashedByte : hashed) { regex.append(String.format("\\x%02x", hashedByte & 0xFF)); } else { regex.append(".{").append(mRowKeyFormat.getSalt().getHashSize()).append("}"); for (int i = 0; i < mComponents.length; i++) { final Object component = mComponents[i]; switch (mRowKeyFormat.getComponents().get(i).getType()) { case INTEGER: if (null == component) { default: throw new IllegalStateException("Unknown component type: " + mRowKeyFormat.getComponents().get(i).getType());
/** * Creates a RawEntityIdFactory. * * @param format Row key format. */ private RawEntityIdFactory(RowKeyFormat2 format) { Preconditions.checkNotNull(format); Preconditions.checkArgument(format.getEncoding() == RowKeyEncoding.RAW); }
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" while (fijiRowElem < format.getComponents().size() && pos < hbaseRowKey.length) { switch (format.getComponents().get(fijiRowElem).getType()) { case STRING: if (fijiRowElem < format.getNullableStartIndex()) { throw new EntityIdException("Too few components decoded from hbase row key. Component " + "number " + fijiRowElem + " cannot be null"); for (; fijiRowElem < format.getComponents().size(); fijiRowElem++) { fijiRowKey.add(null);
components[i] = null; } else if (null != format && ComponentType.LONG == format.getComponents().get(i).getType()) { components[i] = ((Number) component).longValue(); } else {
/** {@inheritDoc} */ @Override public List<Object> getComponents() { Preconditions.checkState(!mRowKeyFormat.getSalt().getSuppressKeyMaterialization(), "Cannot retrieve components as materialization is suppressed"); return Collections.unmodifiableList(mComponentValues); }
/** * Get the ordered list of cluster columns originating from the entity ID. This is the set of * 'scannable' entity ID components. * * @param layout The layou of the table. * @return the cluster columns of the table from the entity ID. */ private static List<String> getEntityIdClusterColumns(FijiTableLayout layout) { RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat(); switch (keyFormat.getEncoding()) { case RAW: { return Lists.newArrayList(); } case FORMATTED: { int size = keyFormat.getComponents().size(); int start = keyFormat.getRangeScanStartIndex(); if (start == size) { return Lists.newArrayList(); } else { return transformToColumns( keyFormat .getComponents() .subList(keyFormat.getRangeScanStartIndex(), keyFormat.getComponents().size())); } } default: throw new IllegalArgumentException( String.format("Unknown row key encoding %s.", keyFormat.getEncoding())); } }
/** * Find the encoding of the row key given the format. * * @param rowKeyFormat Format of row keys of type RowKeyFormat or RowKeyFormat2. * @return The specific row key encoding, e.g. RAW, HASH, etc. */ public static RowKeyEncoding getEncoding(Object rowKeyFormat) { if (rowKeyFormat instanceof RowKeyFormat) { return ((RowKeyFormat) rowKeyFormat).getEncoding(); } else if (rowKeyFormat instanceof RowKeyFormat2) { return ((RowKeyFormat2) rowKeyFormat).getEncoding(); } else { throw new RuntimeException("Unsupported Row Key Format"); } }
public TokenRowKeyComponents apply(final Row row) { final List<RowKeyComponent> formatComponents = mKeyFormat.getComponents(); final Object[] components = new Object[formatComponents.size()];