/** {@inheritDoc} */ @Override public Map<String, String> getAllColumnAnnotations( final FijiColumnName column ) throws IOException { requireState(State.OPEN, "get annotation"); final Map<String, String> collectedAnnotations = Maps.newHashMap(); for (String metaTableKey : keySet()) { if (isKCAColumnMetaTableKey(metaTableKey) && Objects.equal(column, columnFromMetaTableKey(metaTableKey))) { collectedAnnotations.put(keyFromMetaTableKey(metaTableKey), getKV(metaTableKey)); } } return collectedAnnotations; }
/** {@inheritDoc} */ @Override public void setColumnAnnotation( final FijiColumnName column, final String key, final String value ) throws IOException { requireState(State.OPEN, "set annotation"); validateAnnotationKey(key); setKV(getMetaTableKey(mTable, column, key), value); }
/** {@inheritDoc} */ @Override public Map<String, String> getAllTableAnnotations() throws IOException { requireState(State.OPEN, "get annotation"); final Map<String, String> collectedAnnotations = Maps.newHashMap(); for (String metaTableKey : keySet()) { if (isKCATableMetaTableKey(metaTableKey)) { collectedAnnotations.put(keyFromMetaTableKey(metaTableKey), getKV(metaTableKey)); } } return collectedAnnotations; }
/** {@inheritDoc} */ @Override public String getColumnAnnotation( final FijiColumnName column, final String exactKey ) throws IOException { requireState(State.OPEN, "get annotation"); return getKV(getMetaTableKey(mTable, column, exactKey)); }
/** {@inheritDoc} */ @Override public void removeTableAnnotation( final String exactKey ) throws IOException { requireState(State.OPEN, "remove annotation"); removeKV(getMetaTableKey(exactKey)); }
/** {@inheritDoc} */ @Override public Set<String> removeAllColumnAnnotations( final FijiColumnName column ) throws IOException { requireState(State.OPEN, "remove annotation"); final Set<String> removedAnnotationKeys = Sets.newHashSet(); for (String metaTableKey : keySet()) { if (isKCAColumnMetaTableKey(metaTableKey) && Objects.equal(column, columnFromMetaTableKey(metaTableKey))) { removedAnnotationKeys.add(keyFromMetaTableKey(metaTableKey)); removeKV(metaTableKey); } } return removedAnnotationKeys; }
/** {@inheritDoc} */ @Override public Set<String> removeAllTableAnnotations() throws IOException { requireState(State.OPEN, "remove annotation"); final Set<String> removedAnnotationKeys = Sets.newHashSet(); for (String metaTableKey : keySet()) { if (isKCATableMetaTableKey(metaTableKey)) { removedAnnotationKeys.add(keyFromMetaTableKey(metaTableKey)); removeKV(metaTableKey); } } return removedAnnotationKeys; }
/** * 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)); }
/** * Get the FijiColumnName from the given meta table key. If the key component cannot be translated * to a FijiColumnName, the meta table key will be removed and this method will return null. * * @param metaTableKey key from which to exact the column name. * @return FijiColumnName stored in the given meta table key or null if the column name cannot be * translated. * @throws IOException in case of an error removing a defunct key. */ private FijiColumnName columnFromMetaTableKey( final String metaTableKey ) throws IOException { try { return columnFromMetaTableKey(mTable, metaTableKey); } catch (NoSuchColumnException e) { removeKV(metaTableKey); return null; } }
/** * 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); }
/** {@inheritDoc} */ @Override public FijiTableAnnotator openTableAnnotator() throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot get the TableAnnotator for a table in state: %s.", state); return new HBaseFijiTableAnnotator(this); }
/** {@inheritDoc} */ @Override public Map<FijiColumnName, Set<String>> removeAllColumnAnnotations() throws IOException { requireState(State.OPEN, "remove annotation"); final Map<FijiColumnName, Set<String>> removedAnnotationKeys = Maps.newHashMap(); for (String metaTableKey : keySet()) { if (isKCAColumnMetaTableKey(metaTableKey)) { final FijiColumnName column = columnFromMetaTableKey(metaTableKey); if (null != column) { final Set<String> removedKeysInColumn = removedAnnotationKeys.get(column); if (null != removedKeysInColumn) { removedKeysInColumn.add(keyFromMetaTableKey(metaTableKey)); } else { removedAnnotationKeys.put(column, Sets.newHashSet(keyFromMetaTableKey(metaTableKey))); } removeKV(metaTableKey); } } } return removedAnnotationKeys; }
/** {@inheritDoc} */ @Override public Set<String> removeTableAnnotationsContaining( final String substring ) throws IOException { requireState(State.OPEN, "remove annotation"); final Set<String> removedAnnotationKeys = Sets.newHashSet(); for (String metaTableKey : keySet()) { if (isKCATableMetaTableKey(metaTableKey)) { final String annotationKey = keyFromMetaTableKey(metaTableKey); if (annotationKey.contains(substring)) { removedAnnotationKeys.add(annotationKey); removeKV(metaTableKey); } } } return removedAnnotationKeys; }
/** {@inheritDoc} */ @Override public String getTableAnnotation( final String exactKey ) throws IOException { requireState(State.OPEN, "get annotation"); return getKV(getMetaTableKey(exactKey)); }
/** {@inheritDoc} */ @Override public void removeColumnAnnotation( final FijiColumnName column, final String exactKey ) throws IOException { requireState(State.OPEN, "remove annotation"); removeKV(getMetaTableKey(mTable, column, exactKey)); }
/** * 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 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); }
/** {@inheritDoc} */ @Override public Map<String, String> getColumnAnnotationsContaining( final FijiColumnName column, final String substring ) throws IOException { requireState(State.OPEN, "get annotation"); final Map<String, String> collectedAnnotations = Maps.newHashMap(); for (String metaTableKey : keySet()) { if (isKCAColumnMetaTableKey(metaTableKey) && Objects.equal(column, columnFromMetaTableKey(metaTableKey))) { final String annotationKey = keyFromMetaTableKey(metaTableKey); if (annotationKey.contains(substring)) { collectedAnnotations.put(annotationKey, getKV(metaTableKey)); } } } return collectedAnnotations; }
/** {@inheritDoc} */ @Override public Set<String> removeColumnAnnotationsStartingWith( final FijiColumnName column, final String prefix ) throws IOException { requireState(State.OPEN, "remove annotation"); final Set<String> removedAnnotationKeys = Sets.newHashSet(); for (String metaTableKey : keySet()) { if (isKCAColumnMetaTableKey(metaTableKey) && Objects.equal(column, columnFromMetaTableKey(metaTableKey))) { final String annotationKey = keyFromMetaTableKey(metaTableKey); if (annotationKey.startsWith(prefix)) { removedAnnotationKeys.add(annotationKey); removeKV(metaTableKey); } } } return removedAnnotationKeys; }
/** {@inheritDoc} */ @Override public Map<String, String> getTableAnnotationsMatching( final String pattern ) throws IOException { requireState(State.OPEN, "get annotation"); final Map<String, String> collectedAnnotations = Maps.newHashMap(); for (String metaTableKey : keySet()) { if (isKCATableMetaTableKey(metaTableKey)) { final String annotationKey = keyFromMetaTableKey(metaTableKey); if (keyFromMetaTableKey(metaTableKey).matches(pattern)) { collectedAnnotations.put(annotationKey, getKV(metaTableKey)); } } } return collectedAnnotations; }