Java Code Examples for org.apache.hadoop.hbase.client.Mutation#getAttributesMap()
The following examples show how to use
org.apache.hadoop.hbase.client.Mutation#getAttributesMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtobufUtil.java From hbase with Apache License 2.0 | 6 votes |
/** * Code shared by {@link #toMutation(MutationType, Mutation)} and * {@link #toMutationNoData(MutationType, Mutation)} * @param type * @param mutation * @return A partly-filled out protobuf'd Mutation. */ private static MutationProto.Builder getMutationBuilderAndSetCommonFields(final MutationType type, final Mutation mutation, MutationProto.Builder builder) { builder.setRow(UnsafeByteOperations.unsafeWrap(mutation.getRow())); builder.setMutateType(type); builder.setDurability(toDurability(mutation.getDurability())); builder.setTimestamp(mutation.getTimestamp()); Map<String, byte[]> attributes = mutation.getAttributesMap(); if (!attributes.isEmpty()) { NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder(); for (Map.Entry<String, byte[]> attribute: attributes.entrySet()) { attributeBuilder.setName(attribute.getKey()); attributeBuilder.setValue(UnsafeByteOperations.unsafeWrap(attribute.getValue())); builder.addAttribute(attributeBuilder.build()); } } return builder; }
Example 2
Source File: VerifySingleIndexRowTest.java From phoenix with Apache License 2.0 | 6 votes |
private Mutation getUnverifiedPutMutation(Mutation orig, Long ts) { Mutation m = new Put(orig.getRow()); if (orig.getAttributesMap() != null) { for (Map.Entry<String,byte[]> entry : orig.getAttributesMap().entrySet()) { m.setAttribute(entry.getKey(), entry.getValue()); } } List<Cell> origList = orig.getFamilyCellMap().firstEntry().getValue(); ts = ts == null ? EnvironmentEdgeManager.currentTimeMillis() : ts; Cell c = getNewPutCell(orig, origList, ts, KeyValue.Type.Put); Cell empty = getEmptyCell(orig, origList, ts, KeyValue.Type.Put, false); byte[] fam = CellUtil.cloneFamily(origList.get(0)); List<Cell> famCells = Lists.newArrayList(); m.getFamilyCellMap().put(fam, famCells); famCells.add(c); famCells.add(empty); return m; }
Example 3
Source File: PhoenixIndexCodec.java From phoenix with Apache License 2.0 | 4 votes |
@Override public byte[] getBatchId(Mutation m) { Map<String, byte[]> attributes = m.getAttributesMap(); return attributes.get(INDEX_UUID); }
Example 4
Source File: PhoenixTxIndexMutationGenerator.java From phoenix with Apache License 2.0 | 4 votes |
public Collection<Pair<Mutation, byte[]>> getIndexUpdates(Table htable, Iterator<? extends Mutation> mutationIterator) throws IOException, SQLException { if (!mutationIterator.hasNext()) { return Collections.emptyList(); } List<IndexMaintainer> indexMaintainers = indexMetaData.getIndexMaintainers(); ResultScanner currentScanner = null; // Collect up all mutations in batch Map<ImmutableBytesPtr, MultiMutation> mutations = new HashMap<ImmutableBytesPtr, MultiMutation>(); // Collect the set of mutable ColumnReferences so that we can first // run a scan to get the current state. We'll need this to delete // the existing index rows. int estimatedSize = indexMaintainers.size() * 10; Set<ColumnReference> mutableColumns = Sets.newHashSetWithExpectedSize(estimatedSize); for (IndexMaintainer indexMaintainer : indexMaintainers) { // For transactional tables, we use an index maintainer // to aid in rollback if there's a KeyValue column in the index. The alternative would be // to hold on to all uncommitted index row keys (even ones already sent to HBase) on the // client side. Set<ColumnReference> allColumns = indexMaintainer.getAllColumns(); mutableColumns.addAll(allColumns); } Mutation m = mutationIterator.next(); Map<String,byte[]> updateAttributes = m.getAttributesMap(); byte[] txRollbackAttribute = updateAttributes.get(PhoenixTransactionContext.TX_ROLLBACK_ATTRIBUTE_KEY); boolean isRollback = txRollbackAttribute!=null; boolean isImmutable = indexMetaData.isImmutableRows(); Map<ImmutableBytesPtr, MultiMutation> findPriorValueMutations; if (isImmutable && !isRollback) { findPriorValueMutations = new HashMap<ImmutableBytesPtr, MultiMutation>(); } else { findPriorValueMutations = mutations; } while (true) { // add the mutation to the batch set ImmutableBytesPtr row = new ImmutableBytesPtr(m.getRow()); // if we have no non PK columns, no need to find the prior values if ( mutations != findPriorValueMutations && indexMetaData.requiresPriorRowState(m) ) { addMutation(findPriorValueMutations, row, m); } addMutation(mutations, row, m); if (!mutationIterator.hasNext()) { break; } m = mutationIterator.next(); } Collection<Pair<Mutation, byte[]>> indexUpdates = new ArrayList<Pair<Mutation, byte[]>>(mutations.size() * 2 * indexMaintainers.size()); // Track if we have row keys with Delete mutations (or Puts that are // Tephra's Delete marker). If there are none, we don't need to do the scan for // prior versions, if there are, we do. Since rollbacks always have delete mutations, // this logic will work there too. if (!findPriorValueMutations.isEmpty()) { List<KeyRange> keys = Lists.newArrayListWithExpectedSize(mutations.size()); for (ImmutableBytesPtr ptr : findPriorValueMutations.keySet()) { keys.add(PVarbinary.INSTANCE.getKeyRange(ptr.copyBytesIfNecessary())); } Scan scan = new Scan(); // Project all mutable columns for (ColumnReference ref : mutableColumns) { scan.addColumn(ref.getFamily(), ref.getQualifier()); } /* * Indexes inherit the storage scheme of the data table which means all the indexes have the same * storage scheme and empty key value qualifier. Note that this assumption would be broken if we start * supporting new indexes over existing data tables to have a different storage scheme than the data * table. */ byte[] emptyKeyValueQualifier = indexMaintainers.get(0).getEmptyKeyValueQualifier(); // Project empty key value column scan.addColumn(indexMaintainers.get(0).getDataEmptyKeyValueCF(), emptyKeyValueQualifier); ScanRanges scanRanges = ScanRanges.create(SchemaUtil.VAR_BINARY_SCHEMA, Collections.singletonList(keys), ScanUtil.SINGLE_COLUMN_SLOT_SPAN, null, true, -1); scanRanges.initializeScan(scan); Table txTable = indexMetaData.getTransactionContext().getTransactionalTable(htable, true); // For rollback, we need to see all versions, including // the last committed version as there may be multiple // checkpointed versions. SkipScanFilter filter = scanRanges.getSkipScanFilter(); if (isRollback) { filter = new SkipScanFilter(filter,true); indexMetaData.getTransactionContext().setVisibilityLevel(PhoenixVisibilityLevel.SNAPSHOT_ALL); } scan.setFilter(filter); currentScanner = txTable.getScanner(scan); } if (isRollback) { processRollback(indexMetaData, txRollbackAttribute, currentScanner, mutableColumns, indexUpdates, mutations); } else { processMutation(indexMetaData, txRollbackAttribute, currentScanner, mutableColumns, indexUpdates, mutations, findPriorValueMutations); } return indexUpdates; }
Example 5
Source File: PhoenixIndexCodec.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public byte[] getBatchId(Mutation m) { Map<String, byte[]> attributes = m.getAttributesMap(); return attributes.get(INDEX_UUID); }