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

The following examples show how to use org.apache.hadoop.hbase.CellUtil#matchingQualifier() . 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: DefaultVisibilityLabelServiceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected Pair<Map<String, Integer>, Map<String, List<Integer>>> extractLabelsAndAuths(
    List<List<Cell>> labelDetails) {
  Map<String, Integer> labels = new HashMap<>();
  Map<String, List<Integer>> userAuths = new HashMap<>();
  for (List<Cell> cells : labelDetails) {
    for (Cell cell : cells) {
      if (CellUtil.matchingQualifier(cell, LABEL_QUALIFIER)) {
        labels.put(
            Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()),
            PrivateCellUtil.getRowAsInt(cell));
      } else {
        // These are user cells who has authorization for this label
        String user = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(),
            cell.getQualifierLength());
        List<Integer> auths = userAuths.get(user);
        if (auths == null) {
          auths = new ArrayList<>();
          userAuths.put(user, auths);
        }
        auths.add(PrivateCellUtil.getRowAsInt(cell));
      }
    }
  }
  return new Pair<>(labels, userAuths);
}
 
Example 2
Source File: ApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * @param next
 * @return
 */
public boolean matchesPoint(KeyValue next) {
  // point deletes only apply to the exact KV that they reference, so we only need to ensure
  // that the timestamp matches exactly. Because we sort by timestamp first, either the next
  // keyvalue has the exact timestamp or is an older (smaller) timestamp, and we can allow that
  // one.
  if (pointDelete != null && CellUtil.matchingFamily(pointDelete, next)
      && CellUtil.matchingQualifier(pointDelete, next)) {
    if (pointDelete.getTimestamp() == next.getTimestamp()) {
      return true;
    }
    // clear the point delete since the TS must not be matching
    pointDelete = null;
  }
  return false;
}
 
Example 3
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the current cell should be skipped. The cell will be skipped
 * if the previous keyvalue had the same key as the current cell. This means filter already responded
 * for the previous keyvalue with ReturnCode.NEXT_COL or ReturnCode.INCLUDE_AND_NEXT_COL.
 * @param cell the {@link Cell} to be tested for skipping
 * @return true is current cell should be skipped, false otherwise
 */
private boolean skipCellVersion(Cell cell) {
  return skipColumn != null
    && CellUtil.matchingRow(cell, skipColumn.getRowArray(), skipColumn.getRowOffset(),
                            skipColumn.getRowLength())
    && CellUtil.matchingFamily(cell, skipColumn.getFamilyArray(), skipColumn.getFamilyOffset(),
                               skipColumn.getFamilyLength())
    && CellUtil.matchingQualifier(cell, skipColumn.getQualifierArray(), skipColumn.getQualifierOffset(),
                                  skipColumn.getQualifierLength());
}
 
Example 4
Source File: IndexRebuildRegionScanner.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static Cell getCell(Mutation m, byte[] family, byte[] qualifier) {
    List<Cell> cellList = m.getFamilyCellMap().get(family);
    if (cellList == null) {
        return null;
    }
    for (Cell cell : cellList) {
        if (CellUtil.matchingQualifier(cell, qualifier)) {
            return cell;
        }
    }
    return null;
}
 
Example 5
Source File: TestScanner.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Cell getColumn(final List<Cell> kvs, final byte [] family,
    final byte [] qualifier) {
  for (Cell kv: kvs) {
    if (CellUtil.matchingFamily(kv, family) && CellUtil.matchingQualifier(kv, qualifier)) {
      return kv;
    }
  }
  return null;
}
 
Example 6
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the current cell should be skipped. The cell will be skipped
 * if the previous keyvalue had the same key as the current cell. This means filter already responded
 * for the previous keyvalue with ReturnCode.NEXT_COL or ReturnCode.INCLUDE_AND_NEXT_COL.
 * @param cell the {@link Cell} to be tested for skipping
 * @return true is current cell should be skipped, false otherwise
 */
private boolean skipCellVersion(Cell cell) {
  return skipColumn != null
    && CellUtil.matchingRow(cell, skipColumn.getRowArray(), skipColumn.getRowOffset(),
                            skipColumn.getRowLength())
    && CellUtil.matchingFamily(cell, skipColumn.getFamilyArray(), skipColumn.getFamilyOffset(),
                               skipColumn.getFamilyLength())
    && CellUtil.matchingQualifier(cell, skipColumn.getQualifierArray(), skipColumn.getQualifierOffset(),
                                  skipColumn.getQualifierLength());
}
 
Example 7
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the current cell should be skipped. The cell will be skipped
 * if the previous keyvalue had the same key as the current cell. This means filter already responded
 * for the previous keyvalue with ReturnCode.NEXT_COL or ReturnCode.INCLUDE_AND_NEXT_COL.
 * @param cell the {@link Cell} to be tested for skipping
 * @return true is current cell should be skipped, false otherwise
 */
