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

The following are Jave code examples for showing how to use setStartRow() 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: TestAggregateProtocol.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<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
      new LongColumnInterpreter();
  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 2
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 3
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 4
Project: ditb   File: TestBigDecimalColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test (timeout=300000)
public void testMaxWithInvalidRange2() throws Throwable {
  BigDecimal max = new BigDecimal(Long.MIN_VALUE);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  scan.setStartRow(ROWS[4]);
  scan.setStopRow(ROWS[4]);
  try {
    AggregationClient aClient = new AggregationClient(conf);
    final ColumnInterpreter<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
      new BigDecimalColumnInterpreter();
    max = aClient.max(TEST_TABLE, ci, scan);
  } catch (Exception e) {
    max = BigDecimal.ZERO;
  }
  assertEquals(BigDecimal.ZERO, max);// control should go to the catch block
}
 
Example 5
Project: ditb   File: IntegrationTestBigLinkedList.java   Source Code and License Vote up 6 votes
private static CINode findStartNode(Table table, byte[] startKey) throws IOException {
  Scan scan = new Scan();
  scan.setStartRow(startKey);
  scan.setBatch(1);
  scan.addColumn(FAMILY_NAME, COLUMN_PREV);

  long t1 = System.currentTimeMillis();
  ResultScanner scanner = table.getScanner(scan);
  Result result = scanner.next();
  long t2 = System.currentTimeMillis();
  scanner.close();

  if ( result != null) {
    CINode node = getCINode(result, new CINode());
    System.out.printf("FSR %d %s\n", t2 - t1, Bytes.toStringBinary(node.key));
    return node;
  }

  System.out.println("FSR " + (t2 - t1));

  return null;
}
 
Example 6
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test (timeout=300000)
public void testMinWithValidRange() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  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(0l, min.longValue());
}
 
Example 7
Project: ditb   File: TestBigDecimalColumnInterpreter.java   Source Code and License Vote up 5 votes
@Test (timeout=300000)
public void testStdWithValidRange2WithNoCQ() 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<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
    new BigDecimalColumnInterpreter();
  double std = aClient.std(TEST_TABLE, ci, scan);
  System.out.println("std is:" + std);
  assertEquals(0, std, 0.05d);
}
 
Example 8
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 9
Project: ditb   File: TestBigDecimalColumnInterpreter.java   Source Code and License Vote up 5 votes
@Test (timeout=300000)
public void testMaxWithValidRange2WithNoCQ() 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<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
      new BigDecimalColumnInterpreter();
  BigDecimal max = aClient.max(TEST_TABLE, ci, scan);
  assertEquals(new BigDecimal("6.00"), max);
}
 
Example 10
Project: ditb   File: ThriftServerRunner.java   Source Code and License Vote up 5 votes
private Result getRowOrBefore(byte[] tableName, byte[] row, byte[] family) throws IOException {
  Scan scan = new Scan(row);
  scan.setReversed(true);
  scan.addFamily(family);
  scan.setStartRow(row);
  Table table = getTable(tableName);
  try (ResultScanner scanner = table.getScanner(scan)) {
    return scanner.next();
  } finally{
    if(table != null){
      table.close();
    }
  }
}
 
Example 11
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 5 votes
@Test(timeout = 300000)
public void testMaxWithValidRange2WithNoCQ() 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 max = aClient.max(TEST_TABLE, ci, scan);
  assertEquals(6.00, max, 0.00);
}
 
Example 12
Project: ditb   File: TestAggregateProtocol.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<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
      new LongColumnInterpreter();
  long min = aClient.min(TEST_TABLE, ci, scan);
  assertEquals(5, min);
}
 
Example 13
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test (timeout=300000)
public void testMaxWithValidRange2() 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 max = aClient.max(TEST_TABLE, ci, scan);
  assertEquals(14, max);
}
 
Example 14
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test (timeout=300000)
public void testAvgWithValidRange2() 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();
  double avg = aClient.avg(TEST_TABLE, ci, scan);
  assertEquals(9.5, avg, 0);
}
 
Example 15
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 5 votes
@Test(timeout = 300000)
public void testStdWithValidRange2WithNoCQ() 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 std = aClient.std(TEST_TABLE, ci, scan);
  System.out.println("std is:" + std);
  assertEquals(0, std, 0.05d);
}
 
Example 16
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
@Test (timeout=300000)
public void testMinWithValidRange2WithNoCQ() 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 min = aClient.min(TEST_TABLE, ci, scan);
  assertEquals(6, min);
}
 
Example 17
Project: ditb   File: UDGScanner.java   Source Code and License Vote up 5 votes
private GCScanner createGCScanner(ScanRange selectedRange) throws IOException {
  List<ScanRange> list = new ArrayList<>(rangeList.getRanges());
  list.remove(selectedRange);
  Scan scan = new Scan();
  scan.setStartRow(selectedRange.getStart());
  scan.setStopRow(selectedRange.getStop());
  scan.setCaching(rawScan.getCaching());
  scan.setCacheBlocks(rawScan.getCacheBlocks());
  scan.setFilter(new ScanRange.ScanRangeList(list).toFilterList());
  Table table = conn.getTable(
      relation.getIndexTableName(selectedRange.getFamily(), selectedRange.getQualifier()));
  ResultScanner scanner = table.getScanner(scan);
  return new GCScanner(this, scanner, selectedRange.getFamily(), selectedRange.getQualifier());
}
 
