/** * Creates a provider for cell decoders. * * <p> The provider creates decoders for specific Avro records. </p> * * @param table HBase FijiTable to create a CellDecoderProvider for. * @return a new CellDecoderProvider for the specified HBase FijiTable. * @throws IOException on I/O error. */ private static CellDecoderProvider createCellProvider( final HBaseFijiTable table ) throws IOException { return CellDecoderProvider.create( table.getLayout(), ImmutableMap.<FijiColumnName, BoundColumnReaderSpec>of(), ImmutableList.<BoundColumnReaderSpec>of(), FijiTableReaderBuilder.DEFAULT_CACHE_MISS); }
/** {@inheritDoc} */ @Override public <T> T getMostRecentValue(String family, String qualifier) throws IOException { final FijiCellDecoder<T> decoder = mDecoderProvider.getDecoder(FijiColumnName.create(family, qualifier)); final NavigableMap<Long, byte[]> tmap = getRawTimestampMap(family, qualifier); if (null == tmap) { return null; } final byte[] bytes = tmap.values().iterator().next(); return decoder.decodeValue(bytes); }
mResult = result; mDecoderProvider = ((decoderProvider != null) ? decoderProvider : createCellProvider(table)) .getDecoderProviderForRequest(dataRequest);
/** * Create a provider for cell decoders. * * @param layout the layout for which to provide decoders. * @param overrides Column specification overlay/override map. Specifications from this map * override the actual specification from the table. * @param onDecoderCacheMiss behavior to use when a decoder cannot be found. * @param alternatives alternate column specifications for which decoders should be provided. * @throws IOException in case of an error creating the cached decoders. * @return a new {@code CellDecoderProvider}. */ public static CellDecoderProvider create( final FijiTableLayout layout, final Map<FijiColumnName, BoundColumnReaderSpec> overrides, final Collection<BoundColumnReaderSpec> alternatives, final OnDecoderCacheMiss onDecoderCacheMiss ) throws IOException { // Pro-actively build cell decoders for all columns in the table and spec overrides: return new CellDecoderProvider( layout, makeColumnDecoderMap(layout, overrides), makeSpecDecoderMap(layout, overrides.values(), alternatives), onDecoderCacheMiss); }
columnDecoders.put(readerSpec.getColumn(), getDecoder(readerSpec)); return new CellDecoderProvider( mLayout, ImmutableMap.copyOf(columnDecoders),
/** * Build a map of {@link BoundColumnReaderSpec} to {@link FijiCellDecoder} from a collection of * specs. * * All columns in overrides and alternatives are assumed to be included in the table layout * because of prior validation. * * @param layout FijiTableLayout from which storage information will be retrieved to build * decoders. * @param overrides specifications of column read properties from which to build decoders. * @param alternatives further specifications of column reader properties from which to build * decoders. * @return a map from specification to decoders which follow those specifications. * @throws IOException in case of an error making decoders. */ private static Map<BoundColumnReaderSpec, FijiCellDecoder<?>> makeSpecDecoderMap( final FijiTableLayout layout, final Collection<BoundColumnReaderSpec> overrides, final Collection<BoundColumnReaderSpec> alternatives ) throws IOException { final Map<BoundColumnReaderSpec, FijiCellDecoder<?>> decoderMap = Maps.newHashMap(); for (BoundColumnReaderSpec spec : overrides) { Preconditions.checkState(null == decoderMap.put(spec, createDecoderFromSpec(layout, spec))); } for (BoundColumnReaderSpec spec : alternatives) { Preconditions.checkState(null == decoderMap.put(spec, createDecoderFromSpec(layout, spec))); } return decoderMap; }
decoderMap.put(column, decoder); return new CellDecoderProvider( layout, decoderMap.build(),
decoderMap.put(column, createDecoderFromSpec(layout, spec)); } else { final CellSpec cellSpec = layout.getCellSpec(column);
/** {@inheritDoc} */ @Override public Iterator<FijiCell<T>> apply(final ResultSet resultSet) { final Function<Row, FijiCell<T>> decoder = new QualifiedColumnDecoder<>(column, decoderProvider.<T>getDecoder(column)); return Iterators.transform(resultSet.iterator(), decoder); } };
decoderProvider.getDecoderProviderForRequest(dataRequest);
spec.getColumnReaderSpec(), spec.getColumn()); final FijiCellDecoder<T> newDecoder = (FijiCellDecoder<T>) createDecoderFromSpec(mLayout, spec); mReaderSpecDecoders.put(spec, newDecoder); return newDecoder; "Building and not caching new cell decoder from ColumnReaderSpec: {} for column: {}", spec.getColumnReaderSpec(), spec.getColumn()); return (FijiCellDecoder<T>) createDecoderFromSpec(mLayout, spec);
/** {@inheritDoc} */ @Override public <T> T getValue(String family, String qualifier, long timestamp) throws IOException { final FijiCellDecoder<T> decoder = mDecoderProvider.getDecoder(FijiColumnName.create(family, qualifier)); final byte[] bytes = getRawCell(family, qualifier, timestamp); return decoder.decodeValue(bytes); }
decoderProvider.getDecoderProviderForRequest(dataRequest);
/** {@inheritDoc} */ @Override public <T> NavigableMap<Long, FijiCell<T>> getCells(String family, String qualifier) throws IOException { final FijiCellDecoder<T> decoder = mDecoderProvider.getDecoder(FijiColumnName.create(family, qualifier)); final NavigableMap<Long, FijiCell<T>> result = Maps.newTreeMap(TimestampComparator.INSTANCE); final NavigableMap<Long, byte[]> tmap = getRawTimestampMap(family, qualifier); if (tmap != null) { for (Map.Entry<Long, byte[]> entry : tmap.entrySet()) { final Long timestamp = entry.getKey(); final byte[] bytes = entry.getValue(); final FijiCell<T> cell = FijiCell.create( FijiColumnName.create(family, qualifier), timestamp, decoder.decodeCell(bytes)); result.put(timestamp, cell); } } return result; }
return getDecoder(FijiColumnName.create(column.getFamily(), null));
/** {@inheritDoc} */ @Override public <T> FijiCell<T> getMostRecentCell(String family, String qualifier) throws IOException { final FijiCellDecoder<T> decoder = mDecoderProvider.getDecoder(FijiColumnName.create(family, qualifier)); final NavigableMap<Long, byte[]> tmap = getRawTimestampMap(family, qualifier); if (null == tmap) { return null; } final byte[] bytes = tmap.values().iterator().next(); final long timestamp = tmap.firstKey(); return FijiCell.create( FijiColumnName.create(family, qualifier), timestamp, decoder.decodeCell(bytes)); }
/** * 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); } }
/** {@inheritDoc} */ @Override public <T> FijiCell<T> getCell(String family, String qualifier, long timestamp) throws IOException { final FijiCellDecoder<T> decoder = mDecoderProvider.getDecoder(FijiColumnName.create(family, qualifier)); final byte[] bytes = getRawCell(family, qualifier, timestamp); return FijiCell.create( FijiColumnName.create(family, qualifier), timestamp, decoder.decodeCell(bytes)); }