private boolean skipCellVersion(Cell cell) {
  return skipColumn != null
    && CellUtil.matchingRow(cell, skipColumn.getRowArray(), skipColumn.getRowOffset(),
                            skipColumn.getRowLength())
    && CellUtil.matchingFamily(cell, skipColumn.getFamilyArray(), skipColumn.getFamilyOffset(),
                               skipColumn.getFamilyLength())
    && CellUtil.matchingQualifier(cell, skipColumn.getQualifierArray(), skipColumn.getQualifierOffset(),
                                  skipColumn.getQualifierLength());
}
 
Example 8
Source File: CompactorScanner.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private void skipToNextColumn(Cell cell, PeekingIterator<Map.Entry<Cell, Optional<Cell>>> iter) {
    boolean isFamilyDelete = CellUtils.isFamilyDeleteCell(cell);
    while (iter.hasNext()
            && CellUtil.matchingFamily(iter.peek().getKey(), cell)
            && (CellUtil.matchingQualifier(iter.peek().getKey(), cell) || isFamilyDelete)) {
        iter.next();
    }
}
 
Example 9
Source File: VisibilityScanDeleteTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void add(Cell delCell) {
  //Cannot call super.add because need to find if the delete needs to be considered
  long timestamp = delCell.getTimestamp();
  byte type = delCell.getTypeByte();
  if (type == KeyValue.Type.DeleteFamily.getCode()) {
    hasFamilyStamp = true;
    boolean hasVisTag = extractDeleteCellVisTags(delCell, KeyValue.Type.DeleteFamily);
    if (!hasVisTag && timestamp > familyStamp) {
      familyStamp = timestamp;
    }
    return;
  } else if (type == KeyValue.Type.DeleteFamilyVersion.getCode()) {
    familyVersionStamps.add(timestamp);
    extractDeleteCellVisTags(delCell, KeyValue.Type.DeleteFamilyVersion);
    return;
  }
  // new column, or more general delete type
  if (deleteCell != null) {
    if (!(CellUtil.matchingQualifier(delCell, deleteCell))) {
      // A case where there are deletes for a column qualifier but there are
      // no corresponding puts for them. Rare case.
      visibilityTagsDeleteColumns = null;
      visiblityTagsDeleteColumnVersion = null;
    } else if (type == KeyValue.Type.Delete.getCode() && (deleteTimestamp != timestamp)) {
      // there is a timestamp change which means we could clear the list
      // when ts is same and the vis tags are different we need to collect
      // them all. Interesting part is that in the normal case of puts if
      // there are 2 cells with same ts and diff vis tags only one of them is
      // returned. Handling with a single List<Tag> would mean that only one
      // of the cell would be considered. Doing this as a precaution.
      // Rare cases.
      visiblityTagsDeleteColumnVersion = null;
    }
  }
  deleteCell = delCell;
  deleteType = type;
  deleteTimestamp = timestamp;
  extractDeleteCellVisTags(delCell, KeyValue.Type.codeToType(type));
}
 
Example 10
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the current cell should be skipped. The cell will be skipped
 * if the previous keyvalue had the same key as the current cell. This means filter already responded
 * for the previous keyvalue with ReturnCode.NEXT_COL or ReturnCode.INCLUDE_AND_NEXT_COL.
 * @param cell the {@link Cell} to be tested for skipping
 * @return true is current cell should be skipped, false otherwise
 */
private boolean skipCellVersion(Cell cell) {
  return skipColumn != null
    && CellUtil.matchingRow(cell, skipColumn.getRowArray(), skipColumn.getRowOffset(),
                            skipColumn.getRowLength())
    && CellUtil.matchingFamily(cell, skipColumn.getFamilyArray(), skipColumn.getFamilyOffset(),
                               skipColumn.getFamilyLength())
    && CellUtil.matchingQualifier(cell, skipColumn.getQualifierArray(), skipColumn.getQualifierOffset(),
                                  skipColumn.getQualifierLength());
}
 
Example 11
Source File: Mutation.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of all KeyValue objects with matching column family and qualifier.
 *
 * @param family column family
 * @param qualifier column qualifier
 * @return a list of KeyValue objects with the matching family and qualifier,
 *   returns an empty list if one doesn't exist for the given family.
 */
public List<Cell> get(byte[] family, byte[] qualifier) {
  List<Cell> filteredList = new ArrayList<>();
  for (Cell cell: getCellList(family)) {
    if (CellUtil.matchingQualifier(cell, qualifier)) {
      filteredList.add(cell);
    }
  }
  return filteredList;
}
 
Example 12
Source File: ApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * @param next
 * @return
 */
