Examples of HBaseHelper


Examples of util.HBaseHelper

  private final static byte[] QUAL1 = Bytes.toBytes("qual1");

  public static void main(String[] args) throws IOException, InterruptedException {
    Configuration conf = HBaseConfiguration.create();

    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.createTable("testtable", "colfam1");

    HTable table = new HTable(conf, "testtable");
    HBaseAdmin admin = new HBaseAdmin(conf);

    // vv DeleteTimestampExample
    for (int count = 1; count <= 6; count++) { // co DeleteTimestampExample-1-Put Store the same column six times.
      Put put = new Put(ROW1);
      put.add(COLFAM1, QUAL1, count, Bytes.toBytes("val-" + count)); // co DeleteTimestampExample-2-Add The version is set to a specific value, using the loop variable.
      table.put(put);
    }
    // ^^ DeleteTimestampExample
    System.out.println("After put calls...");
    helper.dump("testtable", new String[] { "row1" }, null, null);
//    admin.flush("testtable");
//    Thread.sleep(3000);
//    admin.majorCompact("testtable");
//    Thread.sleep(3000);
    // vv DeleteTimestampExample

    Delete delete = new Delete(ROW1); // co DeleteTimestampExample-3-Delete Delete the newest two versions.
    delete.deleteColumn(COLFAM1, QUAL1, 5);
    delete.deleteColumn(COLFAM1, QUAL1, 6);
    table.delete(delete);
    // ^^ DeleteTimestampExample

    System.out.println("After delete call...");
    helper.dump("testtable", new String[]{ "row1" }, null, null);
  }
View Full Code Here

Examples of util.HBaseHelper

public class GetListErrorExample {

  public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();
    HBaseHelper helper = HBaseHelper.getHelper(conf);
    if (!helper.existsTable("testtable")) {
      helper.createTable("testtable", "colfam1");
    }
    HTable table = new HTable(conf, "testtable");

    byte[] cf1 = Bytes.toBytes("colfam1");
    byte[] qf1 = Bytes.toBytes("qual1");
View Full Code Here

Examples of util.HBaseHelper

