org.apache.hadoop.hbase.client.ResultScanner Java Examples

The following examples show how to use org.apache.hadoop.hbase.client.ResultScanner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleEnrichmentFlatFileLoaderIntegrationTest.java    From metron with Apache License 2.0 6 votes vote down vote up
@Test
public void testLocalLineByLine() throws Exception {
  String[] argv = {"-c cf", "-t enrichment"
          , "-e " + lineByLineExtractorConfigFile.getPath()
          , "-i " + multilineFile.getPath()
          , "-p 2", "-b 128", "-q"
  };
  SimpleEnrichmentFlatFileLoader.main(config, argv);
  EnrichmentConverter converter = new EnrichmentConverter();
  ResultScanner scanner = testTable.getScanner(Bytes.toBytes(cf));
  List<LookupKV<EnrichmentKey, EnrichmentValue>> results = new ArrayList<>();
  for (Result r : scanner) {
    results.add(converter.fromResult(r, cf));
    testTable.delete(new Delete(r.getRow()));
  }
  assertEquals(NUM_LINES, results.size());
  assertTrue(results.get(0).getKey().indicator.startsWith("google"));
  assertEquals(results.get(0).getKey().type, "enrichment");
  assertEquals(results.get(0).getValue().getMetadata().size(), 2);
  assertTrue(results.get(0).getValue().getMetadata().get("meta").toString().startsWith("foo"));
  assertTrue(results.get(0).getValue().getMetadata().get("host").toString().startsWith("google"));
}
 
Example #2
Source File: TestUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public static void dumpIndexStatus(Connection conn, String indexName) throws IOException, SQLException {
    try (Table table = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES)) { 
        System.out.println("************ dumping index status for " + indexName + " **************");
        Scan s = new Scan();
        s.setRaw(true);
        s.setMaxVersions();
        byte[] startRow = SchemaUtil.getTableKeyFromFullName(indexName);
        s.setStartRow(startRow);
        s.setStopRow(ByteUtil.nextKey(ByteUtil.concat(startRow, QueryConstants.SEPARATOR_BYTE_ARRAY)));
        try (ResultScanner scanner = table.getScanner(s)) {
            Result result = null;
            while ((result = scanner.next()) != null) {
                CellScanner cellScanner = result.cellScanner();
                Cell current = null;
                while (cellScanner.advance()) {
                    current = cellScanner.current();
                    if (Bytes.compareTo(current.getQualifierArray(), current.getQualifierOffset(), current.getQualifierLength(), PhoenixDatabaseMetaData.INDEX_STATE_BYTES, 0, PhoenixDatabaseMetaData.INDEX_STATE_BYTES.length) == 0) {
                        System.out.println(current.getTimestamp() + "/INDEX_STATE=" + PIndexState.fromSerializedValue(current.getValueArray()[current.getValueOffset()]));
                    }
                }
            }
        }
        System.out.println("-----------------------------------------------");
}
}
 
Example #3
Source File: Reads.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void readRowRange(String projectId, String instanceId, String tableId) {
  // Initialize client that will be used to send requests. This client only needs to be created
  // once, and can be reused for multiple requests. After completing all of your requests, call
  // the "close" method on the client to safely clean up any remaining background resources.
  try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) {
    Table table = connection.getTable(TableName.valueOf(tableId));

    Scan rangeQuery =
        new Scan()
            .withStartRow(Bytes.toBytes("phone#4c410523#20190501"))
            .withStopRow(Bytes.toBytes("phone#4c410523#201906201"));

    ResultScanner rows = table.getScanner(rangeQuery);

    for (Result row : rows) {
      printRow(row);
    }

  } catch (IOException e) {
    System.out.println(
        "Unable to initialize service client, as a network error occurred: \n" + e.toString());
  }
}
 
Example #4
Source File: TestRegionObserverInterface.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testHBASE14489() throws IOException {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  Table table = util.createTable(tableName, new byte[][] { A });
  Put put = new Put(ROW);
  put.addColumn(A, A, A);
  table.put(put);

  Scan s = new Scan();
  s.setFilter(new FilterAllFilter());
  ResultScanner scanner = table.getScanner(s);
  try {
    for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
    }
  } finally {
    scanner.close();
  }
  verifyMethodResult(SimpleRegionObserver.class, new String[] { "wasScannerFilterRowCalled" },
    tableName, new Boolean[] { true });
  util.deleteTable(tableName);
  table.close();

}
 