public boolean matchesColumn(KeyValue next) {
  if (deleteColumn == null) {
    return false;
  }
  if (CellUtil.matchingFamily(deleteColumn, next) && CellUtil.matchingQualifier(deleteColumn, next)) {
    // falls within the timestamp range
    if (deleteColumn.getTimestamp() >= next.getTimestamp()) {
      return true;
    }
  } else {
    deleteColumn = null;
  }
  return false;
}
 
Example 13
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 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: 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 17
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 18
Source File: VerifySingleIndexRowTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private void infiltrateCell(Cell c, List<Cell> newCellList, TestType e) {
    Cell newCell;
    Cell emptyCell;
    switch(e) {
    case INVALID_COLUMN:
        newCell =
                CellUtil.createCell(CellUtil.cloneRow(c), CellUtil.cloneFamily(c),
                        Bytes.toBytes(UNEXPECTED_COLUMN),
                        EnvironmentEdgeManager.currentTimeMillis(),
                        KeyValue.Type.Put.getCode(), Bytes.toBytes("zxcv"));
        newCellList.add(newCell);
        newCellList.add(c);
        break;
    case INVALID_CELL_VALUE:
        if (CellUtil.matchingQualifier(c, EMPTY_COLUMN_BYTES)) {
            newCell = getCellWithPut(c);
            emptyCell = getVerifiedEmptyCell(c);
            newCellList.add(newCell);
            newCellList.add(emptyCell);
        } else {
            newCellList.add(c);
        }
        break;
    case INVALID_EMPTY_CELL:
        if (CellUtil.matchingQualifier(c, EMPTY_COLUMN_BYTES)) {
            newCell =
                    CellUtil.createCell(CellUtil.cloneRow(c), CellUtil.cloneFamily(c),
                            CellUtil.cloneQualifier(c), c.getTimestamp(),
                            KeyValue.Type.Delete.getCode(), VERIFIED_BYTES);
            newCellList.add(newCell);
        } else {
            newCellList.add(c);
        }
        break;
    case INVALID_EXTRA_CELL:
        newCell = getCellWithPut(c);
        emptyCell = getVerifiedEmptyCell(c);
        newCellList.add(newCell);
        newCellList.add(emptyCell);
        newCellList.add(c);
    }
}
 
Example 19
Source File: MutableSegment.java    From hbase with Apache License 2.0 4 votes vote down vote up
public void upsert(Cell cell, long readpoint, MemStoreSizing memStoreSizing,
    boolean sizeAddedPreOperation) {
  internalAdd(cell, false, memStoreSizing, sizeAddedPreOperation);

  // Get the Cells for the row/family/qualifier regardless of timestamp.
  // For this case we want to clean up any other puts
  Cell firstCell = PrivateCellUtil.createFirstOnRowColTS(cell, HConstants.LATEST_TIMESTAMP);
  SortedSet<Cell> ss = this.tailSet(firstCell);
  Iterator<Cell> it = ss.iterator();
  // versions visible to oldest scanner
  int versionsVisible = 0;
  while (it.hasNext()) {
    Cell cur = it.next();

    if (cell == cur) {
      // ignore the one just put in
      continue;
    }
    // check that this is the row and column we are interested in, otherwise bail
    if (CellUtil.matchingRows(cell, cur) && CellUtil.matchingQualifier(cell, cur)) {
      // only remove Puts that concurrent scanners cannot possibly see
      if (cur.getTypeByte() == KeyValue.Type.Put.getCode() && cur.getSequenceId() <= readpoint) {
        if (versionsVisible >= 1) {
          // if we get here we have seen at least one version visible to the oldest scanner,
          // which means we can prove that no scanner will see this version

          // false means there was a change, so give us the size.
          // TODO when the removed cell ie.'cur' having its data in MSLAB, we can not release that
          // area. Only the Cell object as such going way. We need to consider cellLen to be
          // decreased there as 0 only. Just keeping it as existing code now. We need to know the
          // removed cell is from MSLAB or not. Will do once HBASE-16438 is in
          int cellLen = getCellLength(cur);
          long heapSize = heapSizeChange(cur, true);
          long offHeapSize = offHeapSizeChange(cur, true);
          incMemStoreSize(-cellLen, -heapSize, -offHeapSize, -1);
          if (memStoreSizing != null) {
            memStoreSizing.decMemStoreSize(cellLen, heapSize, offHeapSize, 1);
          }
          it.remove();
        } else {
          versionsVisible++;
        }
      }
    } else {
      // past the row or column, done
      break;
    }
  }
}
 
Example 20
Source File: CellUtils.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean matchingColumn(Cell kv, byte[] family, byte[] qualifier) {
        return CellUtil.matchingFamily(kv, family) && CellUtil.matchingQualifier(kv,qualifier);
}