當前位置: 首頁>>代碼示例>>Java>>正文


Java ResultScanner.iterator方法代碼示例

本文整理匯總了Java中org.apache.hadoop.hbase.client.ResultScanner.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java ResultScanner.iterator方法的具體用法?Java ResultScanner.iterator怎麽用?Java ResultScanner.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.hbase.client.ResultScanner的用法示例。


在下文中一共展示了ResultScanner.iterator方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verify

import org.apache.hadoop.hbase.client.ResultScanner; //導入方法依賴的package包/類
private void verify(Scan scan) throws IOException {
  ResultScanner scanner = htable.getScanner(scan);
  Iterator<Result> it = scanner.iterator();

  /* Then */
  int count = 0;
  try {
    while (it.hasNext()) {
      it.next();
      count++;
    }
  } finally {
    scanner.close();
  }
  assertEquals(expected, count);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:17,代碼來源:TestSCVFWithMiniCluster.java

示例2: syncRange

import org.apache.hadoop.hbase.client.ResultScanner; //導入方法依賴的package包/類
/**
 * Rescan the given range directly from the source and target tables.
 * Count and log differences, and if this is not a dry run, output Puts and Deletes
 * to make the target table match the source table for this range
 */
private void syncRange(Context context, ImmutableBytesWritable startRow,
    ImmutableBytesWritable stopRow) throws IOException, InterruptedException {
  
  Scan scan = sourceTableHash.initScan();
  scan.setStartRow(startRow.copyBytes());
  scan.setStopRow(stopRow.copyBytes());
  
  ResultScanner sourceScanner = sourceTable.getScanner(scan);
  CellScanner sourceCells = new CellScanner(sourceScanner.iterator());

  ResultScanner targetScanner = targetTable.getScanner(scan);
  CellScanner targetCells = new CellScanner(targetScanner.iterator());
  
  boolean rangeMatched = true;
  byte[] nextSourceRow = sourceCells.nextRow();
  byte[] nextTargetRow = targetCells.nextRow();
  while(nextSourceRow != null || nextTargetRow != null) {
    boolean rowMatched;
    int rowComparison = compareRowKeys(nextSourceRow, nextTargetRow);
    if (rowComparison < 0) {
      if (LOG.isInfoEnabled()) {
        LOG.info("Target missing row: " + Bytes.toHex(nextSourceRow));
      }
      context.getCounter(Counter.TARGETMISSINGROWS).increment(1);
      
      rowMatched = syncRowCells(context, nextSourceRow, sourceCells, EMPTY_CELL_SCANNER);
      nextSourceRow = sourceCells.nextRow();  // advance only source to next row
    } else if (rowComparison > 0) {
      if (LOG.isInfoEnabled()) {
        LOG.info("Source missing row: " + Bytes.toHex(nextTargetRow));
      }
      context.getCounter(Counter.SOURCEMISSINGROWS).increment(1);
      
      rowMatched = syncRowCells(context, nextTargetRow, EMPTY_CELL_SCANNER, targetCells);
      nextTargetRow = targetCells.nextRow();  // advance only target to next row
    } else {
      // current row is the same on both sides, compare cell by cell
      rowMatched = syncRowCells(context, nextSourceRow, sourceCells, targetCells);
      nextSourceRow = sourceCells.nextRow();  
      nextTargetRow = targetCells.nextRow();
    }
    
    if (!rowMatched) {
      rangeMatched = false;
    }
  }
  
  sourceScanner.close();
  targetScanner.close();
  
  context.getCounter(rangeMatched ? Counter.RANGESMATCHED : Counter.RANGESNOTMATCHED)
    .increment(1);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:59,代碼來源:SyncTable.java

示例3: verifyAttempt

import org.apache.hadoop.hbase.client.ResultScanner; //導入方法依賴的package包/類
/**
 * Looks at every value of the mapreduce output and verifies that indeed
 * the values have been reversed.
 *
 * @param table Table to scan.
 * @throws IOException
 * @throws NullPointerException if we failed to find a cell value
 */
private void verifyAttempt(final Table table)
    throws IOException, NullPointerException {
  Scan scan = new Scan();
  scan.addFamily(INPUT_FAMILY);
  scan.addFamily(OUTPUT_FAMILY);
  ResultScanner scanner = table.getScanner(scan);
  try {
    Iterator<Result> itr = scanner.iterator();
    assertTrue(itr.hasNext());
    while(itr.hasNext()) {
      Result r = itr.next();
      if (LOG.isDebugEnabled()) {
        if (r.size() > 2 ) {
          throw new IOException("Too many results, expected 2 got " +
              r.size());
        }
      }
      byte[] firstValue = null;
      byte[] secondValue = null;
      int count = 0;
      for(Cell kv : r.listCells()) {
        if (count == 0) {
          firstValue = CellUtil.cloneValue(kv);
        }else if (count == 1) {
          secondValue = CellUtil.cloneValue(kv);
        }else if (count == 2) {
          break;
        }
        count++;
      }
      String first = "";
      if (firstValue == null) {
        throw new NullPointerException(Bytes.toString(r.getRow()) +
            ": first value is null");
      }
      first = Bytes.toString(firstValue);
      String second = "";
      if (secondValue == null) {
        throw new NullPointerException(Bytes.toString(r.getRow()) +
            ": second value is null");
      }
      byte[] secondReversed = new byte[secondValue.length];
      for (int i = 0, j = secondValue.length - 1; j >= 0; j--, i++) {
        secondReversed[i] = secondValue[j];
      }
      second = Bytes.toString(secondReversed);
      if (first.compareTo(second) != 0) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("second key is not the reverse of first. row=" +
              Bytes.toStringBinary(r.getRow()) + ", first value=" + first +
              ", second value=" + second);
        }
        fail();
      }
    }
  } finally {
    scanner.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:68,代碼來源:TestMultithreadedTableMapper.java

示例4: verifyAttempt

import org.apache.hadoop.hbase.client.ResultScanner; //導入方法依賴的package包/類
/**
 * Looks at every value of the mapreduce output and verifies that indeed
 * the values have been reversed.
 * @param table Table to scan.
 * @throws IOException
 * @throws NullPointerException if we failed to find a cell value
 */
private void verifyAttempt(final Table table) throws IOException, NullPointerException {
  Scan scan = new Scan();
  TableInputFormat.addColumns(scan, columns);
  ResultScanner scanner = table.getScanner(scan);
  try {
    Iterator<Result> itr = scanner.iterator();
    assertTrue(itr.hasNext());
    while(itr.hasNext()) {
      Result r = itr.next();
      if (getLog().isDebugEnabled()) {
        if (r.size() > 2 ) {
          throw new IOException("Too many results, expected 2 got " +
            r.size());
        }
      }
      byte[] firstValue = null;
      byte[] secondValue = null;
      int count = 0;
       for(Cell kv : r.listCells()) {
        if (count == 0) {
          firstValue = CellUtil.cloneValue(kv);
        }
        if (count == 1) {
          secondValue = CellUtil.cloneValue(kv);
        }
        count++;
        if (count == 2) {
          break;
        }
      }


      if (firstValue == null) {
        throw new NullPointerException(Bytes.toString(r.getRow()) +
          ": first value is null");
      }
      String first = Bytes.toString(firstValue);

      if (secondValue == null) {
        throw new NullPointerException(Bytes.toString(r.getRow()) +
          ": second value is null");
      }
      byte[] secondReversed = new byte[secondValue.length];
      for (int i = 0, j = secondValue.length - 1; j >= 0; j--, i++) {
        secondReversed[i] = secondValue[j];
      }
      String second = Bytes.toString(secondReversed);

      if (first.compareTo(second) != 0) {
        if (getLog().isDebugEnabled()) {
          getLog().debug("second key is not the reverse of first. row=" +
              Bytes.toStringBinary(r.getRow()) + ", first value=" + first +
              ", second value=" + second);
        }
        fail();
      }
    }
  } finally {
    scanner.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:69,代碼來源:TestTableMapReduceBase.java


注:本文中的org.apache.hadoop.hbase.client.ResultScanner.iterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。