/** * Validate that a given key is a valid FijiTableAnnotator annotation key. * * @param key the annotation key to check for validity. * @throws IllegalArgumentException if the key is invalid. */ private static void validateAnnotationKey( final String key ) { Preconditions.checkArgument(isValidAnnotationKey(key), "Annotation keys much match pattern: %s, found: %s", ALLOWED_ANNOTATION_KEY_PATTERN, key); }
/** * Get the meta table key for the table served by this column annotator and the given annotation * key. This method is package private for testing. * * @param key annotation key for which to get the meta table key. * @return the meta table key for the given annotation key. */ static String getMetaTableKey( final String key ) { Preconditions.checkArgument(isValidAnnotationKey(key), "Annotation key: %s does not conform to " + "required pattern: %s", key, ALLOWED_ANNOTATION_KEY_PATTERN); return String.format("%s.%s", METATABLE_KEY_PREFIX, key); }
/** * Check if a metaTableKey is a FijiTableAnnotator meta table key for a table annotation. * * @param metaTableKey the meta table key to check. * @return whether the given meta table key is a FijiTableAnnotator meta table key for a table * annotation. */ private static boolean isKCATableMetaTableKey( final String metaTableKey ) { final int lastPeriodIndex = metaTableKey.lastIndexOf('.'); return metaTableKey.startsWith(METATABLE_KEY_PREFIX) // The last period should be just after the prefix. && lastPeriodIndex == (METATABLE_KEY_PREFIX.length()) && isValidAnnotationKey(keyFromMetaTableKey(metaTableKey)); }
/** * Check if a metaTableKey is a FijiTableAnnotator meta table key for a column annotation. * * @param metaTableKey the meta table key to check. * @return whether the given meta table key is a FijiTableAnnotator meta table key for a column * annotation. */ private static boolean isKCAColumnMetaTableKey( final String metaTableKey ) { final int firstColonIndex = metaTableKey.indexOf(':'); final int lastPeriodIndex = metaTableKey.lastIndexOf('.'); return metaTableKey.startsWith(METATABLE_KEY_PREFIX) // a colon between the prefix and the last period indicates a qualified column. && ((firstColonIndex > METATABLE_KEY_PREFIX.length() && lastPeriodIndex > firstColonIndex) // nothing between the prefix and the last period indicates a table key. || firstColonIndex == -1 && lastPeriodIndex != (METATABLE_KEY_PREFIX.length())) // +1 to exclude the '.'. && isValidAnnotationKey(keyFromMetaTableKey(metaTableKey)); }
/** * Get the meta table key for the given column name and annotation key. This method is package * private for testing. * * @param table HBaseFijiTable in which the specified column lives. This will be used for * column name translation. * @param columnName the name of the column from which to get the meta table key. * @param key the annotation key from which to get the meta table key. * @return the meta table key for the given column name and annotation key. * @throws NoSuchColumnException in case the column does not exist in the table. */ static String getMetaTableKey( final HBaseFijiTable table, final FijiColumnName columnName, final String key ) throws NoSuchColumnException { final HBaseColumnNameTranslator translator = table.getColumnNameTranslator(); Preconditions.checkArgument(isValidAnnotationKey(key), "Annotation key: %s does not conform to " + "required pattern: %s", key, ALLOWED_ANNOTATION_KEY_PATTERN); return String.format("%s%s.%s", METATABLE_KEY_PREFIX, translator.toHBaseColumnName(columnName), key); }