Package org.apache.hadoop.hbase.client

Examples of org.apache.hadoop.hbase.client.Table


  // @Ignore @Test
  public void testBulkDeleteEndpointWhenRowBatchSizeLessThanRowsToDeleteFromARegion()
      throws Throwable {
    byte[] tableName = Bytes
        .toBytes("testBulkDeleteEndpointWhenRowBatchSizeLessThanRowsToDeleteFromARegion");
    Table ht = createTable(tableName);
    List<Put> puts = new ArrayList<Put>(100);
    for (int j = 0; j < 100; j++) {
      byte[] rowkey = Bytes.toBytes(j);
      puts.add(createPut(rowkey, "v1"));
    }
    ht.put(puts);
    // Deleting all the rows.
    long noOfRowsDeleted = invokeBulkDeleteProtocol(tableName, new Scan(), 10, DeleteType.ROW, null);
    assertEquals(100, noOfRowsDeleted);

    int rows = 0;
    for (Result result : ht.getScanner(new Scan())) {
      rows++;
    }
    assertEquals(0, rows);
    ht.close();
  }
View Full Code Here


    ht.close();
  }

  private long invokeBulkDeleteProtocol(byte[] tableName, final Scan scan, final int rowBatchSize,
      final DeleteType deleteType, final Long timeStamp) throws Throwable {
    Table ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
    long noOfDeletedRows = 0L;
    Batch.Call<BulkDeleteService, BulkDeleteResponse> callable =
      new Batch.Call<BulkDeleteService, BulkDeleteResponse>() {
      ServerRpcController controller = new ServerRpcController();
      BlockingRpcCallback<BulkDeleteResponse> rpcCallback =
        new BlockingRpcCallback<BulkDeleteResponse>();

      public BulkDeleteResponse call(BulkDeleteService service) throws IOException {
        Builder builder = BulkDeleteRequest.newBuilder();
        builder.setScan(ProtobufUtil.toScan(scan));
        builder.setDeleteType(deleteType);
        builder.setRowBatchSize(rowBatchSize);
        if (timeStamp != null) {
          builder.setTimestamp(timeStamp);
        }
        service.delete(controller, builder.build(), rpcCallback);
        return rpcCallback.get();
      }
    };
    Map<byte[], BulkDeleteResponse> result = ht.coprocessorService(BulkDeleteService.class, scan
        .getStartRow(), scan.getStopRow(), callable);
    for (BulkDeleteResponse response : result.values()) {
      noOfDeletedRows += response.getRowsDeleted();
    }
    ht.close();
    return noOfDeletedRows;
  }
View Full Code Here

  }

  // @Ignore @Test
  public void testBulkDeleteWithConditionBasedDelete() throws Throwable {
    byte[] tableName = Bytes.toBytes("testBulkDeleteWithConditionBasedDelete");
    Table ht = createTable(tableName);
    List<Put> puts = new ArrayList<Put>(100);
    for (int j = 0; j < 100; j++) {
      byte[] rowkey = Bytes.toBytes(j);
      String value = (j % 10 == 0) ? "v1" : "v2";
      puts.add(createPut(rowkey, value));
    }
    ht.put(puts);
    Scan scan = new Scan();
    FilterList fl = new FilterList(Operator.MUST_PASS_ALL);
    SingleColumnValueFilter scvf = new SingleColumnValueFilter(FAMILY1, QUALIFIER3,
        CompareOp.EQUAL, Bytes.toBytes("v1"));
    // fl.addFilter(new FirstKeyOnlyFilter());
    fl.addFilter(scvf);
    scan.setFilter(fl);
    // Deleting all the rows where cf1:c1=v1
    long noOfRowsDeleted = invokeBulkDeleteProtocol(tableName, scan, 500, DeleteType.ROW, null);
    assertEquals(10, noOfRowsDeleted);

    int rows = 0;
    for (Result result : ht.getScanner(new Scan())) {
      rows++;
    }
    assertEquals(90, rows);
    ht.close();
  }
