Java Code Examples for org.apache.hadoop.hbase.client.Scan.setStopRow()

The following are Jave code examples for showing how to use setStopRow() of the org.apache.hadoop.hbase.client.Scan class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test(timeout = 300000)
public void testMinWithInvalidRange2() {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addFamily(TEST_FAMILY);
  scan.setStartRow(ROWS[6]);
  scan.setStopRow(ROWS[6]);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  Double min = null;
  try {
    min = aClient.min(TEST_TABLE, ci, scan);
  } catch (Throwable e) {
  }
  assertEquals(null, min);// control should go to the catch block
}
 
Example 2
Project: ditb   File: TestBigDecimalColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test (timeout=300000)
public void testAvgWithInvalidRange() {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  scan.setStartRow(ROWS[5]);
  scan.setStopRow(ROWS[1]);
  final ColumnInterpreter<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
    new BigDecimalColumnInterpreter();
  Double avg = null;
  try {
    avg = aClient.avg(TEST_TABLE, ci, scan);
  } catch (Throwable e) {
  }
  assertEquals(null, avg);// control should go to the catch block
}
 
Example 3
Project: ditb   File: TestBigDecimalColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test (timeout=300000)
public void testMinWithInvalidRange() {
  AggregationClient aClient = new AggregationClient(conf);
  BigDecimal min = null;
  Scan scan = new Scan();
  scan.addFamily(TEST_FAMILY);
  scan.setStartRow(ROWS[4]);
  scan.setStopRow(ROWS[2]);
  final ColumnInterpreter<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
    new BigDecimalColumnInterpreter();
  try {
    min = aClient.min(TEST_TABLE, ci, scan);
  } catch (Throwable e) {
  }
  assertEquals(null, min);// control should go to the catch block
}
 
Example 4
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test(timeout = 300000)
public void testAvgWithInvalidRange() {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  scan.setStartRow(ROWS[5]);
  scan.setStopRow(ROWS[1]);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  Double avg = null;
  try {
    avg = aClient.avg(TEST_TABLE, ci, scan);
  } catch (Throwable e) {
  }
  assertEquals(null, avg);// control should go to the catch block
}
 
Example 5
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test(timeout = 300000)
public void testMaxWithInvalidRange() {
  AggregationClient aClient = new AggregationClient(conf);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  Scan scan = new Scan();
  scan.setStartRow(ROWS[4]);
  scan.setStopRow(ROWS[2]);
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  double max = Double.MIN_VALUE;
  ;
  try {
    max = aClient.max(TEST_TABLE, ci, scan);
  } catch (Throwable e) {
    max = 0.00;
  }
  assertEquals(0.00, max, 0.00);// control should go to the catch block
}
 
Example 6
Project: ditb   File: TestBigDecimalColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test (timeout=300000)
public void testMaxWithInvalidRange() {
  AggregationClient aClient = new AggregationClient(conf);
  final ColumnInterpreter<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
    new BigDecimalColumnInterpreter();
  Scan scan = new Scan();
  scan.setStartRow(ROWS[4]);
  scan.setStopRow(ROWS[2]);
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  BigDecimal max = new BigDecimal(Long.MIN_VALUE);
  ;
  try {
    max = aClient.max(TEST_TABLE, ci, scan);
  } catch (Throwable e) {
    max = BigDecimal.ZERO;
  }
  assertEquals(BigDecimal.ZERO, max);// control should go to the catch block
}
 
Example 7
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test(timeout = 300000)
public void testStdWithValidRangeWithNullCF() {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.setStartRow(ROWS[6]);
  scan.setStopRow(ROWS[17]);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  Double std = null;
  try {
    std = aClient.std(TEST_TABLE, ci, scan);
  } catch (Throwable e) {
  }
  assertEquals(null, std);// CP will throw an IOException about the
  // null column family, and max will be set to 0
}
 
Example 8
Project: ditb   File: TestBigDecimalColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test (timeout=300000)
public void testStdWithValidRangeWithNullCF() {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.setStartRow(ROWS[6]);
  scan.setStopRow(ROWS[17]);
  final ColumnInterpreter<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
    new BigDecimalColumnInterpreter();
  Double std = null;
  try {
    std = aClient.std(TEST_TABLE, ci, scan);
  } catch (Throwable e) {
  }
  assertEquals(null, std);// CP will throw an IOException about the
  // null column family, and max will be set to 0
}
 
