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

The following are Jave code examples for showing how to use addColumn() 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: PerformanceEvaluation.java   Source Code and License Vote up 7 votes
@Override
void testRow(final int i) throws IOException {
  Scan scan = new Scan(getRandomRow(this.rand, opts.totalRows));
  scan.setCaching(opts.caching);
  FilterList list = new FilterList();
  if (opts.addColumns) {
    scan.addColumn(FAMILY_NAME, QUALIFIER_NAME);
  } else {
    scan.addFamily(FAMILY_NAME);
  }
  if (opts.filterAll) {
    list.addFilter(new FilterAllFilter());
  }
  list.addFilter(new WhileMatchFilter(new PageFilter(120)));
  scan.setFilter(list);
  ResultScanner s = this.table.getScanner(scan);
  for (Result rr; (rr = s.next()) != null;) {
    updateValueSize(rr);
  }
  s.close();
}
 
Example 2
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 3
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 4
Project: ditb   File: PerformanceEvaluation.java   Source Code and License Vote up 6 votes
protected Scan constructScan(byte[] valuePrefix) throws IOException {
  FilterList list = new FilterList();
  Filter filter = new SingleColumnValueFilter(
      FAMILY_NAME, COLUMN_ZERO, CompareFilter.CompareOp.EQUAL,
      new BinaryComparator(valuePrefix)
  );
  list.addFilter(filter);
  if(opts.filterAll) {
    list.addFilter(new FilterAllFilter());
  }
  Scan scan = new Scan();
  scan.setCaching(opts.caching);
  if (opts.addColumns) {
    scan.addColumn(FAMILY_NAME, QUALIFIER_NAME);
  } else {
    scan.addFamily(FAMILY_NAME);
  }
  scan.setFilter(list);
  return scan;
}
 
Example 5
Project: ditb   File: TestKeepDeletes.java   Source Code and License Vote up 6 votes
/**
 * The ExplicitColumnTracker does not support "raw" scanning.
 */
@Test
public void testRawScanWithColumns() throws Exception {
  HTableDescriptor htd = hbu.createTableDescriptor(name.getMethodName(), 0, 3,
      HConstants.FOREVER, KeepDeletedCells.TRUE);
  HRegion region = hbu.createLocalHRegion(htd, null, null);

  Scan s = new Scan();
  s.setRaw(true);
  s.setMaxVersions();
  s.addColumn(c0, c0);

  try {
    region.getScanner(s);
    fail("raw scanner with columns should have failed");
  } catch (org.apache.hadoop.hbase.DoNotRetryIOException dnre) {
    // ok!
  }

  HRegion.closeHRegion(region);
}
 
Example 6
Project: ditb   File: PerformanceEvaluation.java   Source Code and License Vote up 6 votes
@Override
void testRow(final int i) throws IOException {
  Pair<byte[], byte[]> startAndStopRow = getStartAndStopRow();
  Scan scan = new Scan(startAndStopRow.getFirst(), startAndStopRow.getSecond());
  scan.addColumn(FAMILY_NAME, QUALIFIER_NAME);
  ResultScanner s = this.table.getScanner(scan);
  int count = 0;
  for (Result rr = null; (rr = s.next()) != null;) {
    count++;
  }

  if (i % 100 == 0) {
    LOG.info(String.format("Scan for key range %s - %s returned %s rows",
        Bytes.toString(startAndStopRow.getFirst()),
        Bytes.toString(startAndStopRow.getSecond()), count));
  }

  s.close();
}
 
Example 7
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 6 votes
@Test(timeout = 300000)
public void testMaxWithInvalidRange2() throws Throwable {
  double max = Double.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<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
        new DoubleColumnInterpreter();
    max = aClient.max(TEST_TABLE, ci, scan);
  } catch (Exception e) {
    max = 0.00;
  }
  assertEquals(0.00, max, 0.00);// control should go to the catch block
}
 
Example 8
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test(timeout = 300000)
public void testStdWithValidRange() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  double std = aClient.std(TEST_TABLE, ci, scan);
  assertEquals(5.766, std, 0.05d);
}
 
Example 9
Project: easyhbase   File: HbaseTemplate2.java   Source Code and License Vote up 5 votes
@Override
public <T> T find(TableName tableName, String family, String qualifier, final
ResultsExtractor<T> action) {
    Scan scan = new Scan();
    scan.addColumn(family.getBytes(getCharset()), qualifier.getBytes(getCharset()));
    return find(tableName, scan, action);
}
 
Example 10
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test (timeout=300000)
public void testMedianWithValidRange() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
  final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci = 
      new LongColumnInterpreter();
  long median = aClient.median(TEST_TABLE, ci,
      scan);
  assertEquals(8L, median);
}
 
