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

The following examples show how to use org.apache.hadoop.hbase.CellUtil#compareQualifiers() . 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: BackupSystemTable.java    From hbase with Apache License 2.0 6 votes vote down vote up
Map<byte[], String> readBulkLoadedFiles(String backupId) throws IOException {
  Scan scan = BackupSystemTable.createScanForBulkLoadedFiles(backupId);
  try (Table table = connection.getTable(bulkLoadTableName);
      ResultScanner scanner = table.getScanner(scan)) {
    Result res = null;
    Map<byte[], String> map = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    while ((res = scanner.next()) != null) {
      res.advance();
      byte[] row = CellUtil.cloneRow(res.listCells().get(0));
      for (Cell cell : res.listCells()) {
        if (CellUtil.compareQualifiers(cell, BackupSystemTable.PATH_COL, 0,
          BackupSystemTable.PATH_COL.length) == 0) {
          map.put(row, Bytes.toString(CellUtil.cloneValue(cell)));
        }
      }
    }
    return map;
  }
}
 
Example 2
Source File: NewVersionBehaviorTracker.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public MatchCode checkColumn(Cell cell, byte type) throws IOException {
  if (columns == null) {
      return MatchCode.INCLUDE;
  }

  while (!done()) {
    int c = CellUtil.compareQualifiers(cell,
      columns[columnIndex], 0, columns[columnIndex].length);
    if (c < 0) {
      return MatchCode.SEEK_NEXT_COL;
    }

    if (c == 0) {
      // We drop old version in #isDeleted, so here we must return INCLUDE.
      return MatchCode.INCLUDE;
    }

    columnIndex++;
  }
  // No more columns left, we are done with this query
  return MatchCode.SEEK_NEXT_ROW;
}
 
Example 3
Source File: ExplicitColumnTracker.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void doneWithColumn(Cell cell) {
  while (this.column != null) {
    int compare = CellUtil.compareQualifiers(cell, column.getBuffer(), column.getOffset(),
      column.getLength());
    resetTS();
    if (compare >= 0) {
      ++this.index;
      if (done()) {
        // Will not hit any more columns in this storefile
        this.column = null;
      } else {
        this.column = this.columns[this.index];
      }
      if (compare > 0) {
        continue;
      }
    }
    return;
  }
}
 
Example 4
Source File: ColumnRangeFilter.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnCode filterCell(final Cell c) {
  int cmpMin = 1;

  if (this.minColumn != null) {
    cmpMin = CellUtil.compareQualifiers(c, this.minColumn, 0, this.minColumn.length);
  }

  if (cmpMin < 0) {
    return ReturnCode.SEEK_NEXT_USING_HINT;
  }

  if (!this.minColumnInclusive && cmpMin == 0) {
    return ReturnCode.NEXT_COL;
  }

  if (this.maxColumn == null) {
    return ReturnCode.INCLUDE;
  }

  int cmpMax = CellUtil.compareQualifiers(c, this.maxColumn, 0, this.maxColumn.length);

  if ((this.maxColumnInclusive && cmpMax <= 0) || (!this.maxColumnInclusive && cmpMax < 0)) {
    return ReturnCode.INCLUDE;
  }

  return ReturnCode.NEXT_ROW;
}
 
Example 5
Source File: ColumnPaginationFilter.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnCode filterCell(final Cell c)
{
  if (columnOffset != null) {
    if (count >= limit) {
      return ReturnCode.NEXT_ROW;
    }
    int cmp = 0;
    // Only compare if no KV's have been seen so far.
    if (count == 0) {
      cmp = CellUtil.compareQualifiers(c, this.columnOffset, 0, this.columnOffset.length);
    }
    if (cmp < 0) {
      return ReturnCode.SEEK_NEXT_USING_HINT;
    } else {
      count++;
      return ReturnCode.INCLUDE_AND_NEXT_COL;
    }
  } else {
    if (count >= offset + limit) {
      return ReturnCode.NEXT_ROW;
    }

    ReturnCode code = count < offset ? ReturnCode.NEXT_COL :
                                       ReturnCode.INCLUDE_AND_NEXT_COL;
    count++;
    return code;
  }
}
 
