Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.HBaseAdmin


    if (this.tableName == null)
      return new ReturnMsg(0, "Syntax error : Please check 'Truncate' syntax.");

    try {
      HConnection conn = HConnectionManager.getConnection(conf);
      HBaseAdmin admin = new HBaseAdmin(conf);

      if (!conn.tableExists(tableName)) {
        return new ReturnMsg(0, "Table not found.");
      }

      HTableDescriptor[] tables = conn.listTables();
      HColumnDescriptor[] columns = null;
      for (int i = 0; i < tables.length; i++) {
        if (tables[i].getName().equals(tableName)) {
          columns = tables[i].getFamilies().values().toArray(
              new HColumnDescriptor[] {});
          break;
        }
      }
      println("Truncating a '" + tableName + "' table ... Please wait.");

      admin.deleteTable(tableName); // delete the table
      HTableDescriptor tableDesc = new HTableDescriptor(tableName.toString());
      for (int i = 0; i < columns.length; i++) {
        tableDesc.addFamily(columns[i]);
      }
      admin.createTable(tableDesc); // re-create the table
    } catch (IOException e) {
      return new ReturnMsg(0, "error msg : " + e.toString());
    }
    return new ReturnMsg(0, "'" + tableName + "' is successfully truncated.");
  }
View Full Code Here


    HTableDescriptor desc = new HTableDescriptor(SINGLE_REGION_TABLE_NAME);
    desc.addFamily(new HColumnDescriptor(INPUT_COLUMN));
    desc.addFamily(new HColumnDescriptor(OUTPUT_COLUMN));
   
    // Create a table.
    HBaseAdmin admin = new HBaseAdmin(this.conf);
    admin.createTable(desc);

    // insert some data into the test table
    HTable table = new HTable(conf, new Text(SINGLE_REGION_TABLE_NAME));

    try {
View Full Code Here

    HTableDescriptor desc = new HTableDescriptor(MULTI_REGION_TABLE_NAME);
    desc.addFamily(new HColumnDescriptor(INPUT_COLUMN));
    desc.addFamily(new HColumnDescriptor(OUTPUT_COLUMN));
   
    // Create a table.
    HBaseAdmin admin = new HBaseAdmin(this.conf);
    admin.createTable(desc);

    // Populate a table into multiple regions
    makeMultiRegionTable(conf, hCluster, fs, MULTI_REGION_TABLE_NAME,
        INPUT_COLUMN);
   
View Full Code Here

      // Start up HBase cluster
      hCluster = new MiniHBaseCluster(conf, 1, dfsCluster, true);

      // Create a table.
      HBaseAdmin admin = new HBaseAdmin(conf);
      admin.createTable(desc);

      // Populate a table into multiple regions
      makeMultiRegionTable(conf, hCluster, this.fs, TABLE_NAME, INPUT_COLUMN);

      // Verify table indeed has multiple regions
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.HBaseAdmin

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.