Example 9
Project: ditb   File: LocalScannerInParallel.java   Source Code and License Vote up 5 votes
private void innerAddScanner(HRegionLocation regionLocation) throws IOException {
  Scan newScan = new Scan(rawScan);
  if (regionLocation.getRegionInfo().getStartKey() != null)
    newScan.setStartRow(regionLocation.getRegionInfo().getStartKey());
  if (regionLocation.getRegionInfo().getEndKey() != null)
    newScan.setStopRow(regionLocation.getRegionInfo().getEndKey());
  newScan.setAttribute(IndexConstants.SCAN_WITH_INDEX, Bytes.toBytes("Hi"));
  ResultScanner scanner = table.getScanner(newScan);
  synchronized (scannerList) {
    scannerList.add(scanner);
  }
}
 
Example 10
Project: ditb   File: GCScanner.java   Source Code and License Vote up 5 votes
/**
 * init selected range and scanner
 *
 * @throws IOException
 */
private void initScanner() throws IOException {
  ScanRange selectedRange = null;
  int selectedRegionNumber = Integer.MAX_VALUE;
  for (ScanRange range : rangeList.getRanges()) {
    int cover = countCoveringRegions(conn,
        relation.getIndexTableName(range.getFamily(), range.getQualifier()), range.getStart(),
        range.getStop());
    LOG.info("LCDBG, " + cover + " regions are covered by range " + range);
    if (selectedRegionNumber > cover) {
      selectedRegionNumber = cover;
      selectedRange = range;
    }
  }
  LOG.info("LCDBG, GC Scanner using range " + selectedRange + " with " + selectedRegionNumber
      + " regions for scan id= " + rawScan.getId());
  indexFamily = selectedRange.getFamily();
  indexQualifier = selectedRange.getQualifier();
  List<ScanRange> list = new ArrayList<>(rangeList.getRanges());
  list.remove(selectedRange);
  Scan scan = new Scan();
  scan.setStartRow(selectedRange.getStart());
  scan.setStopRow(selectedRange.getStop());
  scan.setFamilyMap(rawScan.getFamilyMap());
  scan.setCaching(rawScan.getCaching());
  scan.setCacheBlocks(rawScan.getCacheBlocks());
  scan.setId(rawScan.getId());
  scan.setFilter(new ScanRange.ScanRangeList(list).toFilterList());
  Table table = conn.getTable(
      relation.getIndexTableName(selectedRange.getFamily(), selectedRange.getQualifier()));
  scanner = table.getScanner(scan);
}
 
Example 11
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
@Test (timeout=300000)
public void testMinWithValidRangeWithNoCQ() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addFamily(TEST_FAMILY);
  scan.setStartRow(HConstants.EMPTY_START_ROW);
  scan.setStopRow(HConstants.EMPTY_END_ROW);
  final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
      new LongColumnInterpreter();
  long min = aClient.min(TEST_TABLE, ci,
      scan);
  assertEquals(0, min);
}
 
Example 12
Project: ditb   File: TestBigDecimalColumnInterpreter.java   Source Code and License Vote up 5 votes
@Test (timeout=300000)
public void testMinWithValidRangeWithNoCQ() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addFamily(TEST_FAMILY);
  scan.setStartRow(HConstants.EMPTY_START_ROW);
  scan.setStopRow(HConstants.EMPTY_END_ROW);
  final ColumnInterpreter<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
    new BigDecimalColumnInterpreter();
  BigDecimal min = aClient.min(TEST_TABLE, ci, scan);
  assertEquals(new BigDecimal("0.00"), min);
}
 
Example 13
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
@Test (timeout=300000)
public void testSumWithValidRange2WithNoCQ() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addFamily(TEST_FAMILY);
  scan.setStartRow(ROWS[6]);
  scan.setStopRow(ROWS[7]);
  final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
      new LongColumnInterpreter();
  long sum = aClient.sum(TEST_TABLE, ci, scan);
  assertEquals(6 + 60, sum);
}
 
Example 14
Project: ditb   File: MultiTableInputFormatTestBase.java   Source Code and License Vote up 5 votes
/**
 * Tests a MR scan using specific start and stop rows.
 *
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws InterruptedException
 */
private void testScan(String start, String stop, String last)
    throws IOException, InterruptedException, ClassNotFoundException {
  String jobName =
      "Scan" + (start != null ? start.toUpperCase() : "Empty") + "To" +
          (stop != null ? stop.toUpperCase() : "Empty");
  LOG.info("Before map/reduce startup - job " + jobName);
  Configuration c = new Configuration(TEST_UTIL.getConfiguration());

  c.set(KEY_STARTROW, start != null ? start : "");
  c.set(KEY_LASTROW, last != null ? last : "");

  List<Scan> scans = new ArrayList<Scan>();

  for (String tableName : TABLES) {
    Scan scan = new Scan();

    scan.addFamily(INPUT_FAMILY);
    scan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(tableName));

    if (start != null) {
      scan.setStartRow(Bytes.toBytes(start));
    }
    if (stop != null) {
      scan.setStopRow(Bytes.toBytes(stop));
    }

    scans.add(scan);

    LOG.info("scan before: " + scan);
  }

  runJob(jobName, c, scans);
}
 