View Full Code Here

  }

  // @Ignore @Test
  public void testBulkDeleteColumn() throws Throwable {
    byte[] tableName = Bytes.toBytes("testBulkDeleteColumn");
    Table ht = createTable(tableName);
    List<Put> puts = new ArrayList<Put>(100);
    for (int j = 0; j < 100; j++) {
      byte[] rowkey = Bytes.toBytes(j);
      String value = (j % 10 == 0) ? "v1" : "v2";
      puts.add(createPut(rowkey, value));
    }
    ht.put(puts);
    Scan scan = new Scan();
    scan.addColumn(FAMILY1, QUALIFIER2);
    // Delete the column cf1:col2
    long noOfRowsDeleted = invokeBulkDeleteProtocol(tableName, scan, 500, DeleteType.COLUMN, null);
    assertEquals(100, noOfRowsDeleted);

    int rows = 0;
    for (Result result : ht.getScanner(new Scan())) {
      assertEquals(2, result.getFamilyMap(FAMILY1).size());
      assertTrue(result.getColumnCells(FAMILY1, QUALIFIER2).isEmpty());
      assertEquals(1, result.getColumnCells(FAMILY1, QUALIFIER1).size());
      assertEquals(1, result.getColumnCells(FAMILY1, QUALIFIER3).size());
      rows++;
    }
    assertEquals(100, rows);
    ht.close();
  }
View Full Code Here

    byte[] tableName = Bytes.toBytes("testBulkDeleteFamily");
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
    htd.addFamily(new HColumnDescriptor(FAMILY1));
    htd.addFamily(new HColumnDescriptor(FAMILY2));
    TEST_UTIL.getHBaseAdmin().createTable(htd, Bytes.toBytes(0), Bytes.toBytes(120), 5);
    Table ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
    List<Put> puts = new ArrayList<Put>(100);
    for (int j = 0; j < 100; j++) {
      Put put = new Put(Bytes.toBytes(j));
      put.add(FAMILY1, QUALIFIER1, "v1".getBytes());
      put.add(FAMILY2, QUALIFIER2, "v2".getBytes());
      puts.add(put);
    }
    ht.put(puts);
    Scan scan = new Scan();
    scan.addFamily(FAMILY1);
    // Delete the column family cf1
    long noOfRowsDeleted = invokeBulkDeleteProtocol(tableName, scan, 500, DeleteType.FAMILY, null);
    assertEquals(100, noOfRowsDeleted);
    int rows = 0;
    for (Result result : ht.getScanner(new Scan())) {
      assertTrue(result.getFamilyMap(FAMILY1).isEmpty());
      assertEquals(1, result.getColumnCells(FAMILY2, QUALIFIER2).size());
      rows++;
    }
    assertEquals(100, rows);
    ht.close();
  }
View Full Code Here

  }

  // @Ignore @Test
  public void testBulkDeleteColumnVersion() throws Throwable {
    byte[] tableName = Bytes.toBytes("testBulkDeleteColumnVersion");
    Table ht = createTable(tableName);
    List<Put> puts = new ArrayList<Put>(100);
    for (int j = 0; j < 100; j++) {
      Put put = new Put(Bytes.toBytes(j));
      byte[] value = "v1".getBytes();
      put.add(FAMILY1, QUALIFIER1, 1234L, value);
      put.add(FAMILY1, QUALIFIER2, 1234L, value);
      put.add(FAMILY1, QUALIFIER3, 1234L, value);
      // Latest version values
      value = "v2".getBytes();
      put.add(FAMILY1, QUALIFIER1, value);
      put.add(FAMILY1, QUALIFIER2, value);
      put.add(FAMILY1, QUALIFIER3, value);
      put.add(FAMILY1, null, value);
      puts.add(put);
    }
    ht.put(puts);
    Scan scan = new Scan();
    scan.addFamily(FAMILY1);
    // Delete the latest version values of all the columns in family cf1.
    long noOfRowsDeleted = invokeBulkDeleteProtocol(tableName, scan, 500, DeleteType.VERSION,
        HConstants.LATEST_TIMESTAMP);
    assertEquals(100, noOfRowsDeleted);
    int rows = 0;
    scan = new Scan();
    scan.setMaxVersions();
    for (Result result : ht.getScanner(scan)) {
      assertEquals(3, result.getFamilyMap(FAMILY1).size());
      List<Cell> column = result.getColumnCells(FAMILY1, QUALIFIER1);
      assertEquals(1, column.size());
      assertTrue(CellUtil.matchingValue(column.get(0), "v1".getBytes()));

      column = result.getColumnCells(FAMILY1, QUALIFIER2);
      assertEquals(1, column.size());
      assertTrue(CellUtil.matchingValue(column.get(0), "v1".getBytes()));

      column = result.getColumnCells(FAMILY1, QUALIFIER3);
      assertEquals(1, column.size());
      assertTrue(CellUtil.matchingValue(column.get(0), "v1".getBytes()));
      rows++;
    }
    assertEquals(100, rows);
    ht.close();
  }