Example #5
Source File: TestDeleteMobTable.java    From hbase with Apache License 2.0 6 votes vote down vote up
private String assertHasOneMobRow(Table table, TableName tn, String familyName)
    throws IOException {
  Scan scan = new Scan();
  scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE));
  ResultScanner rs = table.getScanner(scan);
  Result r = rs.next();
  Assert.assertNotNull(r);
  String fileName = MobUtils.getMobFileName(r.getColumnLatestCell(FAMILY, QF));
  Path filePath = new Path(
      MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tn, familyName), fileName);
  FileSystem fs = TEST_UTIL.getTestFileSystem();
  Assert.assertTrue(fs.exists(filePath));
  r = rs.next();
  Assert.assertNull(r);
  return fileName;
}
 
Example #6
Source File: IntegrationTestMobCompaction.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void scanTable() {
  try {

    Result result;
    ResultScanner scanner = table.getScanner(fam);
    int counter = 0;
    while ((result = scanner.next()) != null) {
      assertTrue(Arrays.equals(result.getValue(fam, qualifier), mobVal));
      if (counter % 10000 == 0) {
        LOG.info("GET=" + counter);
      }
      counter++;
    }
    assertEquals(rowsToLoad, counter);
  } catch (Exception e) {
    e.printStackTrace();
    LOG.error("MOB Stress Test FAILED");
    if (util != null) {
      assertTrue(false);
    } else {
      System.exit(-1);
    }
  }
}
 
Example #7
Source File: TestVisibilityLabels.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleVisibilityLabels() throws Exception {
  TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CONFIDENTIAL,
      PRIVATE + "|" + CONFIDENTIAL)) {
    Scan s = new Scan();
    s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE));
    ResultScanner scanner = table.getScanner(s);
    Result[] next = scanner.next(3);

    assertTrue(next.length == 2);
    CellScanner cellScanner = next[0].cellScanner();
    cellScanner.advance();
    Cell current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
        current.getRowLength(), row1, 0, row1.length));
    cellScanner = next[1].cellScanner();
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
        current.getRowLength(), row2, 0, row2.length));
  }
}
 
Example #8
Source File: HBaseConnectionTest.java    From aws-athena-query-federation with Apache License 2.0 6 votes vote down vote up
@Test
public void scanTable()
        throws IOException
{
    logger.info("scanTable: enter");
    when(mockConnection.getTable(any(org.apache.hadoop.hbase.TableName.class))).thenReturn(mockTable);
    when(mockTable.getScanner(any(Scan.class))).thenReturn(mockScanner);

    TableName tableName = org.apache.hadoop.hbase.TableName.valueOf("schema1", "table1");
    boolean result = connection.scanTable(tableName, mock(Scan.class), (ResultScanner scanner) -> scanner != null);

    assertTrue(result);
    assertTrue(connection.isHealthy());
    assertEquals(0, connection.getRetries());
    verify(mockConnection, atLeastOnce()).getTable(anyObject());
    verify(mockTable, atLeastOnce()).getScanner(any(Scan.class));
    logger.info("scanTable: exit");
}
 
Example #9
Source File: GridTableHBaseBenchmark.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private static void fullScan(Connection conn, boolean[] hits, Stats stats) throws IOException {
    Table table = conn.getTable(TableName.valueOf(TEST_TABLE));
    try {
        stats.markStart();

        Scan scan = new Scan();
        scan.addFamily(CF);
        ResultScanner scanner = table.getScanner(scan);
        int i = 0;
        for (Result r : scanner) {
            if (hits[i])
                stats.consume(r);
            dot(i, N_ROWS);
            i++;
        }

        stats.markEnd();
    } finally {
        IOUtils.closeQuietly(table);
    }
}
 
Example #10
Source File: DataJanitorState.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
/**
 * Return regions that were recorded as empty after the given time.
 *
 * @param time time in milliseconds
 * @param includeRegions If not null, the returned set will be an intersection of the includeRegions set
 *                       and the empty regions after the given time
 */
public SortedSet<byte[]> getEmptyRegionsAfterTime(long time, @Nullable SortedSet<byte[]> includeRegions)
  throws IOException {
  SortedSet<byte[]> emptyRegions = new TreeSet<>(Bytes.BYTES_COMPARATOR);
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    Scan scan = new Scan(makeEmptyRegionTimeKey(Bytes.toBytes(time + 1), EMPTY_BYTE_ARRAY),
                         EMPTY_REGION_TIME_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, EMPTY_REGION_TIME_COL);

    try (ResultScanner scanner = stateTable.getScanner(scan)) {
      Result next;
      while ((next = scanner.next()) != null) {
        byte[] emptyRegion = getEmptyRegionFromKey(next.getRow());
        if (includeRegions == null || includeRegions.contains(emptyRegion)) {
          emptyRegions.add(emptyRegion);
        }
      }
    }
  }
  return Collections.unmodifiableSortedSet(emptyRegions);
}
 
