Java Code Examples for org.apache.hadoop.hbase.client.Put#getRow()

The following examples show how to use org.apache.hadoop.hbase.client.Put#getRow() . 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: TTable.java    From phoenix-omid with Apache License 2.0 6 votes vote down vote up
/**
 * @param put an instance of Put
 * @param timestamp  timestamp to be used as cells version
 * @param commitTimestamp  timestamp to be used as commit timestamp
 * @throws IOException if a remote or network exception occurs.
 */
static public Put markPutAsCommitted(Put put, long timestamp, long commitTimestamp) {
    final Put tsput = new Put(put.getRow(), timestamp);
    propagateAttributes(put, tsput);

    Map<byte[], List<Cell>> kvs = put.getFamilyCellMap();
    for (List<Cell> kvl : kvs.values()) {
        for (Cell c : kvl) {
            KeyValue kv = KeyValueUtil.ensureKeyValue(c);
            Bytes.putLong(kv.getValueArray(), kv.getTimestampOffset(), timestamp);
            try {
                tsput.add(kv);
            } catch (IOException e) {
                // The existing Put has this Cell, so the cloned one
                // will never throw an IOException when it's added.
                throw new RuntimeException(e);
            }
            tsput.addColumn(CellUtil.cloneFamily(kv),
                    CellUtils.addShadowCellSuffixPrefix(CellUtil.cloneQualifier(kv), 0, CellUtil.cloneQualifier(kv).length),
                    kv.getTimestamp(),
                    Bytes.toBytes(commitTimestamp));
        }
    }

    return tsput;
}
 