Example 15
Project: ditb   File: TestTableInputFormatScanBase.java   Source Code and License Vote up 5 votes
/**
 * Tests a MR scan using specific start and stop rows.
 *
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws InterruptedException
 */
protected void testScan(String start, String stop, String last)
throws IOException, InterruptedException, ClassNotFoundException {
  String jobName = "Scan" + (start != null ? start.toUpperCase() : "Empty") +
    "To" + (stop != null ? stop.toUpperCase() : "Empty");
  LOG.info("Before map/reduce startup - job " + jobName);
  Configuration c = new Configuration(TEST_UTIL.getConfiguration());
  Scan scan = new Scan();
  scan.addFamily(INPUT_FAMILY);
  if (start != null) {
    scan.setStartRow(Bytes.toBytes(start));
  }
  c.set(KEY_STARTROW, start != null ? start : "");
  if (stop != null) {
    scan.setStopRow(Bytes.toBytes(stop));
  }
  c.set(KEY_LASTROW, last != null ? last : "");
  LOG.info("scan before: " + scan);
  Job job = new Job(c, jobName);
  TableMapReduceUtil.initTableMapperJob(
    Bytes.toString(TABLE_NAME), scan, ScanMapper.class,
    ImmutableBytesWritable.class, ImmutableBytesWritable.class, job);
  job.setReducerClass(ScanReducer.class);
  job.setNumReduceTasks(1); // one to get final "first" and "last" key
  FileOutputFormat.setOutputPath(job,
      new Path(TEST_UTIL.getDataTestDir(), job.getJobName()));
  LOG.info("Started " + job.getJobName());
  assertTrue(job.waitForCompletion(true));
  LOG.info("After map/reduce completion - job " + jobName);
}
 
Example 16
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test (timeout=300000)
public void testSumWithValidRange2() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
  scan.setStartRow(ROWS[5]);
  scan.setStopRow(ROWS[15]);
  final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
      new LongColumnInterpreter();
  long sum = aClient.sum(TEST_TABLE, ci, scan);
  assertEquals(95, sum);
}
 
Example 17
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 5 votes
@Test(timeout = 300000)
public void testAvgWithValidRange2WithNoCQ() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addFamily(TEST_FAMILY);
  scan.setStartRow(ROWS[6]);
  scan.setStopRow(ROWS[7]);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  double avg = aClient.avg(TEST_TABLE, ci, scan);
  assertEquals(6 + 0.60, avg, 0);
}
 
Example 18
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test(timeout = 300000)
public void testMinWithValidRange2() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  scan.setStartRow(ROWS[5]);
  scan.setStopRow(ROWS[15]);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  double min = aClient.min(TEST_TABLE, ci, scan);
  assertEquals(5.00, min, 0.00);
}
 
Example 19
Project: Transwarp-Sample-Code   File: DownloadData.java   Source Code and License Vote up 4 votes
/**
 * 获取文件
 * @param fileName 文件名
 */
public int getFile(String fileName) {
    try {
        HTable hTable = new HTable(configuration, constant.HBASE_TABLE_NAME);
        String fileName2 = fileName;
        if (System.getProperty("os.name").toLowerCase().contains("windows")) {
            fileName2 = constant.UPLOAD_DIR + "\\" + fileName;
            System.out.println(fileName2);
        } else {
            fileName2 = constant.UPLOAD_DIR + "/" + fileName;
        }
        String fileNameMD5 = md5crypt(fileName2);

        String result_filename;
        byte[] result_filedata;
        int result_fileCount=0;

        byte [] startRowKey = Bytes.toBytes(fileNameMD5);
        byte [] stopRowKey = Bytes.toBytes(fileNameMD5+"9");

        Scan scan = new Scan();
        scan.setStartRow(startRowKey);
        scan.setStopRow(stopRowKey);
        ResultScanner scanner = hTable.getScanner(scan);
        for (Result r : scanner) {
            result_filename = Bytes.toString(r.getValue(Bytes.toBytes("file"), Bytes.toBytes("filename")));
            System.out.println(result_filename);
            if (fileName2.compareTo(result_filename) == 0){
                result_fileCount++;
                result_filedata = r.getValue(Bytes.toBytes("data"), Bytes.toBytes("bytes"));
                FileUtil.byte2File(result_filedata, constant.DOWNLOAD_DIR, fileName);
            }
        }
        if (result_fileCount != 0)
            System.out.println("Download "+ result_fileCount + " files");
        else
            System.out.println("Not found:"+fileName);

        hTable.close();
        return result_fileCount;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
 
Example 20
Project: ditb   File: SyncTable.java   Source Code and License Vote up 4 votes
/**
 * 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);
}