Example #11
Source File: AclTableMigrationTool.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void convertToResourceStore(KylinConfig kylinConfig, String tableName, ResourceStore store,
        ResultConverter converter) throws IOException {

    Table table = null;
    ResultScanner rs = null;
    Scan scan = new Scan();
    try {
        table = HBaseConnection.get(kylinConfig.getStorageUrl()).getTable(TableName.valueOf(tableName));
        rs = table.getScanner(scan);
        converter.convertResult(rs, store);
        store.checkAndPutResource(MIGRATE_OK_PREFIX + tableName, new StringEntity(tableName + " migrated"),
                StringEntity.serializer);
    } finally {
        IOUtils.closeQuietly(rs);
        IOUtils.closeQuietly(table);
    }

}
 
Example #12
Source File: TestVisibilityLabelsWithACL.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testScanForSuperUserWithFewerLabelAuths() throws Throwable {
  String[] auths = { SECRET };
  String user = "admin";
  try (Connection conn = ConnectionFactory.createConnection(conf)) {
    VisibilityClient.setAuths(conn, auths, user);
  }
  TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
      + "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
  PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      Scan s = new Scan();
      s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
      try (Connection connection = ConnectionFactory.createConnection(conf);
           Table t = connection.getTable(table.getName())) {
        ResultScanner scanner = t.getScanner(s);
        Result[] result = scanner.next(5);
        assertTrue(result.length == 2);
      }
      return null;
    }
  };
  SUPERUSER.runAs(scanAction);
}
 
Example #13
Source File: HBaseFilterTest.java    From BigData-In-Practice with Apache License 2.0 6 votes vote down vote up
@Test
public void columnPrefixFilterTest() {
    Filter filter = new ColumnPrefixFilter(Bytes.toBytes("nam"));
    FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL, Arrays.asList(filter));
    ResultScanner scanner = HBaseUtil
            .getScanner("FileTable", "rowkey1", "rowkey3", filterList);

    if (scanner != null) {
        scanner.forEach(result -> {
            System.out.println("rowkey=" + Bytes.toString(result.getRow()));
            System.out.println("fileName=" + Bytes
                    .toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("name"))));
            System.out.println("fileType=" + Bytes
                    .toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("type"))));
        });
        scanner.close();
    }
}
 
Example #14
Source File: HbaseRecordHandler.java    From aws-athena-query-federation with Apache License 2.0 6 votes vote down vote up
private boolean scanFilterProject(ResultScanner scanner, ReadRecordsRequest request, BlockSpiller blockSpiller, QueryStatusChecker queryStatusChecker)
{
    Schema projection = request.getSchema();
    boolean isNative = projection.getCustomMetadata().get(HBASE_NATIVE_STORAGE_FLAG) != null;

    for (Result row : scanner) {
        if (!queryStatusChecker.isQueryRunning()) {
            return true;
        }
        blockSpiller.writeRows((Block block, int rowNum) -> {
            boolean match = true;
            for (Field field : projection.getFields()) {
                if (match) {
                    match &= writeField(block, field, isNative, row, rowNum);
                }
            }
            return match ? 1 : 0;
        });
    }
    return true;
}
 
Example #15
Source File: SimpleEnrichmentFlatFileLoaderIntegrationTest.java    From metron with Apache License 2.0 6 votes vote down vote up
@Test
public void testMRLineByLine() throws Exception {
  String[] argv = {"-c cf", "-t enrichment"
          , "-e " + lineByLineExtractorConfigFile.getPath()
          , "-i " + multilineFile.getName()
          , "-m MR"
          , "-p 2", "-b 128", "-q"
  };
  FileSystem fs = FileSystem.get(config);
  HBaseUtil.INSTANCE.writeFile(new String(Files.readAllBytes(multilineFile.toPath()),
      StandardCharsets.UTF_8), new Path(multilineFile.getName()), fs);
  SimpleEnrichmentFlatFileLoader.main(config, argv);
  EnrichmentConverter converter = new EnrichmentConverter();
  ResultScanner scanner = testTable.getScanner(Bytes.toBytes(cf));
  List<LookupKV<EnrichmentKey, EnrichmentValue>> results = new ArrayList<>();
  for (Result r : scanner) {
    results.add(converter.fromResult(r, cf));
    testTable.delete(new Delete(r.getRow()));
  }
  assertEquals(NUM_LINES, results.size());
  assertTrue(results.get(0).getKey().indicator.startsWith("google"));
  assertEquals(results.get(0).getKey().type, "enrichment");
  assertEquals(results.get(0).getValue().getMetadata().size(), 2);
  assertTrue(results.get(0).getValue().getMetadata().get("meta").toString().startsWith("foo"));
  assertTrue(results.get(0).getValue().getMetadata().get("host").toString().startsWith("google"));
}
 