Example 6
Source File: BackupSystemTable.java    From hbase with Apache License 2.0 4 votes vote down vote up
public Map<byte[], List<Path>>[] readBulkLoadedFiles(String backupId, List<TableName> sTableList)
    throws IOException {
  Scan scan = BackupSystemTable.createScanForBulkLoadedFiles(backupId);
  Map<byte[], List<Path>>[] mapForSrc = new Map[sTableList == null ? 1 : sTableList.size()];
  try (Table table = connection.getTable(bulkLoadTableName);
      ResultScanner scanner = table.getScanner(scan)) {
    Result res = null;
    while ((res = scanner.next()) != null) {
      res.advance();
      TableName tbl = null;
      byte[] fam = null;
      String path = null;
      for (Cell cell : res.listCells()) {
        if (CellUtil.compareQualifiers(cell, BackupSystemTable.TBL_COL, 0,
          BackupSystemTable.TBL_COL.length) == 0) {
          tbl = TableName.valueOf(CellUtil.cloneValue(cell));
        } else if (CellUtil.compareQualifiers(cell, BackupSystemTable.FAM_COL, 0,
          BackupSystemTable.FAM_COL.length) == 0) {
          fam = CellUtil.cloneValue(cell);
        } else if (CellUtil.compareQualifiers(cell, BackupSystemTable.PATH_COL, 0,
          BackupSystemTable.PATH_COL.length) == 0) {
          path = Bytes.toString(CellUtil.cloneValue(cell));
        }
      }
      int srcIdx = IncrementalTableBackupClient.getIndex(tbl, sTableList);
      if (srcIdx == -1) {
        // the table is not among the query
        continue;
      }
      if (mapForSrc[srcIdx] == null) {
        mapForSrc[srcIdx] = new TreeMap<>(Bytes.BYTES_COMPARATOR);
      }
      List<Path> files;
      if (!mapForSrc[srcIdx].containsKey(fam)) {
        files = new ArrayList<Path>();
        mapForSrc[srcIdx].put(fam, files);
      } else {
        files = mapForSrc[srcIdx].get(fam);
      }
      files.add(new Path(path));
      if (LOG.isDebugEnabled()) {
        LOG.debug("found bulk loaded file : " + tbl + " " + Bytes.toString(fam) + " " + path);
      }
    }

    return mapForSrc;
  }
}
 
Example 7
Source File: BackupSystemTable.java    From hbase with Apache License 2.0 4 votes vote down vote up
public Pair<Map<TableName, Map<String, Map<String, List<Pair<String, Boolean>>>>>, List<byte[]>>
  readBulkloadRows(List<TableName> tableList) throws IOException {

  Map<TableName, Map<String, Map<String, List<Pair<String, Boolean>>>>> map = new HashMap<>();
  List<byte[]> rows = new ArrayList<>();
  for (TableName tTable : tableList) {
    Scan scan = BackupSystemTable.createScanForOrigBulkLoadedFiles(tTable);
    Map<String, Map<String, List<Pair<String, Boolean>>>> tblMap = map.get(tTable);
    try (Table table = connection.getTable(bulkLoadTableName);
        ResultScanner scanner = table.getScanner(scan)) {
      Result res = null;
      while ((res = scanner.next()) != null) {
        res.advance();
        String fam = null;
        String path = null;
        boolean raw = false;
        byte[] row;
        String region = null;
        for (Cell cell : res.listCells()) {
          row = CellUtil.cloneRow(cell);
          rows.add(row);
          String rowStr = Bytes.toString(row);
          region = BackupSystemTable.getRegionNameFromOrigBulkLoadRow(rowStr);
          if (CellUtil.compareQualifiers(cell, BackupSystemTable.FAM_COL, 0,
            BackupSystemTable.FAM_COL.length) == 0) {
            fam = Bytes.toString(CellUtil.cloneValue(cell));
          } else if (CellUtil.compareQualifiers(cell, BackupSystemTable.PATH_COL, 0,
            BackupSystemTable.PATH_COL.length) == 0) {
            path = Bytes.toString(CellUtil.cloneValue(cell));
          } else if (CellUtil.compareQualifiers(cell, BackupSystemTable.STATE_COL, 0,
            BackupSystemTable.STATE_COL.length) == 0) {
            byte[] state = CellUtil.cloneValue(cell);
            if (Bytes.equals(BackupSystemTable.BL_PREPARE, state)) {
              raw = true;
            } else {
              raw = false;
            }
          }
        }
        if (map.get(tTable) == null) {
          map.put(tTable, new HashMap<>());
          tblMap = map.get(tTable);
        }
        if (tblMap.get(region) == null) {
          tblMap.put(region, new HashMap<>());
        }
        Map<String, List<Pair<String, Boolean>>> famMap = tblMap.get(region);
        if (famMap.get(fam) == null) {
          famMap.put(fam, new ArrayList<>());
        }
        famMap.get(fam).add(new Pair<>(path, raw));
        LOG.debug("found orig " + path + " for " + fam + " of table " + region);
      }
    }
  }
  return new Pair<>(map, rows);
}