/** * Get the column name translator for the current layout of this table. Do not cache this object. * If you need both the table layout and a column name translator within a single short lived * operation, you should use {@link #getLayout()}} and create your own * {@link HBaseColumnNameTranslator} to ensure consistent state. * @return the column name translator for the current layout of this table. */ public HBaseColumnNameTranslator getColumnNameTranslator() { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot get the column name translator of a table in state %s.", state); return HBaseColumnNameTranslator.from(getLayout()); }
/** {@inheritDoc} */ @Override public HBaseColumnName getHBaseColumnName( final FijiColumnName fijiColumnName ) throws NoSuchColumnException { return mTranslator.toHBaseColumnName(fijiColumnName); } }
/** * Get the column name from a meta table key. Does not check if the metaTableKey is a valid * FijiTableAnnotator meta table key. This method is package private for testing. * * @param table HBaseFijiTable in which the column from the specified key lives. This will be used * for column name translation. * @param metaTableKey the meta table key from which to get the column name. * @return the column name stored in the given meta table key. * @throws NoSuchColumnException in case the column does not exist in the table. */ static FijiColumnName columnFromMetaTableKey( final HBaseFijiTable table, final String metaTableKey ) throws NoSuchColumnException { final HBaseColumnNameTranslator translator = table.getColumnNameTranslator(); // Everything between the prefix and the annotation key. final String hbaseColumnString = metaTableKey.substring(METATABLE_KEY_PREFIX.length(), metaTableKey.lastIndexOf('.')); // Everything before the first ':'. final String hbaseFamily = hbaseColumnString.substring(0, hbaseColumnString.indexOf(':')); // Everything after the first ':'. The +1 excludes the ':' itself. final String hbaseQualifier = hbaseColumnString.substring(hbaseColumnString.indexOf(':') + 1); final HBaseColumnName hbaseColumn = new HBaseColumnName(hbaseFamily, hbaseQualifier); return translator.toFijiColumnName(hbaseColumn); }
HBaseColumnNameTranslator.from(mTableLayout); fijiColumnName = columnNameTranslator.toFijiColumnName( new HBaseColumnName(familyEntry.getKey(), columnEntry.getKey())); } catch (NoSuchColumnException e) {
/** {@inheritDoc} */ @Override public byte[] getHBaseCellValue(FijiColumnName column, DecodedCell<?> fijiCell) throws IOException { final CellSpec cellSpec = mColumnNameTranslator.getTableLayout().getCellSpec(column) .setSchemaTable(mSchemaTable); final FijiCellEncoder encoder = DefaultFijiCellEncoderFactory.get().create(cellSpec); return encoder.encode(fijiCell); } }
/** * Translates a Fiji locality group into an HColumnDescriptor. * * @param localityGroup A Fiji locality group. * @param hbaseColumnNameTranslator to convert the locality group into the HBase family. * @return The HColumnDescriptor to use for storing the data in the locality group. */ private static HColumnDescriptor toHColumnDescriptor( final LocalityGroupLayout localityGroup, final HBaseColumnNameTranslator hbaseColumnNameTranslator ) { byte[] hbaseFamilyName = hbaseColumnNameTranslator.toHBaseFamilyName(localityGroup); LocalityGroupDesc groupDesc = localityGroup.getDesc(); return new HColumnDescriptor( hbaseFamilyName, groupDesc.getMaxVersions(), groupDesc.getCompressionType().toString(), groupDesc.getInMemory(), true, // block cache groupDesc.getBlockSize() != null ? groupDesc.getBlockSize() : HColumnDescriptor.DEFAULT_BLOCKSIZE, groupDesc.getTtlSeconds(), groupDesc.getBloomType() != null ? groupDesc.getBloomType().toString() : HColumnDescriptor.DEFAULT_BLOOMFILTER, HColumnDescriptor.DEFAULT_REPLICATION_SCOPE); } }
final HBaseColumnNameTranslator translator = HBaseColumnNameTranslator.from(layout); final HBaseDataRequestAdapter adapter = new HBaseDataRequestAdapter(nextPageDataRequest, translator); final HBaseColumnName hbaseColumn = new HBaseColumnName(kvs[i].getFamily(), kvs[i].getQualifier()); final FijiColumnName fijiColumn = translator.toFijiColumnName(hbaseColumn); qualifiers[i] = fijiColumn.getQualifier();
/** {@inheritDoc} */ @Override public HBaseColumnName getHBaseColumnName(FijiColumnName fijiColumnName) throws NoSuchColumnException { return mColumnNameTranslator.toHBaseColumnName(fijiColumnName); }
/** * Get a FijiResult corresponding to the same data as this KjiRowData. * * <p> * This method allows the caller to specify a type-bound on the values of the {@code FijiCell}s * of the returned {@code FijiResult}. The caller should be careful to only specify an * appropriate type. If the type is too specific (or wrong), a runtime * {@link java.lang.ClassCastException} will be thrown when the returned {@code FijiResult} is * used. See the 'Type Safety' section of {@link FijiResult}'s documentation for more details. * </p> * * @return A FijiResult corresponding to the same data as this FijiRowData. * @param <T> The type of {@code FijiCell} values in the returned {@code FijiResult}. * @throws IOException if error while decoding cells. */ public <T> FijiResult<T> asFijiResult() throws IOException { return HBaseFijiResult.create( mEntityId, mDataRequest, mResult, mTable, mTableLayout, HBaseColumnNameTranslator.from(mTableLayout), mDecoderProvider); }
/** * Get the FijiColumnName encoded in the Key of a given KeyValue. * * @param kv KeyValue from which to get the encoded FijiColumnName. * @param translator for table. * @return the FijiColumnName encoded in the Key of a given KeyValue. */ private static FijiColumnName getKeyValueColumnName( final KeyValue kv, final HBaseColumnNameTranslator translator ) { final HBaseColumnName hBaseColumnName = new HBaseColumnName(kv.getFamily(), kv.getQualifier()); try { return translator.toFijiColumnName(hBaseColumnName); } catch (NoSuchColumnException nsce) { // This should not happen since it's only called on data returned by HBase. throw new IllegalStateException( String.format("Unknown column name in KeyValue: %s.", kv)); } }
/** * 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); }
/** * Applies the row filter to an HBase scan object. * * <p>This will tell HBase region servers to filter rows on the server-side, so filtered * rows will not even need to get sent across the network back to the client.</p> * * @param scan An HBase scan descriptor. * @throws IOException If there is an IO error. */ public void applyTo(Scan scan) throws IOException { // The filter might need to request data that isn't already requested by the scan, so add // it here if needed. try { // TODO: SCHEMA-444 Avoid constructing a new FijiColumnNameTranslator below. new HBaseDataRequestAdapter( mRowFilter.getDataRequest(), HBaseColumnNameTranslator.from(mTableLayout)) .applyToScan(scan, mTableLayout); } catch (InvalidLayoutException e) { throw new InternalFijiError(e); } // Set the filter. final FijiRowFilter.Context context = new FijiRowFilterContext(HBaseColumnNameTranslator.from(mTableLayout)); scan.setFilter(mRowFilter.toHBaseFilter(context)); } }
mLastQualifier = keyValue.getQualifier(); mLastColumn = mColumnTranslator.toFijiColumnName( new HBaseColumnName(keyValue.getFamily(), keyValue.getQualifier()));
/** {@inheritDoc} */ @Override public void deleteColumn(EntityId entityId, String family, String qualifier, long upToTimestamp) throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot delete column while FijiTableWriter %s is in state %s.", this, state); final HBaseColumnName hbaseColumnName = mWriterLayoutCapsule.getColumnNameTranslator() .toHBaseColumnName(FijiColumnName.create(family, qualifier)); final Delete delete = new Delete(entityId.getHBaseRowKey()) .deleteColumns(hbaseColumnName.getFamily(), hbaseColumnName.getQualifier(), upToTimestamp); mHTable.delete(delete); }
/** * Constructs a new context that can write cells to an HFile that can be loaded into an HBase * table. * * @param hadoopContext is the Hadoop {@link TaskInputOutputContext} that will be used to perform * the writes. * @throws IOException on I/O error. */ public HFileWriterContext(TaskInputOutputContext<?, ?, ?, ?> hadoopContext) throws IOException { super(hadoopContext); final Configuration conf = new Configuration(hadoopContext.getConfiguration()); final FijiURI outputURI = FijiURI.newBuilder(conf.get(FijiConfKeys.FIJI_OUTPUT_TABLE_URI)).build(); mFiji = Fiji.Factory.open(outputURI, conf); mTable = mFiji.openTable(outputURI.getTable()); mReader = mTable.openTableReader(); mColumnNameTranslator = HBaseColumnNameTranslator.from(mTable.getLayout()); mEntityIdFactory = EntityIdFactory.getFactory(mTable.getLayout()); }
next.getFamily(), next.getQualifier()); final FijiColumnName column = mColumnNameTranslator.toFijiColumnName(hbaseColumn);
/** {@inheritDoc} */ @Override public void deleteCell(EntityId entityId, String family, String qualifier, long timestamp) throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot delete cell while FijiTableWriter %s is in state %s.", this, state); final HBaseColumnName hbaseColumnName = mWriterLayoutCapsule.getColumnNameTranslator() .toHBaseColumnName(FijiColumnName.create(family, qualifier)); final Delete delete = new Delete(entityId.getHBaseRowKey()) .deleteColumn(hbaseColumnName.getFamily(), hbaseColumnName.getQualifier(), timestamp); mHTable.delete(delete); }
/** * Translates a Fiji table layout into an HColumnDescriptor. * * @param fijiInstanceName The name of the Fiji instance the table lives in. * @param tableLayout The Fiji table layout. * @return The HTableDescriptor to use for storing the Fiji table data. */ public HTableDescriptor toHTableDescriptor(String fijiInstanceName, FijiTableLayout tableLayout) { // Figure out the name of the table. final String tableName = tableLayout.getName(); final FijiManagedHBaseTableName hbaseTableName = FijiManagedHBaseTableName.getFijiTableName(fijiInstanceName, tableName); final HTableDescriptor tableDescriptor = new HTableDescriptor(hbaseTableName.toString()); TableLayoutDesc tableLayoutDesc = tableLayout.getDesc(); if (tableLayoutDesc.getMaxFilesize() != null) { tableDescriptor.setMaxFileSize(tableLayoutDesc.getMaxFilesize()); } if (tableLayoutDesc.getMemstoreFlushsize() != null) { tableDescriptor.setMemStoreFlushSize(tableLayoutDesc.getMemstoreFlushsize()); } HBaseColumnNameTranslator translator = HBaseColumnNameTranslator.from(tableLayout); // Add the columns. for (LocalityGroupLayout localityGroup : tableLayout.getLocalityGroupMap().values()) { tableDescriptor.addFamily(toHColumnDescriptor(localityGroup, translator)); } return tableDescriptor; }
try { mLastColumn = mColumnTranslator.toFijiColumnName( new HBaseColumnName(keyValue.getFamily(), keyValue.getQualifier())); } catch (NoSuchColumnException e) {
/** {@inheritDoc} */ @Override public <T> void put(EntityId entityId, String family, String qualifier, long timestamp, T value) throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot put cell to FijiTableWriter instance %s in state %s.", this, state); final FijiColumnName columnName = FijiColumnName.create(family, qualifier); final WriterLayoutCapsule capsule = mWriterLayoutCapsule; final HBaseColumnName hbaseColumnName = capsule.getColumnNameTranslator().toHBaseColumnName(columnName); final FijiCellEncoder cellEncoder = capsule.getCellEncoderProvider().getEncoder(family, qualifier); final byte[] encoded = cellEncoder.encode(value); final Put put = new Put(entityId.getHBaseRowKey()) .add(hbaseColumnName.getFamily(), hbaseColumnName.getQualifier(), timestamp, encoded); mHTable.put(put); }