Example #16
Source File: TestFsRegionsMetaRecoverer.java    From hbase-operator-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveRegionInfoFromMeta() throws Exception {
  ResultScanner mockedRsTables = Mockito.mock(ResultScanner.class);
  List<Cell> cells = new ArrayList<>();
  cells.add(createCellForTableState(TableName.valueOf("test-tbl")));
  Result result = Result.create(cells);
  ResultScanner mockedRsRegions = Mockito.mock(ResultScanner.class);
  createRegionInMeta(mockedRsRegions);
  when(this.mockedTable.getScanner(any(Scan.class))).
    thenReturn(mockedRsTables).
      thenReturn(mockedRsRegions);
  when(mockedRsTables.next()).thenReturn(result,(Result)null);
  List<String> tableList = new ArrayList<>();
  tableList.add("default:test-tbl");
  fixer.removeExtraRegionsFromMetaForTables(tableList);
  Mockito.verify(this.mockedTable).delete(anyList());
}
 
Example #17
Source File: TestSpaceQuotaViolationPolicyRefresherChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testParsingError() throws IOException {
  when(chore.fetchSnapshotsFromQuotaTable()).thenCallRealMethod();
  ResultScanner scanner = mock(ResultScanner.class);
  Table quotaTable = mock(Table.class);
  when(conn.getTable(QuotaUtil.QUOTA_TABLE_NAME)).thenReturn(quotaTable);
  when(quotaTable.getScanner(any(Scan.class))).thenReturn(scanner);

  List<Result> results = new ArrayList<>();
  Cell c = new KeyValue(toBytes("t:inviolation"), toBytes("u"), toBytes("v"), new byte[0]);
  results.add(Result.create(Collections.singletonList(c)));
  when(scanner.iterator()).thenReturn(results.iterator());
  try {
    chore.fetchSnapshotsFromQuotaTable();
    fail("Expected an IOException, but did not receive one.");
  } catch (IOException e) {
    // We provided a garbage serialized protobuf message (empty byte array), this should
    // in turn throw an IOException
  }
}
 
Example #18
Source File: TestMultiRowRangeFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
private List<Cell> getScanResult(byte[] startRow, byte[] stopRow, Table ht) throws IOException {
  Scan scan = new Scan();
  scan.readAllVersions();
  if(!Bytes.toString(startRow).isEmpty()) {
    scan.withStartRow(startRow);
  }
  if(!Bytes.toString(stopRow).isEmpty()) {
    scan.withStopRow(stopRow);
  }
  ResultScanner scanner = ht.getScanner(scan);
  List<Cell> kvList = new ArrayList<>();
  Result r;
  while ((r = scanner.next()) != null) {
    for (Cell kv : r.listCells()) {
      kvList.add(kv);
    }
  }
  scanner.close();
  return kvList;
}
 
Example #19
Source File: TransactionAwareHTableTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckpointRollback() throws Exception {
  // start a transaction, using checkpoints between writes
  transactionContext.start();
  transactionAwareHTable.put(new Put(TestBytes.row).add(TestBytes.family, TestBytes.qualifier, TestBytes.value));
  transactionContext.checkpoint();
  transactionAwareHTable.put(new Put(TestBytes.row2).add(TestBytes.family, TestBytes.qualifier, TestBytes.value2));
  transactionContext.checkpoint();
  transactionAwareHTable.put(new Put(TestBytes.row3).add(TestBytes.family, TestBytes.qualifier, TestBytes.value));

  transactionContext.abort();

  transactionContext.start();
  verifyRow(transactionAwareHTable, TestBytes.row, null);
  verifyRow(transactionAwareHTable, TestBytes.row2, null);
  verifyRow(transactionAwareHTable, TestBytes.row3, null);

  Scan scan = new Scan();
  ResultScanner scanner = transactionAwareHTable.getScanner(scan);
  assertNull(scanner.next());
  scanner.close();
  transactionContext.finish();
}
 