  public static void main(String[] args) throws IOException {
    // ^^ DependentColumnFilterExample
    Configuration conf = HBaseConfiguration.create();

    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.createTable("testtable", "colfam1", "colfam2");
    System.out.println("Adding rows to table...");
    helper.fillTable("testtable", 1, 10, 10, true, "colfam1", "colfam2");

    table = new HTable(conf, "testtable");

    // vv DependentColumnFilterExample
    filter(true, CompareFilter.CompareOp.NO_OP, null);
View Full Code Here

Examples of util.HBaseHelper

// cc EndpointProxyExample Example using the proxy call of HTable to invoke an endpoint on a single region
public class EndpointProxyExample {

  public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();
    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.createTable("testtable", "colfam1", "colfam2");
    helper.put("testtable",
      new String[]{"row1", "row2", "row3", "row4", "row5"},
      new String[]{"colfam1", "colfam2"},
      new String[]{"qual1", "qual1"},
      new long[]{1, 2},
      new String[]{"val1", "val2"});
    System.out.println("Before endpoint call...");
    helper.dump("testtable",
      new String[]{"row1", "row2", "row3", "row4", "row5"},
      null, null);
    HBaseAdmin admin = new HBaseAdmin(conf);
    try {
      admin.split("testtable", "row3");
View Full Code Here

Examples of util.HBaseHelper

  public static void main(String[] args) throws IOException {
    // vv GetExample
    Configuration conf = HBaseConfiguration.create(); // co GetExample-1-CreateConf Create the configuration.

    // ^^ GetExample
    HBaseHelper helper = HBaseHelper.getHelper(conf);
    if (!helper.existsTable("testtable")) {
      helper.createTable("testtable", "colfam1");
    }
    // vv GetExample
    HTable table = new HTable(conf, "testtable"); // co GetExample-2-NewTable Instantiate a new table reference.

    Get get = new Get(Bytes.toBytes("row1")); // co GetExample-3-NewGet Create get with specific row.
View Full Code Here

Examples of util.HBaseHelper

public class SkipFilterExample {

  public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();

    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.createTable("testtable", "colfam1");
    System.out.println("Adding rows to table...");
    helper.fillTable("testtable", 1, 30, 5, 2, true, true, "colfam1");

    HTable table = new HTable(conf, "testtable");

    // vv SkipFilterExample
    Filter filter1 = new ValueFilter(CompareFilter.CompareOp.NOT_EQUAL,
View Full Code Here

Examples of util.HBaseHelper

    }

    // ^^ RowLockExample

  public static void main(String[] args) throws IOException {
    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.createTable("testtable", "colfam1", "colfam2");

    HTable table = new HTable(conf, "testtable");

    // vv RowLockExample
    System.out.println("Taking out lock...");
    RowLock lock = table.lockRow(ROW1); // co RowLockExample-3-Lock Lock the entire row.
    System.out.println("Lock ID: " + lock.getLockId());

    Thread thread = new Thread(new UnlockedPut()); // co RowLockExample-4-Start Start the asynchronous thread, which will block.
    thread.start();

    try {
      System.out.println("Sleeping 5secs in main()..."); // co RowLockExample-5-Sleep Sleep for some time to block other writers.
      Thread.sleep(5000);
    } catch (InterruptedException e) {
      // ignore
    }

    try {
      Put put1 = new Put(ROW1, lock); // co RowLockExample-6-NewPut1 Create Put under own lock.
      put1.add(COLFAM1, QUAL1, VAL1);
      table.put(put1);

      Put put2 = new Put(ROW1, lock); // co RowLockExample-7-NewPut2 Create another Put under own lock.
      put2.add(COLFAM1, QUAL1, VAL2);
      table.put(put2);
    } catch (Exception e) {
      System.err.println("Error: " + e);
    } finally {
      System.out.println("Releasing lock..."); // co RowLockExample-8-Unlock Release the lock, which will make the thread continue.
      table.unlockRow(lock);
    }
    // ^^ RowLockExample
    try {
      thread.join();
    } catch (InterruptedException e) {
      // ignore
    }
    System.out.println("After thread ended...");
    helper.dump("testtable", new String[]{ "row1" }, null, null);
  }
View Full Code Here

Examples of util.HBaseHelper

public class WhileMatchFilterExample {

  public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();

    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.createTable("testtable", "colfam1");
    System.out.println("Adding rows to table...");
    helper.fillTable("testtable", 1, 10, 1, 2, true, false, "colfam1");

    HTable table = new HTable(conf, "testtable");

    // vv WhileMatchFilterExample
    Filter filter1 = /*[*/new RowFilter(CompareFilter.CompareOp.NOT_EQUAL,
View Full Code Here

Examples of util.HBaseHelper

public class DeleteListErrorExample {

  public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();
    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.createTable("testtable", "colfam1", "colfam2");
    HTable table = new HTable(conf, "testtable");
    helper.put("testtable",
      new String[] { "row1" },
      new String[] { "colfam1", "colfam2" },
      new String[] { "qual1", "qual1", "qual2", "qual2", "qual3", "qual3" },
      new long[]   { 1, 2, 3, 4, 5, 6 },
      new String[] { "val1", "val2", "val3", "val4", "val5", "val6" });
    helper.put("testtable",
      new String[] { "row2" },
      new String[] { "colfam1", "colfam2" },
      new String[] { "qual1", "qual1", "qual2", "qual2", "qual3", "qual3" },
      new long[]   { 1, 2, 3, 4, 5, 6 },
      new String[] { "val1", "val2", "val3", "val4", "val5", "val6" });
    helper.put("testtable",
      new String[] { "row3" },
      new String[] { "colfam1", "colfam2" },
      new String[] { "qual1", "qual1", "qual2", "qual2", "qual3", "qual3" },
      new long[]   { 1, 2, 3, 4, 5, 6 },
      new String[] { "val1", "val2", "val3", "val4", "val5", "val6" });
    System.out.println("Before delete call...");
    helper.dump("testtable", new String[]{ "row1", "row2", "row3" }, null, null);

    List<Delete> deletes = new ArrayList<Delete>();

    Delete delete1 = new Delete(Bytes.toBytes("row1"));
    delete1.setTimestamp(4);
    deletes.add(delete1);

    Delete delete2 = new Delete(Bytes.toBytes("row2"));
    delete2.deleteColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"));
    delete2.deleteColumns(Bytes.toBytes("colfam2"), Bytes.toBytes("qual3"), 5);
    deletes.add(delete2);

    Delete delete3 = new Delete(Bytes.toBytes("row3"));
    delete3.deleteFamily(Bytes.toBytes("colfam1"));
    delete3.deleteFamily(Bytes.toBytes("colfam2"), 3);
    deletes.add(delete3);

    // vv DeleteListErrorExample
    Delete delete4 = new Delete(Bytes.toBytes("row2"));
    /*[*/delete4.deleteColumn(Bytes.toBytes("BOGUS"),/*]*/ Bytes.toBytes("qual1")); // co DeleteListErrorExample-1-DelColNoTS Add bogus column family to trigger an error.
    deletes.add(delete4);

    try {
      table.delete(deletes); // co DeleteListErrorExample-2-DoDel Delete the data from multiple rows the HBase table.
    } catch (Exception e) {
      System.err.println("Error: " + e); // co DeleteListErrorExample-3-Catch Guard against remote exceptions.
    }
    table.close();

    System.out.println("Deletes length: " + deletes.size()); // co DeleteListErrorExample-4-CheckSize Check the length of the list after the call.
    for (Delete delete : deletes) {
      System.out.println(delete); // co DeleteListErrorExample-5-Dump Print out failed delete for debugging purposes.
    }
    // ^^ DeleteListErrorExample
    System.out.println("After delete call...");
    helper.dump("testtable", new String[]{ "row1", "row2", "row3" }, null, null);
  }
View Full Code Here

Examples of util.HBaseHelper

public class CustomFilterExample {

  public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();

    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.createTable("testtable", "colfam1");
    System.out.println("Adding rows to table...");
    helper.fillTable("testtable", 1, 10, 10, 2, false, "colfam1");

    HTable table = new HTable(conf, "testtable");

    // vv CustomFilterExample
    List<Filter> filters = new ArrayList<Filter>();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.