/** {@inheritDoc} */ @Override public int hashCode() { return Arrays.hashCode(getHBaseRowKey()); }
/** * Constructs an EntityIdWritable from an existing EntityId. * * @param entityId from a FijiRowData. */ public EntityIdWritable(EntityId entityId) { mHBaseRowKey = entityId.getHBaseRowKey(); try { mComponents = entityId.getComponents(); } catch (IllegalStateException ise) { LOG.warn("Cannot retrieve EntityId components", ise.getMessage()); String asciiRowKey = ByteArrayFormatter.toHex(mHBaseRowKey); mComponents = Collections.singletonList((Object) asciiRowKey); } mShellString = entityId.toShellString(); }
case HASH_PREFIX: return new FijiRestEntityId( new Object[] { Bytes.toString((byte[]) entityId.getComponentByIndex(0)) }, false); case FORMATTED: final HashSpec hashSpec = ((RowKeyFormat2) keysFormat).getSalt(); if (!hashSpec.getSuppressKeyMaterialization()) { return new FijiRestEntityId(entityId.getComponents().toArray(), false); } else { return new FijiRestEntityId( String.format("hbase=%s", Bytes.toStringBinary(entityId.getHBaseRowKey()))); String.format("hbase=%s", Bytes.toStringBinary(entityId.getHBaseRowKey())));
/** {@inheritDoc} */ @Override public void begin(EntityId eid) { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot begin a transaction on an AtomicFijiPutter instance in state %s.", state); // Preconditions.checkArgument() cannot be used here because mEntityId is null between calls to // begin(). if (mPut != null) { throw new IllegalStateException(String.format("There is already a transaction in progress on " + "row: %s. Call commit(), checkAndCommit(), or rollback() to clear the Put.", mEntityId.toShellString())); } synchronized (mLock) { mLayoutOutOfDate = false; } mEntityId = eid; mId = eid.getHBaseRowKey(); mHopper = new ArrayList<KeyValue>(); mPut = new Put(mId); }
/** * Get the entity ID component values from an Entity ID. * * @param entityID The entity ID. * @return The entity ID's component values. */ private List<Object> getEntityIDComponents( final EntityId entityID ) { switch (mRowKeyFormat.getEncoding()) { case RAW: { return ImmutableList.<Object>of(ByteBuffer.wrap(entityID.getHBaseRowKey())); } case FORMATTED: { return entityID.getComponents(); } default: throw new IllegalArgumentException( String.format("Unknown row key encoding %s.", mRowKeyFormat.getEncoding())); } }
final Column columnRequest ) { Preconditions.checkArgument(entityId.getComponents().size() == mEntityIDColumns.size(), "Entity ID components mismatch. entity ID components: {}, entity ID columns: {}", entityId.getComponents(), mEntityIDColumns);
/** * Formats an entity ID for pretty-printing. (e.g., to the console.) * * @deprecated use {@link EntityId#toShellString}. * @param eid Entity ID to format. * @return the formatted entity ID as a String to print for the user. */ @Deprecated public static String formatEntityId(EntityId eid) { return eid.toShellString(); } }
break; if (hasVerboseDebug() && (!row.getEntityId().toShellString().startsWith("hbase="))) { getPrintStream().printf("entity-id=%s%s%n", ToolUtils.HBASE_ROW_KEY_SPEC_PREFIX, Bytes.toStringBinary((row.getEntityId().getHBaseRowKey())));
/** {@inheritDoc} */ @Override public void begin(EntityId eid) { synchronized (mMonitor) { Preconditions.checkState(mState == State.OPEN, "Can not begin a transaction on an AtomicFijiPutter instance in state %s.", mState); if (mStatements != null) { throw new IllegalStateException( String.format( "There is already a transaction in progress on row: %s. Call commit()," + " checkAndCommit(), or rollback() to clear the current transaction.", mEntityId.toShellString())); } mEntityId = eid; mStatements = Lists.newArrayList(); mLayoutChanged = false; mTimestamp = System.currentTimeMillis(); } }
/** {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!getClass().equals(obj.getClass())) { return false; } final EntityId eid = (EntityId) obj; return Arrays.equals(getHBaseRowKey(), eid.getHBaseRowKey()); }
false, layout, Bytes.toString((byte[]) entityId.getComponentByIndex(0))); case FORMATTED: final HashSpec hashSpec = ((RowKeyFormat2) keysFormat).getSalt(); if (hashSpec.getSuppressKeyMaterialization()) { return new JsonEntityIdParser( String.format("hbase=%s", Bytes.toStringBinary(entityId.getHBaseRowKey())), layout); } else { return new JsonEntityIdParser(false, layout, entityId.getComponents()); String.format("hbase=%s", Bytes.toStringBinary(entityId.getHBaseRowKey())), layout);
/** {@inheritDoc} */ @Override public void deleteRow(EntityId entityId, long upToTimestamp) throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot delete row while FijiTableWriter %s is in state %s.", this, state); final Delete delete = SchemaPlatformBridge.get() .createDelete(entityId.getHBaseRowKey(), upToTimestamp); mHTable.delete(delete); }
/** * Returns a line formatted as: * [entityid]|[timestamp]|[key]|[datum_as_json] * * As an exception to this format, Strings are printed without surrounding quotes. * All other data types are returned as json. * * @param row The EntityId of this row. * @param timestamp The timestamp. * @param key The key for this map (identical to the row qualifier). * @param datum The datum to encode as json. * @return The line to export. */ private String makeLine(EntityId row, long timestamp, String key, Object datum) { StringBuilder sb = new StringBuilder(); sb.append(Bytes.toStringBinary(row.getHBaseRowKey())); sb.append(mFieldDelimiter); sb.append(Long.toString(timestamp)); sb.append(mFieldDelimiter); sb.append(key); sb.append(mFieldDelimiter); // If datum is a string, print it without quotes. Otherwise, convert datum to json. if (datum instanceof CharSequence) { sb.append(datum.toString()); } else { sb.append(GenericData.get().toString(datum)); // Converts the datum to json. } return sb.toString(); }
if (null != startRow) { conf.set(FijiConfKeys.FIJI_START_ROW_KEY, Base64.encodeBase64String(startRow.getHBaseRowKey())); Base64.encodeBase64String(endRow.getHBaseRowKey()));
mCurrentWriteBufferSize += mPutBuffer.get(entityId).heapSize(); } else { final Put put = new Put(entityId.getHBaseRowKey()) .add(family, qualifier, timestamp, value); mPutBuffer.put(entityId, put);
/** {@inheritDoc} */ @Override public void deleteRow(EntityId entityId, long upToTimestamp) throws IOException { final Delete delete = SchemaPlatformBridge.get() .createDelete(entityId.getHBaseRowKey(), upToTimestamp); updateBuffer(delete); }
/** {@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); }
/** {@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); }
/** {@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); }
/** * Prints the data for a single entity id. * * @param reader The reader. * @param request The data request. * @param entityId The entity id to lookup. * @param mapTypeFamilies The map type families to print. * @param groupTypeColumns The group type columns to print. * @return A program exit code (zero on success). */ private int lookup( FijiTableReader reader, FijiDataRequest request, EntityId entityId, Map<FamilyLayout, List<String>> mapTypeFamilies, Map<FamilyLayout, List<ColumnLayout>> groupTypeColumns) { try { final FijiRowData row = reader.get(entityId, request); if (hasVerboseDebug() && (!ToolUtils.formatEntityId(entityId).startsWith("hbase="))) { getPrintStream().printf("entity-id=%s%s%n", ToolUtils.HBASE_ROW_KEY_SPEC_PREFIX, Bytes.toStringBinary((entityId.getHBaseRowKey()))); } ToolUtils.printRow(row, mapTypeFamilies, groupTypeColumns, getPrintStream()); } catch (IOException ioe) { LOG.error(ioe.getMessage()); return FAILURE; } return SUCCESS; }