Example #20
Source File: TestJoinedScanners.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void runScanner(Table table, boolean slow) throws Exception {
  long time = System.nanoTime();
  Scan scan = new Scan();
  scan.addColumn(cf_essential, col_name);
  scan.addColumn(cf_joined, col_name);

  SingleColumnValueFilter filter = new SingleColumnValueFilter(
      cf_essential, col_name, CompareOperator.EQUAL, flag_yes);
  filter.setFilterIfMissing(true);
  scan.setFilter(filter);
  scan.setLoadColumnFamiliesOnDemand(!slow);

  ResultScanner result_scanner = table.getScanner(scan);
  Result res;
  long rows_count = 0;
  while ((res = result_scanner.next()) != null) {
    rows_count++;
  }

  double timeSec = (System.nanoTime() - time) / 1000000000.0;
  result_scanner.close();
  LOG.info((slow ? "Slow" : "Joined") + " scanner finished in " + Double.toString(timeSec)
    + " seconds, got " + Long.toString(rows_count/2) + " rows");
}
 
Example #21
Source File: TestSCVFWithMiniCluster.java    From hbase with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #22
Source File: TestScanRowPrefix.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void verifyScanResult(Table table, Scan scan, List<byte[]> expectedKeys, String message) {
  List<byte[]> actualKeys = new ArrayList<>();
  try {
    ResultScanner scanner = table.getScanner(scan);
    for (Result result : scanner) {
      actualKeys.add(result.getRow());
    }

    String fullMessage = message;
    if (LOG.isDebugEnabled()) {
      fullMessage = message + "\n" + tableOfTwoListsOfByteArrays(
              "Expected", expectedKeys,
              "Actual  ", actualKeys);
    }

    Assert.assertArrayEquals(
            fullMessage,
            expectedKeys.toArray(),
            actualKeys.toArray());
  } catch (IOException e) {
    e.printStackTrace();
    Assert.fail();
  }
}
 
Example #23
Source File: TransactionAwareHTableTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckpointRollback() throws Exception {
  // start a transaction, using checkpoints between writes
  transactionContext.start();
  transactionAwareHTable.put(new Put(TestBytes.row).add(TestBytes.family, TestBytes.qualifier, TestBytes.value));
  transactionContext.checkpoint();
  transactionAwareHTable.put(new Put(TestBytes.row2).add(TestBytes.family, TestBytes.qualifier, TestBytes.value2));
  transactionContext.checkpoint();
  transactionAwareHTable.put(new Put(TestBytes.row3).add(TestBytes.family, TestBytes.qualifier, TestBytes.value));

  transactionContext.abort();

  transactionContext.start();
  verifyRow(transactionAwareHTable, TestBytes.row, null);
  verifyRow(transactionAwareHTable, TestBytes.row2, null);
  verifyRow(transactionAwareHTable, TestBytes.row3, null);

  Scan scan = new Scan();
  ResultScanner scanner = transactionAwareHTable.getScanner(scan);
  assertNull(scanner.next());
  scanner.close();
  transactionContext.finish();
}
 
Example #24
Source File: DataJanitorState.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
/**
 * Return regions that were recorded as empty after the given time.
 *
 * @param time time in milliseconds
 * @param includeRegions If not null, the returned set will be an intersection of the includeRegions set
 *                       and the empty regions after the given time
 */
public SortedSet<byte[]> getEmptyRegionsAfterTime(long time, @Nullable SortedSet<byte[]> includeRegions)
  throws IOException {
  SortedSet<byte[]> emptyRegions = new TreeSet<>(Bytes.BYTES_COMPARATOR);
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    Scan scan = new Scan(makeEmptyRegionTimeKey(Bytes.toBytes(time + 1), EMPTY_BYTE_ARRAY),
                         EMPTY_REGION_TIME_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, EMPTY_REGION_TIME_COL);

    try (ResultScanner scanner = stateTable.getScanner(scan)) {
      Result next;
      while ((next = scanner.next()) != null) {
        byte[] emptyRegion = getEmptyRegionFromKey(next.getRow());
        if (includeRegions == null || includeRegions.contains(emptyRegion)) {
          emptyRegions.add(emptyRegion);
        }
      }
    }
  }
  return Collections.unmodifiableSortedSet(emptyRegions);
}
 
