Java Code Examples for org.apache.hadoop.hbase.CellUtil#matchingValue()

The following examples show how to use org.apache.hadoop.hbase.CellUtil#matchingValue() . 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: Result.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Does a deep comparison of two Results, down to the byte arrays.
 * @param res1 first result to compare
 * @param res2 second result to compare
 * @throws Exception Every difference is throwing an exception
 */
public static void compareResults(Result res1, Result res2)
    throws Exception {
  if (res2 == null) {
    throw new Exception("There wasn't enough rows, we stopped at "
        + Bytes.toStringBinary(res1.getRow()));
  }
  if (res1.size() != res2.size()) {
    throw new Exception("This row doesn't have the same number of KVs: "
        + res1.toString() + " compared to " + res2.toString());
  }
  Cell[] ourKVs = res1.rawCells();
  Cell[] replicatedKVs = res2.rawCells();
  for (int i = 0; i < res1.size(); i++) {
    if (!ourKVs[i].equals(replicatedKVs[i]) ||
        !CellUtil.matchingValue(ourKVs[i], replicatedKVs[i])) {
      throw new Exception("This result was different: "
          + res1.toString() + " compared to " + res2.toString());
    }
  }
}
 
Example 2
Source File: PrepareIndexMutationsForRebuildTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
boolean isEqualCell(Cell a, Cell b) {
    return CellUtil.matchingRow(a, b)
            && CellUtil.matchingFamily(a, b)
            && CellUtil.matchingQualifier(a, b)
            && CellUtil.matchingTimestamp(a, b)
            && CellUtil.matchingType(a, b)
            && CellUtil.matchingValue(a, b);
}
 
Example 3
Source File: MetaDataUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Iterates over the cells that are mutated by the put operation for the given column family and
 * column qualifier and conditionally modifies those cells to add a tags list. We only add tags
 * if the cell value does not match the passed valueArray. If we always want to add tags to
 * these cells, we can pass in a null valueArray
 * @param somePut Put operation
 * @param family column family of the cells
 * @param qualifier column qualifier of the cells
 * @param cellBuilder ExtendedCellBuilder object
 * @param valueArray byte array of values or null
 * @param tagArray byte array of tags to add to the cells
 */
public static void conditionallyAddTagsToPutCells(Put somePut, byte[] family, byte[] qualifier,
        ExtendedCellBuilder cellBuilder, byte[] valueArray, byte[] tagArray) {
    NavigableMap<byte[], List<Cell>> familyCellMap = somePut.getFamilyCellMap();
    List<Cell> cells = familyCellMap.get(family);
    List<Cell> newCells = Lists.newArrayList();
    if (cells != null) {
        for (Cell cell : cells) {
            if (Bytes.compareTo(cell.getQualifierArray(), cell.getQualifierOffset(),
                    cell.getQualifierLength(), qualifier, 0, qualifier.length) == 0 &&
                    (valueArray == null || !CellUtil.matchingValue(cell, valueArray))) {
                ExtendedCell extendedCell = cellBuilder
                        .setRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())
                        .setFamily(cell.getFamilyArray(), cell.getFamilyOffset(),
                                cell.getFamilyLength())
                        .setQualifier(cell.getQualifierArray(), cell.getQualifierOffset(),
                                cell.getQualifierLength())
                        .setValue(cell.getValueArray(), cell.getValueOffset(),
                                cell.getValueLength())
                        .setTimestamp(cell.getTimestamp())
                        .setType(cell.getType())
                        .setTags(TagUtil.concatTags(tagArray, cell))
                        .build();
                // Replace existing cell with a cell that has the custom tags list
                newCells.add(extendedCell);
            } else {
                // Add cell as is
                newCells.add(cell);
            }
        }
        familyCellMap.put(family, newCells);
    }
}
 
