当前位置: 首页>>代码示例>>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;未经允许,请勿转载。