Example #25
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public ResultScanner getScanner(Scan scan) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  return hTable.getScanner(transactionalizeAction(scan));
}
 
Example #26
Source File: TestHBaseStorage.java    From spork with Apache License 2.0 5 votes vote down vote up
private void deleteAllRows(String tableName) throws Exception {
    HTable table = new HTable(conf, tableName);
    ResultScanner scanner = table.getScanner(new Scan());
    List<Delete> deletes = Lists.newArrayList();
    for (Result row : scanner) {
        deletes.add(new Delete(row.getRow()));
    }
    table.delete(deletes);
    table.close();
}
 
Example #27
Source File: TestMobStoreScanner.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void testGetReferences(boolean reversed) throws Exception {
  TableName tn = TableName.valueOf("testGetReferences" + reversed);
  setUp(defaultThreshold, tn);
  long ts1 = System.currentTimeMillis();
  long ts2 = ts1 + 1;
  long ts3 = ts1 + 2;
  byte [] value = generateMobValue((int)defaultThreshold+1);

  Put put1 = new Put(row1);
  put1.addColumn(family, qf1, ts3, value);
  put1.addColumn(family, qf2, ts2, value);
  put1.addColumn(family, qf3, ts1, value);
  table.put(put1);

  admin.flush(tn);

  Scan scan = new Scan();
  setScan(scan, reversed, true);

  ResultScanner results = table.getScanner(scan);
  int count = 0;
  for (Result res : results) {
    List<Cell> cells = res.listCells();
    for(Cell cell : cells) {
      // Verify the value
      assertIsMobReference(cell, row1, family, value, tn);
      count++;
    }
  }
  results.close();
  Assert.assertEquals(3, count);
}
 
Example #28
Source File: TestQuotaTableUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerDeViolationPolicies() throws Exception {
  final TableName tn1 = getUniqueTableName();
  final SpaceQuotaSnapshot snapshot1 = new SpaceQuotaSnapshot(
      new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 512L, 1024L);
  final TableName tn2 = getUniqueTableName();
  final SpaceQuotaSnapshot snapshot2 = new SpaceQuotaSnapshot(
      new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 512L, 1024L);
  final TableName tn3 = getUniqueTableName();
  final SpaceQuotaSnapshot snapshot3 = new SpaceQuotaSnapshot(
      new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 512L, 1024L);
  List<Put> puts = new ArrayList<>();
  puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn1, snapshot1));
  puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn2, snapshot2));
  puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn3, snapshot3));
  final Map<TableName,SpaceQuotaSnapshot> expectedPolicies = new HashMap<>();
  expectedPolicies.put(tn1, snapshot1);
  expectedPolicies.put(tn2, snapshot2);
  expectedPolicies.put(tn3, snapshot3);

  final Map<TableName,SpaceQuotaSnapshot> actualPolicies = new HashMap<>();
  try (Table quotaTable = connection.getTable(QuotaUtil.QUOTA_TABLE_NAME)) {
    quotaTable.put(puts);
    ResultScanner scanner = quotaTable.getScanner(QuotaTableUtil.makeQuotaSnapshotScan());
    for (Result r : scanner) {
      QuotaTableUtil.extractQuotaSnapshot(r, actualPolicies);
    }
    scanner.close();
  }

  assertEquals(expectedPolicies, actualPolicies);
}
 
Example #29
Source File: ParallelScannerTest.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Configuration conf = HBaseConfiguration.create();
  HTable table = new HTable(conf, "t");
  String startKey = "1";
  String stopKey = "3";
  boolean isParallel = true;
  String familyName = "f";
  String columnName = "id";
  String remainder = "2";

  Scan scan = new Scan(Bytes.toBytes(startKey), Bytes.toBytes(stopKey));
  int count = 0;
  if (isParallel) {
    scan.setParallel(true);
  }
  scan.setFilter(new SingleColumnValueFilter(Bytes.toBytes(familyName), Bytes
      .toBytes(columnName), CompareOp.LESS, Bytes.toBytes(remainder)));
  ResultScanner scanner = table.getScanner(scan);
  Result r = scanner.next();
  while (r != null) {
    count++;
    r = scanner.next();
  }
  System.out.println("++ Scanning finished with count : " + count + " ++");
  scanner.close();
  table.close();
}
 
Example #30
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public ResultScanner getScanner(byte[] family, byte[] qualifier) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  Scan scan = new Scan();
  scan.addColumn(family, qualifier);
  return hTable.getScanner(transactionalizeAction(scan));
}