Example 4
Source File: IndexMaintainer.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private boolean hasIndexedColumnChanged(ValueGetter oldState, Collection<? extends Cell> pendingUpdates, long ts) throws IOException {
    if (pendingUpdates.isEmpty()) {
        return false;
    }
    Map<ColumnReference,Cell> newState = Maps.newHashMapWithExpectedSize(pendingUpdates.size()); 
    for (Cell kv : pendingUpdates) {
        newState.put(new ColumnReference(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv)), kv);
    }
    for (ColumnReference ref : indexedColumns) {
    	Cell newValue = newState.get(ref);
    	if (newValue != null) { // Indexed column has potentially changed
    	    ImmutableBytesWritable oldValue = oldState.getLatestValue(ref, ts);
            boolean newValueSetAsNull = (newValue.getTypeByte() == Type.DeleteColumn.getCode() || newValue.getTypeByte() == Type.Delete.getCode() || CellUtil.matchingValue(newValue, HConstants.EMPTY_BYTE_ARRAY));
    		boolean oldValueSetAsNull = oldValue == null || oldValue.getLength() == 0;
    		//If the new column value has to be set as null and the older value is null too,
    		//then just skip to the next indexed column.
    		if (newValueSetAsNull && oldValueSetAsNull) {
    			continue;
    		}
    		if (oldValueSetAsNull || newValueSetAsNull) {
    			return true;
    		}
    		// If the old value is different than the new value, the index row needs to be deleted
    		if (Bytes.compareTo(oldValue.get(), oldValue.getOffset(), oldValue.getLength(), 
    				newValue.getValueArray(), newValue.getValueOffset(), newValue.getValueLength()) != 0) {
    			return true;
    		}
    	}
    }
    return false;
}
 