Example 18
Project: ditb   File: TestBigDecimalColumnInterpreter.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<BigDecimal, BigDecimal, EmptyMsg, BigDecimalMsg, BigDecimalMsg> ci =
    new BigDecimalColumnInterpreter();
  BigDecimal sum = aClient.sum(TEST_TABLE, ci, scan);
  assertEquals(new BigDecimal("95.00"), sum);
}
 
Example 19
Project: ditb   File: TestSeekOptimizations.java   Source Code and License Vote up 4 votes
private void testScan(final int[] columnArr, final boolean lazySeekEnabled,
    final int startRow, final int endRow, int maxVersions)
    throws IOException {
  StoreScanner.enableLazySeekGlobally(lazySeekEnabled);
  final Scan scan = new Scan();
  final Set<String> qualSet = new HashSet<String>();
  for (int iColumn : columnArr) {
    String qualStr = getQualStr(iColumn);
    scan.addColumn(FAMILY_BYTES, Bytes.toBytes(qualStr));
    qualSet.add(qualStr);
  }
  scan.setMaxVersions(maxVersions);
  scan.setStartRow(rowBytes(startRow));

  // Adjust for the fact that for multi-row queries the end row is exclusive.
  {
    final byte[] scannerStopRow =
        rowBytes(endRow + (startRow != endRow ? 1 : 0));
    scan.setStopRow(scannerStopRow);
  }

  final long initialSeekCount = StoreFileScanner.getSeekCount();
  final InternalScanner scanner = region.getScanner(scan);
  final List<Cell> results = new ArrayList<Cell>();
  final List<Cell> actualKVs = new ArrayList<Cell>();

  // Such a clumsy do-while loop appears to be the official way to use an
  // internalScanner. scanner.next() return value refers to the _next_
  // result, not to the one already returned in results.
  boolean hasNext;
  do {
    hasNext = scanner.next(results);
    actualKVs.addAll(results);
    results.clear();
  } while (hasNext);

  List<Cell> filteredKVs = filterExpectedResults(qualSet,
      rowBytes(startRow), rowBytes(endRow), maxVersions);
  final String rowRestrictionStr =
      (startRow == -1 && endRow == -1) ? "all rows" : (
          startRow == endRow ? ("row=" + startRow) : ("startRow="
          + startRow + ", " + "endRow=" + endRow));
  final String columnRestrictionStr =
      columnArr.length == 0 ? "all columns"
          : ("columns=" + Arrays.toString(columnArr));
  final String testDesc =
      "Bloom=" + bloomType + ", compr=" + comprAlgo + ", "
          + (scan.isGetScan() ? "Get" : "Scan") + ": "
          + columnRestrictionStr + ", " + rowRestrictionStr
          + ", maxVersions=" + maxVersions + ", lazySeek=" + lazySeekEnabled;
  long seekCount = StoreFileScanner.getSeekCount() - initialSeekCount;
  if (VERBOSE) {
    System.err.println("Seek count: " + seekCount + ", KVs returned: "
      + actualKVs.size() + ". " + testDesc +
      (lazySeekEnabled ? "\n" : ""));
  }
  if (lazySeekEnabled) {
    totalSeekLazy += seekCount;
  } else {
    totalSeekDiligent += seekCount;
  }
  assertKVListsEqual(testDesc, filteredKVs, actualKVs);
}
 
Example 20
Project: ditb   File: IntegrationTestBigLinkedList.java   Source Code and License Vote up 4 votes
@Override
public int run(String[] args) throws Exception {
  Options options = new Options();
  options.addOption("s", "start", true, "start key");
  options.addOption("e", "end", true, "end key");
  options.addOption("l", "limit", true, "number to print");

  GnuParser parser = new GnuParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
    if (cmd.getArgs().length != 0) {
      throw new ParseException("Command takes no arguments");
    }
  } catch (ParseException e) {
    System.err.println("Failed to parse command line " + e.getMessage());
    System.err.println();
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(getClass().getSimpleName(), options);
    System.exit(-1);
  }

  Table table = new HTable(getConf(), getTableName(getConf()));

  Scan scan = new Scan();
  scan.setBatch(10000);

  if (cmd.hasOption("s"))
    scan.setStartRow(Bytes.toBytesBinary(cmd.getOptionValue("s")));

  if (cmd.hasOption("e"))
    scan.setStopRow(Bytes.toBytesBinary(cmd.getOptionValue("e")));

  int limit = 0;
  if (cmd.hasOption("l"))
    limit = Integer.parseInt(cmd.getOptionValue("l"));
  else
    limit = 100;

  ResultScanner scanner = table.getScanner(scan);

  CINode node = new CINode();
  Result result = scanner.next();
  int count = 0;
  while (result != null && count++ < limit) {
    node = getCINode(result, node);
    System.out.printf("%s:%s:%012d:%s\n", Bytes.toStringBinary(node.key),
        Bytes.toStringBinary(node.prev), node.count, node.client);
    result = scanner.next();
  }
  scanner.close();
  table.close();

  return 0;
}