Example 11
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 5 votes
@Test(timeout = 300000)
public void testAvgWithFilter() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
  scan.setFilter(f);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  Double avg = null;
  avg = aClient.avg(TEST_TABLE, ci, scan);
  assertEquals(Double.NaN, avg, 0);
}
 
Example 12
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test (timeout=300000)
public void testSumWithValidRange() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
  final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
      new LongColumnInterpreter();
  long sum = aClient.sum(TEST_TABLE, ci,
      scan);
  assertEquals(190, sum);
}
 
Example 13
Project: ditb   File: TestAggregateProtocol.java   Source Code and License Vote up 5 votes
/**
 * give max for the entire table.
 * @throws Throwable
 */
@Test (timeout=300000)
public void testMaxWithValidRange() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
      new LongColumnInterpreter();
  long maximum = aClient.max(TEST_TABLE, ci, scan);
  assertEquals(19, maximum);
}
 
Example 14
Project: ditb   File: ThriftServerRunner.java   Source Code and License Vote up 5 votes
@Override
public int scannerOpen(ByteBuffer tableName, ByteBuffer startRow,
    List<ByteBuffer> columns,
    Map<ByteBuffer, ByteBuffer> attributes) throws IOError {

  Table table = null;
  try {
    table = getTable(tableName);
    Scan scan = new Scan(getBytes(startRow));
    addAttributes(scan, attributes);
    if(columns != null && columns.size() != 0) {
      for(ByteBuffer column : columns) {
        byte [][] famQf = KeyValue.parseColumn(getBytes(column));
        if(famQf.length == 1) {
          scan.addFamily(famQf[0]);
        } else {
          scan.addColumn(famQf[0], famQf[1]);
        }
      }
    }
    return addScanner(table.getScanner(scan), false);
  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw new IOError(Throwables.getStackTraceAsString(e));
  } finally{
    closeTable(table);
  }
}
 
Example 15
Project: ditb   File: ThriftServerRunner.java   Source Code and License Vote up 5 votes
@Override
public int scannerOpenWithStop(ByteBuffer tableName, ByteBuffer startRow,
    ByteBuffer stopRow, List<ByteBuffer> columns,
    Map<ByteBuffer, ByteBuffer> attributes)
    throws IOError, TException {

  Table table = null;
  try {
    table = getTable(tableName);
    Scan scan = new Scan(getBytes(startRow), getBytes(stopRow));
    addAttributes(scan, attributes);
    if(columns != null && columns.size() != 0) {
      for(ByteBuffer column : columns) {
        byte [][] famQf = KeyValue.parseColumn(getBytes(column));
        if(famQf.length == 1) {
          scan.addFamily(famQf[0]);
        } else {
          scan.addColumn(famQf[0], famQf[1]);
        }
      }
    }
    return addScanner(table.getScanner(scan), false);
  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw new IOError(Throwables.getStackTraceAsString(e));
  } finally{
    closeTable(table);
  }
}
 
Example 16
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 5 votes
@Test(timeout = 300000)
public void testMaxWithFilter() throws Throwable {
  Double max = 0.00d;
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
  scan.setFilter(f);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  max = aClient.max(TEST_TABLE, ci, scan);
  assertEquals(null, max);
}
 
Example 17
Project: ditb   File: PerformanceEvaluation.java   Source Code and License Vote up 5 votes
@Override
void testRow(final int i) throws IOException {
  if (this.testScanner == null) {
    Scan scan = new Scan(format(this.startRow));
    scan.addColumn(FAMILY_NAME, QUALIFIER_NAME);
    this.testScanner = table.getScanner(scan);
  }
  testScanner.next();
}
 
Example 18
Project: ditb   File: TestDoubleColumnInterpreter.java   Source Code and License Vote up 5 votes
/**
 * @throws Throwable
 */
@Test(timeout = 300000)
public void testSumWithValidRange() throws Throwable {
  AggregationClient aClient = new AggregationClient(conf);
  Scan scan = new Scan();
  scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
  final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
      new DoubleColumnInterpreter();
  double sum = aClient.sum(TEST_TABLE, ci, scan);
  assertEquals(190.00, sum, 0.00);
}
 
Example 19
Project: ditb   File: TestSCVFWithMiniCluster.java   Source Code and License Vote up 5 votes
/**
 * Test the filter by adding 1 column of family A (the one used in the filter) and 1 column of
 * family B in the scan. (OK)
 */
@Test
public void scanWithSpecificQualifiers2() throws IOException {
  /* When */
  Scan scan = new Scan();
  scan.addColumn(FAMILY_A, QUALIFIER_FOO);
  scan.addColumn(FAMILY_B, QUALIFIER_BAR);
  scan.setFilter(scanFilter);

  verify(scan);
}
 
Example 20
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);
}