View Full Code Here

  }

  // @Ignore @Test
  public void testBulkDeleteColumnVersionBasedOnTS() throws Throwable {
    byte[] tableName = Bytes.toBytes("testBulkDeleteColumnVersionBasedOnTS");
    Table ht = createTable(tableName);
    List<Put> puts = new ArrayList<Put>(100);
    for (int j = 0; j < 100; j++) {
      Put put = new Put(Bytes.toBytes(j));
      // TS = 1000L
      byte[] value = "v1".getBytes();
      put.add(FAMILY1, QUALIFIER1, 1000L, value);
      put.add(FAMILY1, QUALIFIER2, 1000L, value);
      put.add(FAMILY1, QUALIFIER3, 1000L, value);
      // TS = 1234L
      value = "v2".getBytes();
      put.add(FAMILY1, QUALIFIER1, 1234L, value);
      put.add(FAMILY1, QUALIFIER2, 1234L, value);
      put.add(FAMILY1, QUALIFIER3, 1234L, value);
      // Latest version values
      value = "v3".getBytes();
      put.add(FAMILY1, QUALIFIER1, value);
      put.add(FAMILY1, QUALIFIER2, value);
      put.add(FAMILY1, QUALIFIER3, value);
      puts.add(put);
    }
    ht.put(puts);
    Scan scan = new Scan();
    scan.addColumn(FAMILY1, QUALIFIER3);
    // Delete the column cf1:c3's one version at TS=1234
    long noOfRowsDeleted = invokeBulkDeleteProtocol(tableName, scan, 500, DeleteType.VERSION, 1234L);
    assertEquals(100, noOfRowsDeleted);
    int rows = 0;
    scan = new Scan();
    scan.setMaxVersions();
    for (Result result : ht.getScanner(scan)) {
      assertEquals(3, result.getFamilyMap(FAMILY1).size());
      assertEquals(3, result.getColumnCells(FAMILY1, QUALIFIER1).size());
      assertEquals(3, result.getColumnCells(FAMILY1, QUALIFIER2).size());
      List<Cell> column = result.getColumnCells(FAMILY1, QUALIFIER3);
      assertEquals(2, column.size());
      assertTrue(CellUtil.matchingValue(column.get(0), "v3".getBytes()));
      assertTrue(CellUtil.matchingValue(column.get(1), "v1".getBytes()));
      rows++;
    }
    assertEquals(100, rows);
    ht.close();
  }
View Full Code Here

  }

  // @Ignore @Test
  public void testBulkDeleteWithNumberOfVersions() throws Throwable {
    byte[] tableName = Bytes.toBytes("testBulkDeleteWithNumberOfVersions");
    Table ht = createTable(tableName);
    List<Put> puts = new ArrayList<Put>(100);
    for (int j = 0; j < 100; j++) {
      Put put = new Put(Bytes.toBytes(j));
      // TS = 1000L
      byte[] value = "v1".getBytes();
      put.add(FAMILY1, QUALIFIER1, 1000L, value);
      put.add(FAMILY1, QUALIFIER2, 1000L, value);
      put.add(FAMILY1, QUALIFIER3, 1000L, value);
      // TS = 1234L
      value = "v2".getBytes();
      put.add(FAMILY1, QUALIFIER1, 1234L, value);
      put.add(FAMILY1, QUALIFIER2, 1234L, value);
      put.add(FAMILY1, QUALIFIER3, 1234L, value);
      // TS = 2000L
      value = "v3".getBytes();
      put.add(FAMILY1, QUALIFIER1, 2000L, value);
      put.add(FAMILY1, QUALIFIER2, 2000L, value);
      put.add(FAMILY1, QUALIFIER3, 2000L, value);
      // Latest version values
      value = "v4".getBytes();
      put.add(FAMILY1, QUALIFIER1, value);
      put.add(FAMILY1, QUALIFIER2, value);
      put.add(FAMILY1, QUALIFIER3, value);
      puts.add(put);
    }
    ht.put(puts);

    // Delete all the versions of columns cf1:c1 and cf1:c2 falling with the time range
    // [1000,2000)
    final Scan scan = new Scan();
    scan.addColumn(FAMILY1, QUALIFIER1);
    scan.addColumn(FAMILY1, QUALIFIER2);
    scan.setTimeRange(1000L, 2000L);
    scan.setMaxVersions();

    long noOfDeletedRows = 0L;
    long noOfVersionsDeleted = 0L;
    Batch.Call<BulkDeleteService, BulkDeleteResponse> callable =
      new Batch.Call<BulkDeleteService, BulkDeleteResponse>() {
      ServerRpcController controller = new ServerRpcController();
      BlockingRpcCallback<BulkDeleteResponse> rpcCallback =
        new BlockingRpcCallback<BulkDeleteResponse>();

      public BulkDeleteResponse call(BulkDeleteService service) throws IOException {
        Builder builder = BulkDeleteRequest.newBuilder();
        builder.setScan(ProtobufUtil.toScan(scan));
        builder.setDeleteType(DeleteType.VERSION);
        builder.setRowBatchSize(500);
        service.delete(controller, builder.build(), rpcCallback);
        return rpcCallback.get();
      }
    };
    Map<byte[], BulkDeleteResponse> result = ht.coprocessorService(BulkDeleteService.class, scan
        .getStartRow(), scan.getStopRow(), callable);
    for (BulkDeleteResponse response : result.values()) {
      noOfDeletedRows += response.getRowsDeleted();
      noOfVersionsDeleted += response.getVersionsDeleted();
    }
    assertEquals(100, noOfDeletedRows);
    assertEquals(400, noOfVersionsDeleted);

    int rows = 0;
    Scan scan1 = new Scan();
    scan1.setMaxVersions();
    for (Result res : ht.getScanner(scan1)) {
      assertEquals(3, res.getFamilyMap(FAMILY1).size());
      List<Cell> column = res.getColumnCells(FAMILY1, QUALIFIER1);
      assertEquals(2, column.size());
      assertTrue(CellUtil.matchingValue(column.get(0), "v4".getBytes()));
      assertTrue(CellUtil.matchingValue(column.get(1), "v3".getBytes()));
      column = res.getColumnCells(FAMILY1, QUALIFIER2);
      assertEquals(2, column.size());
      assertTrue(CellUtil.matchingValue(column.get(0), "v4".getBytes()));
      assertTrue(CellUtil.matchingValue(column.get(1), "v3".getBytes()));
      assertEquals(4, res.getColumnCells(FAMILY1, QUALIFIER3).size());
      rows++;
    }
    assertEquals(100, rows);
    ht.close();
  }
