/** {@inheritDoc} */ @Override public <T> Iterator<FijiCell<T>> iterator(final String family) { final FamilyLayout familyLayout = mLayout.getFamilyMap().get(family); Preconditions.checkArgument(familyLayout != null, "Column %s has no data request.", family); Preconditions.checkState(familyLayout.isMapType(), "iterator(String family) is only enabled on map type column families." + " The column family [%s], is a group type column family." + " Please use the iterator(String family, String qualifier) method.", family); return iterator(family, null); }
/** {@inheritDoc} */ @Override public <T> NavigableMap<String, T> getMostRecentValues(String family) throws IOException { Preconditions.checkState(mTableLayout.getFamilyMap().get(family).isMapType(), "getMostRecentValues(String family) is only enabled" + " on map type column families. The column family [%s], is a group type column family." + " Please use the getMostRecentValues(String family, String qualifier) method.", family); final NavigableMap<String, T> result = Maps.newTreeMap(); for (String qualifier : getQualifiers(family)) { final T value = getMostRecentValue(family, qualifier); result.put(qualifier, value); } return result; }
/** {@inheritDoc} */ @Override public <T> NavigableMap<String, NavigableMap<Long, FijiCell<T>>> getCells(String family) throws IOException { Preconditions.checkState(mTableLayout.getFamilyMap().get(family).isMapType(), "getCells(String family) is only enabled" + " on map type column families. The column family [%s], is a group type column family." + " Please use the getCells(String family, String qualifier) method.", family); final NavigableMap<String, NavigableMap<Long, FijiCell<T>>> result = Maps.newTreeMap(); for (String qualifier : getQualifiers(family)) { final NavigableMap<Long, FijiCell<T>> cells = getCells(family, qualifier); result.put(qualifier, cells); } return result; }
/** * Reports the raw specification record for the specified column. * * <p> Note: in most cases, you should use {@link #getCellSpec(FijiColumnName)}. </p> * * @param columnName Column to reports the raw specification record of. * @return the raw specification record for the specified column. * @throws NoSuchColumnException if the column does not exist. */ public CellSchema getCellSchema(FijiColumnName columnName) throws NoSuchColumnException { final FamilyLayout fLayout = mFamilyMap.get(columnName.getFamily()); if (fLayout == null) { throw new NoSuchColumnException(String.format( "Table '%s' has no family '%s'.", getName(), columnName.getFamily())); } if (fLayout.isMapType()) { return CellSchema.newBuilder(fLayout.getDesc().getMapSchema()).build(); } // Group-type family: Preconditions.checkArgument(columnName.isFullyQualified(), String.format("Cannot get CellFormat for entire group-type family: '%s'.", columnName)); final FamilyLayout.ColumnLayout cLayout = fLayout.getColumnMap().get(columnName.getQualifier()); if (cLayout == null) { throw new NoSuchColumnException(String.format( "Table '%s' has no column '%s'.", getName(), columnName)); } return CellSchema.newBuilder(cLayout.getDesc().getColumnSchema()).build(); }
final FijiColumnName column = FijiColumnName.create(family, null); validateColumnRequest(column); Preconditions.checkState(mLayout.getFamilyMap().get(family).isMapType(), "getMostRecentValues(String family) is only enabled on map type column families." + " The column family [%s], is a group type column family."
/** * Get a decoder function for a column. * * @param column to decode. * @param layout of table. * @param translator for table. * @param decoderProvider for table. * @param <T> type of values in the column. * @return a decode for the column. */ public static <T> Function<KeyValue, FijiCell<T>> getDecoderFunction( final FijiColumnName column, final FijiTableLayout layout, final HBaseColumnNameTranslator translator, final CellDecoderProvider decoderProvider ) { if (column.isFullyQualified()) { final FijiCellDecoder<T> decoder = decoderProvider.getDecoder(column); return new QualifiedColumnDecoder<T>(column, decoder); } final FamilyLayout family = layout.getFamilyMap().get(column.getFamily()); if (family.isMapType()) { return new MapFamilyDecoder<T>(translator, decoderProvider.<T>getDecoder(column)); } else { return new GroupFamilyDecoder<T>(translator, decoderProvider); } }
} else { assert family.isMapType(); final byte[] qualifierBytes = Bytes.toBytes(qualifierName); return new CassandraColumnName(familyBytes, qualifierBytes);
if (rawColumnNames.isEmpty()) { for (FamilyLayout family : layout.getFamilies()) { if (family.isMapType()) { familyMap.put(family, new ArrayList<String>()); "No family '%s' in table '%s'.", rawColumn.getFamily(), layout.getName())); if (family.isMapType()) { addColumn(family, rawColumn.getQualifier(), familyMap);
/** {@inheritDoc} */ @Override public void deleteFamily(EntityId entityId, String family, long upToTimestamp) throws IOException { final HBaseFijiTableWriter.WriterLayoutCapsule capsule = mWriterLayoutCapsule; final FamilyLayout familyLayout = capsule.getLayout().getFamilyMap().get(family); if (null == familyLayout) { throw new NoSuchColumnException(String.format("Family '%s' not found.", family)); } if (familyLayout.getLocalityGroup().getFamilyMap().size() > 1) { // There are multiple families within the locality group, so we need to be clever. if (familyLayout.isGroupType()) { deleteGroupFamily(entityId, familyLayout, upToTimestamp); } else if (familyLayout.isMapType()) { deleteMapFamily(entityId, familyLayout, upToTimestamp); } else { throw new RuntimeException("Internal error: family is neither map-type nor group-type."); } return; } // The only data in this HBase family is the one Fiji family, so we can delete everything. final HBaseColumnName hbaseColumnName = capsule.getColumnNameTranslator() .toHBaseColumnName(FijiColumnName.create(family)); final Delete delete = new Delete(entityId.getHBaseRowKey()); delete.deleteFamily(hbaseColumnName.getFamily(), upToTimestamp); // Buffer the delete. updateBuffer(delete); }
} else if (familyLayout.isMapType()) { deleteMapFamily(entityId, familyLayout, upToTimestamp); } else {
/** * Retrieves a list of FijiColumnNames from a FijiTableLayout including both fully qualified * columns as well as map-type families. * * @param fijiTableLayout to retrieve all of the FijiColumnNames from. * @return collection of FijiColumnNames in the specified Layout. */ private static Collection<FijiColumnName> getFijiColumns(FijiTableLayout fijiTableLayout) { // We need to do this because getColumnNames doesn't seem to get all of the columns names; List<FijiColumnName> fijiColumnNames = Lists.newArrayList(); for (FamilyLayout family : fijiTableLayout.getFamilies()) { String familyName = family.getName(); if (family.isMapType()) { // Map type column family FijiColumnName fijiColumnName = new FijiColumnName(familyName); fijiColumnNames.add(fijiColumnName); } else { for (FamilyLayout.ColumnLayout column : family.getColumns()) { String columnName = column.getName(); FijiColumnName fijiColumnName = new FijiColumnName(familyName, columnName); fijiColumnNames.add(fijiColumnName); } } } return fijiColumnNames; }
/** * Reports whether a column exists. * * @param column Column name. * @return whether the specified column exists. */ public boolean exists(FijiColumnName column) { final FamilyLayout fLayout = mFamilyMap.get(column.getFamily()); if (fLayout == null) { // Family does not exist: return false; } if (fLayout.isMapType()) { // This is a map-type family, we don't need to validate the qualifier: return true; } // This is a group-type family: if (!column.isFullyQualified()) { // No column qualifier, the group-type family exists: return true; } // Validate the qualifier: return fLayout.getColumnMap().containsKey(column.getQualifier()); }
/** {@inheritDoc} */ @Override public <T> NavigableMap<String, NavigableMap<Long, T>> getValues(final String family) { final FijiColumnName column = FijiColumnName.create(family, null); validateColumnRequest(column); Preconditions.checkState(mLayout.getFamilyMap().get(family).isMapType(), "getValues(String family) is only enabled on map type column families." + " The column family [%s], is a group type column family." + " Please use the getValues(String family, String qualifier) method.", family); final NavigableMap<String, NavigableMap<Long, T>> qualifiers = Maps.newTreeMap(); for (final FijiCell<T> cell : mResult.<T>narrowView(column)) { NavigableMap<Long, T> columnValues = qualifiers.get(cell.getColumn().getQualifier()); if (columnValues == null) { columnValues = Maps.newTreeMap(TimestampComparator.INSTANCE); qualifiers.put(cell.getColumn().getQualifier(), columnValues); } columnValues.put(cell.getTimestamp(), cell.getData()); } return qualifiers; }
/** {@inheritDoc} */ @Override public FijiPager getPager(final String family) throws FijiColumnPagingNotEnabledException { final FijiColumnName column = FijiColumnName.create(family, null); Preconditions.checkState(mLayout.getFamilyMap().get(family).isMapType(), "getPager(String family) is only enabled on map type column families. " + "The column family '%s' is a group type column family. " + "Please use the getPager(String family, String qualifier) method.", family); final Column columnRequest = mResult.getDataRequest().getColumn(column); Preconditions.checkNotNull(columnRequest, "Requested column %s is not included in the data request %s.", column, mResult.getDataRequest()); if (!columnRequest.isPagingEnabled()) { throw new FijiColumnPagingNotEnabledException( String.format("Requested column %s does not have paging enabled in data request %s.", column, mResult.getDataRequest())); } return new FijiResultQualifierPager(mResult.narrowView(column), mLayout); }
/** {@inheritDoc} */ @Override public <T> NavigableMap<String, NavigableMap<Long, FijiCell<T>>> getCells(final String family) { final FijiColumnName column = FijiColumnName.create(family, null); validateColumnRequest(column); Preconditions.checkState(mLayout.getFamilyMap().get(family).isMapType(), "getCells(String family) is only enabled on map type column families." + " The column family [%s], is a group type column family." + " Please use the getCells(String family, String qualifier) method.", family); final NavigableMap<String, NavigableMap<Long, FijiCell<T>>> qualifiers = Maps.newTreeMap(); for (final FijiCell<T> cell : mResult.<T>narrowView(column)) { NavigableMap<Long, FijiCell<T>> columnValues = qualifiers.get(cell.getColumn().getQualifier()); if (columnValues == null) { columnValues = Maps.newTreeMap(TimestampComparator.INSTANCE); qualifiers.put(cell.getColumn().getQualifier(), columnValues); } columnValues.put(cell.getTimestamp(), cell); } return qualifiers; }
/** {@inheritDoc} */ @Override public <T> NavigableMap<String, NavigableMap<Long, T>> getValues(String family) throws IOException { Preconditions.checkState(mTableLayout.getFamilyMap().get(family).isMapType(), "getValues(String family) is only enabled on map " + "type column families. The column family [%s], is a group type column family. Please use " + "the getValues(String family, String qualifier) method.", family); final NavigableMap<String, NavigableMap<Long, T>> result = Maps.newTreeMap(); for (String qualifier : getQualifiers(family)) { final NavigableMap<Long, T> timeseries = getValues(family, qualifier); result.put(qualifier, timeseries); } return result; }
/** {@inheritDoc} */ @Override public <T> NavigableMap<String, FijiCell<T>> getMostRecentCells(String family) throws IOException { Preconditions.checkState(mTableLayout.getFamilyMap().get(family).isMapType(), "getMostRecentCells(String family) is only enabled" + " on map type column families. The column family [%s], is a group type column family." + " Please use the getMostRecentCells(String family, String qualifier) method.", family); final NavigableMap<String, FijiCell<T>> result = Maps.newTreeMap(); for (String qualifier : getQualifiers(family)) { final FijiCell<T> cell = getMostRecentCell(family, qualifier); result.put(qualifier, cell); } return result; }
/** {@inheritDoc} */ @Override public <T> Iterator<FijiCell<T>> iterator(String family) throws IOException { final FijiColumnName column = FijiColumnName.create(family, null); Preconditions.checkArgument( mDataRequest.getRequestForColumn(column) != null, "Column %s has no data request.", column); Preconditions.checkState(mTableLayout.getFamilyMap().get(family).isMapType(), "iterator(String family) is only enabled" + " on map type column families. The column family [%s], is a group type column family." + " Please use the iterator(String family, String qualifier) method.", family); return new FijiCellIterator<T>(this, column, mTable.getColumnNameTranslator()); }
/** {@inheritDoc} */ @Override public <T> Iterable<FijiCell<T>> asIterable(String family) { final FijiColumnName column = FijiColumnName.create(family, null); Preconditions.checkArgument( mDataRequest.getRequestForColumn(column) != null, "Column %s has no data request.", column); Preconditions.checkState(mTableLayout.getFamilyMap().get(family).isMapType(), "asIterable(String family) is only enabled" + " on map type column families. The column family [%s], is a group type column family." + " Please use the asIterable(String family, String qualifier) method.", family); return new CellIterable<T>(column, this, mTable.getColumnNameTranslator()); }
/** {@inheritDoc} */ @Override public FijiPager getPager(String family) throws FijiColumnPagingNotEnabledException { final FijiColumnName fijiFamily = FijiColumnName.create(family, null); Preconditions.checkState(mTableLayout.getFamilyMap().get(family).isMapType(), "getPager(String family) is only enabled on map type column families. " + "The column family '%s' is a group type column family. " + "Please use the getPager(String family, String qualifier) method.", family); return new HBaseMapFamilyPager(mEntityId, mDataRequest, mTable, fijiFamily); }