Example 5
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public static boolean isFamilyDelete(Cell cell) {
  return !TxUtils.isPreExistingVersion(cell.getTimestamp()) &&
    CellUtil.matchingQualifier(cell, TxConstants.FAMILY_DELETE_QUALIFIER) &&
    CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 6
Source File: TransactionUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static boolean isDeleteFamily(Cell cell) {
    return CellUtil.matchingQualifier(cell, FAMILY_DELETE_MARKER) && CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 7
Source File: TransactionUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static boolean isDelete(Cell cell) {
    return CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 8
Source File: TestSyncTable.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void assertTargetDoDeletesFalse(int expectedRows, TableName sourceTableName,
    TableName targetTableName) throws Exception {
  Table sourceTable = TEST_UTIL.getConnection().getTable(sourceTableName);
  Table targetTable = TEST_UTIL.getConnection().getTable(targetTableName);

  ResultScanner sourceScanner = sourceTable.getScanner(new Scan());
  ResultScanner targetScanner = targetTable.getScanner(new Scan());
  Result targetRow = targetScanner.next();
  Result sourceRow = sourceScanner.next();
  int rowsCount = 0;
  while (targetRow != null) {
    rowsCount++;
    //only compares values for existing rows, skipping rows existing on
    //target only that were not deleted given --doDeletes=false
    if (Bytes.toInt(sourceRow.getRow()) != Bytes.toInt(targetRow.getRow())) {
      targetRow = targetScanner.next();
      continue;
    }

    LOG.debug("SOURCE row: " + (sourceRow == null ? "null"
        : Bytes.toInt(sourceRow.getRow()))
        + " cells:" + sourceRow);
    LOG.debug("TARGET row: " + (targetRow == null ? "null"
        : Bytes.toInt(targetRow.getRow()))
        + " cells:" + targetRow);

    Cell[] sourceCells = sourceRow.rawCells();
    Cell[] targetCells = targetRow.rawCells();
    int targetRowKey = Bytes.toInt(targetRow.getRow());
    if (targetRowKey >= 70 && targetRowKey < 80) {
      if (sourceCells.length == targetCells.length) {
        LOG.debug("Source cells: " + Arrays.toString(sourceCells));
        LOG.debug("Target cells: " + Arrays.toString(targetCells));
        Assert.fail("Row " + targetRowKey + " should have more cells in "
            + "target than in source");
      }

    } else {
      if (sourceCells.length != targetCells.length) {
        LOG.debug("Source cells: " + Arrays.toString(sourceCells));
        LOG.debug("Target cells: " + Arrays.toString(targetCells));
        Assert.fail("Row " + Bytes.toInt(sourceRow.getRow())
            + " has " + sourceCells.length
            + " cells in source table but " + targetCells.length
            + " cells in target table");
      }
    }
    for (int j = 0; j < sourceCells.length; j++) {
      Cell sourceCell = sourceCells[j];
      Cell targetCell = targetCells[j];
      try {
        if (!CellUtil.matchingRows(sourceCell, targetCell)) {
          Assert.fail("Rows don't match");
        }
        if (!CellUtil.matchingFamily(sourceCell, targetCell)) {
          Assert.fail("Families don't match");
        }
        if (!CellUtil.matchingQualifier(sourceCell, targetCell)) {
          Assert.fail("Qualifiers don't match");
        }
        if (targetRowKey < 80 && targetRowKey >= 90){
          if (!CellUtil.matchingTimestamp(sourceCell, targetCell)) {
            Assert.fail("Timestamps don't match");
          }
        }
        if (!CellUtil.matchingValue(sourceCell, targetCell)) {
          Assert.fail("Values don't match");
        }
      } catch (Throwable t) {
        LOG.debug("Source cell: " + sourceCell + " target cell: "
            + targetCell);
        Throwables.propagate(t);
      }
    }
    targetRow = targetScanner.next();
    sourceRow = sourceScanner.next();
  }
  assertEquals("Target expected rows does not match.",expectedRows,
      rowsCount);
  sourceScanner.close();
  targetScanner.close();
  sourceTable.close();
  targetTable.close();
}
 
Example 9
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public static boolean isFamilyDelete(Cell cell) {
  return !TxUtils.isPreExistingVersion(cell.getTimestamp()) &&
    CellUtil.matchingQualifier(cell, TxConstants.FAMILY_DELETE_QUALIFIER) &&
    CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 10
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public static boolean isFamilyDelete(Cell cell) {
  return !TxUtils.isPreExistingVersion(cell.getTimestamp()) &&
    CellUtil.matchingQualifier(cell, TxConstants.FAMILY_DELETE_QUALIFIER) &&
    CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 11
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public static boolean isFamilyDelete(Cell cell) {
  return !TxUtils.isPreExistingVersion(cell.getTimestamp()) &&
    CellUtil.matchingQualifier(cell, TxConstants.FAMILY_DELETE_QUALIFIER) &&
    CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 12
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public static boolean isFamilyDelete(Cell cell) {
  return !TxUtils.isPreExistingVersion(cell.getTimestamp()) &&
    CellUtil.matchingQualifier(cell, TxConstants.FAMILY_DELETE_QUALIFIER) &&
    CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 13
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public static boolean isFamilyDelete(Cell cell) {
  return !TxUtils.isPreExistingVersion(cell.getTimestamp()) &&
    CellUtil.matchingQualifier(cell, TxConstants.FAMILY_DELETE_QUALIFIER) &&
    CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 14
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public static boolean isFamilyDelete(Cell cell) {
  return !TxUtils.isPreExistingVersion(cell.getTimestamp()) &&
    CellUtil.matchingQualifier(cell, TxConstants.FAMILY_DELETE_QUALIFIER) &&
    CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 15
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public static boolean isFamilyDelete(Cell cell) {
  return !TxUtils.isPreExistingVersion(cell.getTimestamp()) &&
    CellUtil.matchingQualifier(cell, TxConstants.FAMILY_DELETE_QUALIFIER) &&
    CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 16
Source File: CellUtils.java    From phoenix-omid with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether a cell contains a qualifier that is a delete cell
 * column qualifier or not.
 * @param cell the cell to check if contains the delete cell qualifier
 * @return whether the cell passed contains a delete cell qualifier or not
 */
public static boolean isFamilyDeleteCell(Cell cell) {
    return CellUtil.matchingQualifier(cell, CellUtils.FAMILY_DELETE_QUALIFIER) &&
            CellUtil.matchingValue(cell, HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 17
Source File: CellUtils.java    From phoenix-omid with Apache License 2.0 2 votes vote down vote up
/**
 * Returns if a cell is marked as a tombstone.
 * @param cell the cell to check
 * @return whether the cell is marked as a tombstone or not
 */
public static boolean isTombstone(Cell cell) {
    return CellUtil.matchingValue(cell, DELETE_TOMBSTONE) ||
            CellUtil.matchingValue(cell, LEGACY_DELETE_TOMBSTONE);
}