View Full Code Here

    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
    HColumnDescriptor hcd = new HColumnDescriptor(FAMILY1);
    hcd.setMaxVersions(10);// Just setting 10 as I am not testing with more than 10 versions here
    htd.addFamily(hcd);
    TEST_UTIL.getHBaseAdmin().createTable(htd, Bytes.toBytes(0), Bytes.toBytes(120), 5);
    Table ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
    return ht;
  }
View Full Code Here

    HColumnDescriptor hcd = new HColumnDescriptor(F)
    .setMaxVersions(10)
    .setTimeToLive(1);
    desc.addFamily(hcd);
    TEST_UTIL.getHBaseAdmin().createTable(desc);
    Table t = new HTable(new Configuration(TEST_UTIL.getConfiguration()), tableName);
    long now = EnvironmentEdgeManager.currentTime();

    ZooKeeperWatcher zkw = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(), "test", null);
    ZooKeeper zk = zkw.getRecoverableZooKeeper().getZooKeeper();
    ZKUtil.createWithParents(zkw, ZooKeeperScanPolicyObserver.node);
    // let's say test last backup was 1h ago
    // using plain ZK here, because RecoverableZooKeeper add extra encoding to the data
    zk.setData(ZooKeeperScanPolicyObserver.node, Bytes.toBytes(now - 3600*1000), -1);

    LOG.debug("Set time: "+Bytes.toLong(Bytes.toBytes(now - 3600*1000)));

    // sleep for 1s to give the ZK change a chance to reach the watcher in the observer.
    // TODO: Better to wait for the data to be propagated
    Thread.sleep(1000);

    long ts = now - 2000;
    Put p = new Put(R);
    p.add(F, Q, ts, Q);
    t.put(p);
    p = new Put(R);
    p.add(F, Q, ts+1, Q);
    t.put(p);

    // these two should be expired but for the override
    // (their ts was 2s in the past)
    Get g = new Get(R);
    g.setMaxVersions(10);
    Result r = t.get(g);
    // still there?
    assertEquals(2, r.size());

    TEST_UTIL.flush(tableName);
    TEST_UTIL.compact(tableName, true);

    g = new Get(R);
    g.setMaxVersions(10);
    r = t.get(g);
    // still there?
    assertEquals(2, r.size());
    zk.setData(ZooKeeperScanPolicyObserver.node, Bytes.toBytes(now), -1);
    LOG.debug("Set time: "+now);

    TEST_UTIL.compact(tableName, true);

    g = new Get(R);
    g.setMaxVersions(10);
    r = t.get(g);
    // should be gone now
    assertEquals(0, r.size());
    t.close();
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.client.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.