Example 2
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private Put transactionalizeAction(Put put) throws IOException {
  Put txPut = new Put(put.getRow(), tx.getWritePointer());
  Set<Map.Entry<byte[], List<Cell>>> familyMap = put.getFamilyCellMap().entrySet();
  if (!familyMap.isEmpty()) {
    for (Map.Entry<byte[], List<Cell>> family : familyMap) {
      List<Cell> familyValues = family.getValue();
      if (!familyValues.isEmpty()) {
        for (Cell value : familyValues) {
          txPut.add(value.getFamily(), value.getQualifier(), tx.getWritePointer(), value.getValue());
          addToChangeSet(txPut.getRow(), value.getFamily(), value.getQualifier());
        }
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : put.getAttributesMap().entrySet()) {
    txPut.setAttribute(entry.getKey(), entry.getValue());
  }
  txPut.setDurability(put.getDurability());
  addToOperation(txPut, tx);
  return txPut;
}
 
Example 3
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private Put transactionalizeAction(Put put) throws IOException {
  Put txPut = new Put(put.getRow(), tx.getWritePointer());
  Set<Map.Entry<byte[], List<Cell>>> familyMap = put.getFamilyCellMap().entrySet();
  if (!familyMap.isEmpty()) {
    for (Map.Entry<byte[], List<Cell>> family : familyMap) {
      List<Cell> familyValues = family.getValue();
      if (!familyValues.isEmpty()) {
        for (Cell value : familyValues) {
          txPut.add(value.getFamily(), value.getQualifier(), tx.getWritePointer(), value.getValue());
          addToChangeSet(txPut.getRow(), value.getFamily(), value.getQualifier());
        }
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : put.getAttributesMap().entrySet()) {
    txPut.setAttribute(entry.getKey(), entry.getValue());
  }
  txPut.setDurability(put.getDurability());
  addToOperation(txPut, tx);
  return txPut;
}
 
Example 4
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private Put transactionalizeAction(Put put) throws IOException {
  Put txPut = new Put(put.getRow(), tx.getWritePointer());
  Set<Map.Entry<byte[], List<Cell>>> familyMap = put.getFamilyCellMap().entrySet();
  if (!familyMap.isEmpty()) {
    for (Map.Entry<byte[], List<Cell>> family : familyMap) {
      List<Cell> familyValues = family.getValue();
      if (!familyValues.isEmpty()) {
        for (Cell value : familyValues) {
          txPut.add(value.getFamily(), value.getQualifier(), tx.getWritePointer(), value.getValue());
          addToChangeSet(txPut.getRow(), value.getFamily(), value.getQualifier());
        }
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : put.getAttributesMap().entrySet()) {
    txPut.setAttribute(entry.getKey(), entry.getValue());
  }
  txPut.setDurability(put.getDurability());
  addToOperation(txPut, tx);
  return txPut;
}
 
Example 5
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private Put transactionalizeAction(Put put) throws IOException {
  Put txPut = new Put(put.getRow(), tx.getWritePointer());
  Set<Map.Entry<byte[], List<Cell>>> familyMap = put.getFamilyCellMap().entrySet();
  if (!familyMap.isEmpty()) {
    for (Map.Entry<byte[], List<Cell>> family : familyMap) {
      List<Cell> familyValues = family.getValue();
      if (!familyValues.isEmpty()) {
        for (Cell value : familyValues) {
          txPut.addColumn(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value),
            tx.getWritePointer(), CellUtil.cloneValue(value));
          addToChangeSet(txPut.getRow(), CellUtil.cloneFamily(value),
            CellUtil.cloneQualifier(value));
        }
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : put.getAttributesMap().entrySet()) {
    txPut.setAttribute(entry.getKey(), entry.getValue());
  }
  txPut.setDurability(put.getDurability());
  addToOperation(txPut, tx);
  return txPut;
}
 
Example 6
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private Put transactionalizeAction(Put put) throws IOException {
  Put txPut = new Put(put.getRow(), tx.getWritePointer());
  Set<Map.Entry<byte[], List<Cell>>> familyMap = put.getFamilyCellMap().entrySet();
  if (!familyMap.isEmpty()) {
    for (Map.Entry<byte[], List<Cell>> family : familyMap) {
      List<Cell> familyValues = family.getValue();
      if (!familyValues.isEmpty()) {
        for (Cell value : familyValues) {
          txPut.add(value.getFamily(), value.getQualifier(), tx.getWritePointer(), value.getValue());
          addToChangeSet(txPut.getRow(), value.getFamily(), value.getQualifier());
        }
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : put.getAttributesMap().entrySet()) {
    txPut.setAttribute(entry.getKey(), entry.getValue());
  }
  txPut.setDurability(put.getDurability());
  addToOperation(txPut, tx);
  return txPut;
}
 
Example 7
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private Put transactionalizeAction(Put put) throws IOException {
  Put txPut = new Put(put.getRow(), tx.getWritePointer());
  Set<Map.Entry<byte[], List<Cell>>> familyMap = put.getFamilyCellMap().entrySet();
  if (!familyMap.isEmpty()) {
    for (Map.Entry<byte[], List<Cell>> family : familyMap) {
      List<Cell> familyValues = family.getValue();
      if (!familyValues.isEmpty()) {
        for (Cell value : familyValues) {
          txPut.add(value.getFamily(), value.getQualifier(), tx.getWritePointer(), value.getValue());
          addToChangeSet(txPut.getRow(), value.getFamily(), value.getQualifier());
        }
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : put.getAttributesMap().entrySet()) {
    txPut.setAttribute(entry.getKey(), entry.getValue());
  }
  txPut.setDurability(put.getDurability());
  addToOperation(txPut, tx);
  return txPut;
}
 
Example 8
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private Put transactionalizeAction(Put put) throws IOException {
  Put txPut = new Put(put.getRow(), tx.getWritePointer());
  Set<Map.Entry<byte[], List<Cell>>> familyMap = put.getFamilyCellMap().entrySet();
  if (!familyMap.isEmpty()) {
    for (Map.Entry<byte[], List<Cell>> family : familyMap) {
      List<Cell> familyValues = family.getValue();
      if (!familyValues.isEmpty()) {
        for (Cell value : familyValues) {
          txPut.add(value.getFamily(), value.getQualifier(), tx.getWritePointer(), value.getValue());
          addToChangeSet(txPut.getRow(), value.getFamily(), value.getQualifier());
        }
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : put.getAttributesMap().entrySet()) {
    txPut.setAttribute(entry.getKey(), entry.getValue());
  }
  txPut.setDurability(put.getDurability());
  addToOperation(txPut, tx);
  return txPut;
}
 
Example 9
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private Put transactionalizeAction(Put put) throws IOException {
  Put txPut = new Put(put.getRow(), tx.getWritePointer());
  Set<Map.Entry<byte[], List<Cell>>> familyMap = put.getFamilyCellMap().entrySet();
  if (!familyMap.isEmpty()) {
    for (Map.Entry<byte[], List<Cell>> family : familyMap) {
      List<Cell> familyValues = family.getValue();
      if (!familyValues.isEmpty()) {
        for (Cell value : familyValues) {
          txPut.add(value.getFamily(), value.getQualifier(), tx.getWritePointer(), value.getValue());
          addToChangeSet(txPut.getRow(), value.getFamily(), value.getQualifier());
        }
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : put.getAttributesMap().entrySet()) {
    txPut.setAttribute(entry.getKey(), entry.getValue());
  }
  txPut.setDurability(put.getDurability());
  addToOperation(txPut, tx);
  return txPut;
}
 
Example 10
Source File: Mutators.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
private static void create(Table table, Creator creator, Put put) {
    byte[] row = put.getRow();
    try {
        boolean success = table.checkAndPut(row, Constants.DEFAULT_FAMILY_BYTES,
                creator.getQualifierToCheck(), null, put);
        if (!success) {
            HBaseElement element = (HBaseElement) creator.getElement();
            if (element != null) {
                element.removeStaleIndices();
            }
            throw creator.alreadyExists();
        }
    } catch (IOException e) {
        throw new HBaseGraphException(e);
    }
}
 
Example 11
Source File: TTable.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private Put putInternal(Transaction tx, Put put, boolean addShadowCell) throws IOException {

        throwExceptionIfOpSetsTimerange(put);

        HBaseTransaction transaction = enforceHBaseTransactionAsParam(tx);

        final long writeTimestamp = transaction.getWriteTimestamp();

        // create put with correct ts
        final Put tsput = new Put(put.getRow(), writeTimestamp);
        propagateAttributes(put, tsput);
        Map<byte[], List<Cell>> kvs = put.getFamilyCellMap();
        for (List<Cell> kvl : kvs.values()) {
            for (Cell c : kvl) {
                CellUtils.validateCell(c, writeTimestamp);
                // Reach into keyvalue to update timestamp.
                // It's not nice to reach into keyvalue internals,
                // but we want to avoid having to copy the whole thing
                KeyValue kv = KeyValueUtil.ensureKeyValue(c);
                Bytes.putLong(kv.getValueArray(), kv.getTimestampOffset(), writeTimestamp);
                tsput.add(kv);

                if (addShadowCell) {
                    tsput.addColumn(CellUtil.cloneFamily(kv),
                            CellUtils.addShadowCellSuffixPrefix(CellUtil.cloneQualifier(kv), 0, CellUtil.cloneQualifier(kv).length),
                            kv.getTimestamp(),
                            Bytes.toBytes(kv.getTimestamp()));
                } else {
                    HBaseCellId cellId = new HBaseCellId(this,
                            CellUtil.cloneRow(kv),
                            CellUtil.cloneFamily(kv),
                            CellUtil.cloneQualifier(kv),
                            kv.getTimestamp());

                    addWriteSetElement(transaction, cellId);
                }
            }
        }
        return tsput;
    }
 
Example 12
Source File: HbaseJsonEventSerializerTest.java    From searchanalytics-bigdata with MIT License 5 votes vote down vote up
@Test
public void testGetActions() {
	Event event = generateSearchAnalyticsDataService.getSearchEvents(1).get(0);
	hbaseJsonEventSerializer.initialize(event, null);
	Put action = (Put) hbaseJsonEventSerializer.getActions().get(0);
	byte[] row = action.getRow();
	System.out.println(new String(row));
	System.out.println(new String(row.clone()));
}
 
Example 13
Source File: RemoteHTable.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected CellSetModel buildModelFromPut(Put put) {
  RowModel row = new RowModel(put.getRow());
  long ts = put.getTimestamp();
  for (List<Cell> cells : put.getFamilyCellMap().values()) {
    for (Cell cell : cells) {
      row.addCell(new CellModel(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell),
        ts != HConstants.LATEST_TIMESTAMP ? ts : cell.getTimestamp(), CellUtil.cloneValue(cell)));
    }
  }
  CellSetModel model = new CellSetModel();
  model.addRow(row);
  return model;
}
 
Example 14
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
boolean testRow(final int i) throws IOException {
  final byte [] bytes = format(i);
  // checkAndXXX tests operate on only a single value
  // Put a known value so when we go to check it, it is there.
  Put put = new Put(bytes);
  put.addColumn(FAMILY_ZERO, getQualifier(), bytes);
  this.table.put(put);
  Delete delete = new Delete(put.getRow());
  delete.addColumn(FAMILY_ZERO, getQualifier());
  this.table.checkAndMutate(bytes, FAMILY_ZERO).qualifier(getQualifier())
      .ifEquals(bytes).thenDelete(delete);
  return true;
}
 
Example 15
Source File: ThriftTable.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean thenPut(Put put) throws IOException {
  preCheck();
  RowMutations rowMutations = new RowMutations(put.getRow());
  rowMutations.add(put);
  return checkAndMutate(row, family, qualifier, op, value, rowMutations);
}
 
Example 16
Source File: HBObjectMapper.java    From hbase-orm with Apache License 2.0 4 votes vote down vote up
private <R extends Serializable & Comparable<R>, T extends HBRecord<R>> T readValueFromPut(Put put, Class<T> clazz) {
    if (put == null || put.isEmpty() || put.getRow() == null || put.getRow().length == 0) {
        return null;
    }
    return readValueFromRowAndPut(put.getRow(), put, clazz);
}
 
Example 17
Source File: PrepareIndexMutationsForRebuildTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
void addCellToPutMutation(Put put, byte[] family, byte[] column, long ts, byte[] value) throws Exception {
    byte[] rowKey = put.getRow();
    Cell cell = CellUtil.createCell(rowKey, family, column, ts, KeyValue.Type.Put.getCode(), value);
    put.add(cell);
}
 
Example 18
Source File: SpliceIndexObserver.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit, Durability durability) throws IOException {
    try {
        if (LOG.isTraceEnabled())
            SpliceLogUtils.trace(LOG, "prePut %s",put);
        if(conglomId>0){
            if(put.getAttribute(SIConstants.SUPPRESS_INDEXING_ATTRIBUTE_NAME)!=null) return;
            if(factoryLoader==null){
                /** the below awaitStartup() call is commented out since we don't think there will be
                 * rows inserted into a user index during startup, this code will cause a deadlock
                 * when we add a new system index during system upgrade *
                try{
                    DatabaseLifecycleManager.manager().awaitStartup();
                }catch(InterruptedException e1){
                    throw new InterruptedIOException();
                }
                */
                /* In the case that a new system index is added during a system upgrade, its conglomId will be
                   bigger than 0, but it should still go through the path for system index instead of the regular
                   user table index
                 */
                return;
            }
            //we can't update an index if the conglomerate id isn't positive--it's probably a temp table or something
            byte[] row = put.getRow();
            List<Cell> data = put.get(SIConstants.DEFAULT_FAMILY_BYTES,SIConstants.PACKED_COLUMN_BYTES);
            KVPair kv;
            if(data!=null&&!data.isEmpty()){
                byte[] value = CellUtil.cloneValue(data.get(0));
                if(put.getAttribute(SIConstants.SUPPRESS_INDEXING_ATTRIBUTE_NAME)!=null){
                    kv = new KVPair(row,value, KVPair.Type.UPDATE);
                }else
                    kv = new KVPair(row,value);
            }else{
                kv = new KVPair(row, HConstants.EMPTY_BYTE_ARRAY);
            }
            byte[] txnData = put.getAttribute(SIConstants.SI_TRANSACTION_ID_KEY);
            TxnView txn = operationFactory.fromWrites(txnData,0,txnData.length);
            mutate(kv,txn);
        }
    } catch (Throwable t) {
        throw CoprocessorUtils.getIOException(t);
    }
}