/** * @param columnPrefixBytes The byte representation for the column prefix. * Should not contain {@link Separator#QUALIFIERS}. * @param qualifier the byte representation for the remainder of the column. * @return fully sanitized column qualifier that is a combination of prefix * and qualifier. If prefix is null, the result is simply the encoded * qualifier without any separator. */ public static byte[] getColumnQualifier(byte[] columnPrefixBytes, byte[] qualifier) { if (columnPrefixBytes == null) { return qualifier; } byte[] columnQualifier = Separator.QUALIFIERS.join(columnPrefixBytes, qualifier); return columnQualifier; }
/** * @param columnPrefixBytes The byte representation for the column prefix. * Should not contain {@link Separator#QUALIFIERS}. * @param qualifier for the remainder of the column. * @return fully sanitized column qualifier that is a combination of prefix * and qualifier. If prefix is null, the result is simply the encoded * qualifier without any separator. */ public static byte[] getColumnQualifier(byte[] columnPrefixBytes, long qualifier) { if (columnPrefixBytes == null) { return Bytes.toBytes(qualifier); } // Convert qualifier to lower case, strip of separators and tag on column // prefix. byte[] columnQualifier = Separator.QUALIFIERS.join(columnPrefixBytes, Bytes.toBytes(qualifier)); return columnQualifier; }
/** * @param columnPrefixBytes The byte representation for the column prefix. * Should not contain {@link Separator#QUALIFIERS}. * @param qualifier for the remainder of the column. * {@link Separator#QUALIFIERS} is permissible in the qualifier * as it is joined only with the column prefix bytes. * @return fully sanitized column qualifier that is a combination of prefix * and qualifier. If prefix is null, the result is simply the encoded * qualifier without any separator. */ public static byte[] getColumnQualifier(byte[] columnPrefixBytes, String qualifier) { // We don't want column names to have spaces / tabs. byte[] encodedQualifier = Separator.encode(qualifier, Separator.SPACE, Separator.TAB); if (columnPrefixBytes == null) { return encodedQualifier; } // Convert qualifier to lower case, strip of separators and tag on column // prefix. byte[] columnQualifier = Separator.QUALIFIERS.join(columnPrefixBytes, encodedQualifier); return columnQualifier; }
/** * Gets the possibly next row key prefix given current prefix and type. * * @param currRowKeyPrefix The current prefix that contains user, cluster, * flow, run, and application id. * @param entityType Current entity type. * @return A new prefix for the possibly immediately next row key. */ private static byte[] getNextRowKey(byte[] currRowKeyPrefix, String entityType) { if (currRowKeyPrefix == null || entityType == null) { return null; } byte[] entityTypeEncoded = Separator.QUALIFIERS.join( Separator.encode(entityType, Separator.SPACE, Separator.TAB, Separator.QUALIFIERS), Separator.EMPTY_BYTES); byte[] currRowKey = new byte[currRowKeyPrefix.length + entityTypeEncoded.length]; System.arraycopy(currRowKeyPrefix, 0, currRowKey, 0, currRowKeyPrefix.length); System.arraycopy(entityTypeEncoded, 0, currRowKey, currRowKeyPrefix.length, entityTypeEncoded.length); return HBaseTimelineStorageUtils.calculateTheClosestNextRowKeyForPrefix( currRowKey); }
@Override public byte[] encode(EventColumnName key) { byte[] first = Separator.encode(key.getId(), Separator.SPACE, Separator.TAB, Separator.VALUES); if (key.getTimestamp() == null) { return Separator.VALUES.join(first, Separator.EMPTY_BYTES); } byte[] second = Bytes.toBytes( LongConverter.invertLong(key.getTimestamp())); if (key.getInfoKey() == null) { return Separator.VALUES.join(first, second, Separator.EMPTY_BYTES); } return Separator.VALUES.join(first, second, Separator.encode( key.getInfoKey(), Separator.SPACE, Separator.TAB, Separator.VALUES)); }
@Override public byte[] encode(FlowRunRowKey rowKey) { byte[] first = Separator.QUALIFIERS.join(Separator.encode(rowKey.getClusterId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS), Separator .encode(rowKey.getUserId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS), Separator.encode(rowKey.getFlowName(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS)); if (rowKey.getFlowRunId() == null) { return Separator.QUALIFIERS.join(first, Separator.EMPTY_BYTES); } else { // Note that flowRunId is a long, so we can't encode them all at the // same // time. byte[] second = Bytes.toBytes(LongConverter.invertLong(rowKey.getFlowRunId())); return Separator.QUALIFIERS.join(first, second); } }
@Override public byte[] encode(DomainRowKey rowKey) { if (rowKey == null) { return Separator.EMPTY_BYTES; } byte[] cluster = Separator.encode(rowKey.getClusterId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] domainIdBytes = Separator.encode(rowKey.getDomainId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); return Separator.QUALIFIERS.join(cluster, domainIdBytes); }
@Override public byte[] encode(ApplicationRowKey rowKey) { byte[] cluster = Separator.encode(rowKey.getClusterId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] user = Separator.encode(rowKey.getUserId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] flow = Separator.encode(rowKey.getFlowName(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] first = Separator.QUALIFIERS.join(cluster, user, flow); // Note that flowRunId is a long, so we can't encode them all at the same // time. if (rowKey.getFlowRunId() == null) { return Separator.QUALIFIERS.join(first, Separator.EMPTY_BYTES); } byte[] second = Bytes.toBytes(LongConverter.invertLong( rowKey.getFlowRunId())); if (rowKey.getAppId() == null || rowKey.getAppId().isEmpty()) { return Separator.QUALIFIERS.join(first, second, Separator.EMPTY_BYTES); } byte[] third = appIDKeyConverter.encode(rowKey.getAppId()); return Separator.QUALIFIERS.join(first, second, third); }
@Override public byte[] encode(SubApplicationRowKey rowKey) { byte[] subAppUser = Separator.encode(rowKey.getSubAppUserId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] cluster = Separator.encode(rowKey.getClusterId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] first = Separator.QUALIFIERS.join(subAppUser, cluster); if (rowKey.getEntityType() == null) { return first; } byte[] entityType = Separator.encode(rowKey.getEntityType(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); if (rowKey.getEntityIdPrefix() == null) { return Separator.QUALIFIERS.join(first, entityType, Separator.EMPTY_BYTES); } byte[] entityIdPrefix = Bytes.toBytes(rowKey.getEntityIdPrefix()); if (rowKey.getEntityId() == null) { return Separator.QUALIFIERS.join(first, entityType, entityIdPrefix, Separator.EMPTY_BYTES); } byte[] entityId = Separator.encode(rowKey.getEntityId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] userId = Separator.encode(rowKey.getUserId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] second = Separator.QUALIFIERS.join(entityType, entityIdPrefix, entityId, userId); return Separator.QUALIFIERS.join(first, second); }
Separator.encode(rowKey.getFlowName(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS); byte[] first = Separator.QUALIFIERS.join(user, cluster, flow); byte[] third = appIDKeyConverter.encode(rowKey.getAppId()); if (rowKey.getEntityType() == null) { return Separator.QUALIFIERS.join(first, second, third, Separator.EMPTY_BYTES); return Separator.QUALIFIERS.join(first, second, third, entityType, Separator.EMPTY_BYTES); return Separator.QUALIFIERS.join(first, second, third, entityType, entityIdPrefix, Separator.EMPTY_BYTES); Separator.QUALIFIERS.join(entityType, entityIdPrefix, entityId); return Separator.QUALIFIERS.join(first, second, third, fourth);
@Override public byte[] encode(FlowActivityRowKey rowKey) { if (rowKey.getDayTimestamp() == null) { return Separator.QUALIFIERS.join(Separator.encode( rowKey.getClusterId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS), Separator.EMPTY_BYTES); } if (rowKey.getUserId() == null) { return Separator.QUALIFIERS.join(Separator.encode( rowKey.getClusterId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS), Bytes.toBytes(LongConverter .invertLong(rowKey.getDayTimestamp())), Separator.EMPTY_BYTES); } return Separator.QUALIFIERS.join(Separator.encode(rowKey.getClusterId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS), Bytes .toBytes(LongConverter.invertLong(rowKey.getDayTimestamp())), Separator.encode(rowKey.getUserId(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS), Separator.encode(rowKey.getFlowName(), Separator.SPACE, Separator.TAB, Separator.QUALIFIERS)); }