util.HBaseHelper.createTable()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(15.3k)|赞(0)|评价(0)|浏览(80)

本文整理了Java中util.HBaseHelper.createTable()方法的一些代码示例,展示了HBaseHelper.createTable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HBaseHelper.createTable()方法的具体详情如下:
包路径:util.HBaseHelper
类名称:HBaseHelper
方法名:createTable

HBaseHelper.createTable介绍

暂无

代码示例

代码示例来源:origin: larsgeorge/hbase-book

public void createTable(TableName table, int maxVersions, String... colfams)
throws IOException {
 createTable(table, maxVersions, null, colfams);
}

代码示例来源:origin: larsgeorge/hbase-book

public void createTable(TableName table, String... colfams)
throws IOException {
 createTable(table, 1, null, colfams);
}

代码示例来源:origin: larsgeorge/hbase-book

public void createTable(String table, byte[][] splitKeys, String... colfams)
throws IOException {
 createTable(TableName.valueOf(table), 1, splitKeys, colfams);
}

代码示例来源:origin: larsgeorge/hbase-book

public void createTable(String table, String... colfams)
throws IOException {
 createTable(TableName.valueOf(table), 1, null, colfams);
}

代码示例来源:origin: larsgeorge/hbase-book

public void createTable(String table, int maxVersions, String... colfams)
throws IOException {
 createTable(TableName.valueOf(table), maxVersions, null, colfams);
}

代码示例来源:origin: larsgeorge/hbase-book

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

  HBaseHelper helper = HBaseHelper.getHelper(conf);
  helper.dropTable("testtable");
  helper.createTable("testtable", "daily");
  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf("testtable"));
  // vv IncrementSingleExample
  long cnt1 = table.incrementColumnValue(Bytes.toBytes("20110101"), // co IncrementSingleExample-1-Incr1 Increase counter by one.
   Bytes.toBytes("daily"), Bytes.toBytes("hits"), 1);
  long cnt2 = table.incrementColumnValue(Bytes.toBytes("20110101"), // co IncrementSingleExample-2-Incr2 Increase counter by one a second time.
   Bytes.toBytes("daily"), Bytes.toBytes("hits"), 1);

  long current = table.incrementColumnValue(Bytes.toBytes("20110101"), // co IncrementSingleExample-3-GetCurrent Get current value of the counter without increasing it.
   Bytes.toBytes("daily"), Bytes.toBytes("hits"), 0);

  long cnt3 = table.incrementColumnValue(Bytes.toBytes("20110101"), // co IncrementSingleExample-4-Decr1 Decrease counter by one.
   Bytes.toBytes("daily"), Bytes.toBytes("hits"), -1);
  // ^^ IncrementSingleExample
  System.out.println("cnt1: " + cnt1 + ", cnt2: " + cnt2 +
   ", current: " + current + ", cnt3: " + cnt3);
 }
}

代码示例来源:origin: larsgeorge/hbase-book

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

  // ^^ GetTryWithResourcesExample
  HBaseHelper helper = HBaseHelper.getHelper(conf);
  if (!helper.existsTable("testtable")) {
   helper.createTable("testtable", "colfam1");
  }
  // vv GetTryWithResourcesExample
  try (
   Connection connection = ConnectionFactory.createConnection(conf);
   Table table = connection.getTable(TableName.valueOf("testtable")); // co GetTryWithResourcesExample-2-NewTable Instantiate a new table reference in "try" block.
  ) {
   Get get = new Get(Bytes.toBytes("row1"));
   get.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"));
   Result result = table.get(get);
   byte[] val = result.getValue(Bytes.toBytes("colfam1"),
    Bytes.toBytes("qual1"));
   System.out.println("Value: " + Bytes.toString(val));
  } // co GetTryWithResourcesExample-3-Close No explicit close needed, Java will handle AutoClosable's.
  // ^^ GetTryWithResourcesExample
  helper.close();
 }
}

代码示例来源:origin: larsgeorge/hbase-book

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

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

  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf("testtable"));

  // vv PutIdenticalExample
  Put put = new Put(Bytes.toBytes("row1"));
  put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"),
   Bytes.toBytes("val2"));
  put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"),
   Bytes.toBytes("val1")); // co PutIdenticalExample-1-Add Add the same column with a different value. The last value is going to be used.
  table.put(put);

  Get get = new Get(Bytes.toBytes("row1"));
  Result result = table.get(get);
  System.out.println("Result: " + result + ", Value: " + Bytes.toString(
   result.getValue(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1")))); // co PutIdenticalExample-2-Get Perform a get to verify that "val1" was actually stored.
  // ^^ PutIdenticalExample
  table.close();
  connection.close();
  helper.close();
 }
}

代码示例来源:origin: larsgeorge/hbase-book

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
  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf("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.

  get.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1")); // co GetExample-4-AddCol Add a column to the get.

  Result result = table.get(get); // co GetExample-5-DoGet Retrieve row with selected columns from HBase.

  byte[] val = result.getValue(Bytes.toBytes("colfam1"),
   Bytes.toBytes("qual1")); // co GetExample-6-GetValue Get a specific value for the given column.

  System.out.println("Value: " + Bytes.toString(val)); // co GetExample-7-Print Print out the value while converting it back.

  table.close(); // co GetExample-8-Close Close the table and connection instances to free resources.
  connection.close();
  // ^^ GetExample
  helper.close();
 }
}

代码示例来源:origin: larsgeorge/hbase-book

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");
  }
  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf("testtable"));

  // vv GetCloneExample
  Get get1 = new Get(Bytes.toBytes("row1"));
  get1.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"));

  Get get2 = new Get(get1);
  Result result = table.get(get2);

  System.out.println("Result : " + result);
  // ^^ GetCloneExample
  table.close();
  connection.close();
  helper.close();
 }
}

代码示例来源:origin: larsgeorge/hbase-book

helper.createTable("testtable", "colfam1");
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf("testtable"));

代码示例来源:origin: larsgeorge/hbase-book

@Override
 public Void run() throws Exception {
  Configuration conf = superuser.getConfiguration();
  HBaseHelper helper = HBaseHelper.getHelper(conf);
  helper.dropTable("testtable");
  helper.createTable("testtable", "colfam1");
  System.out.println("Superuser: Adding rows to table...");
  helper.fillTable("testtable", 1, 2, 2, "colfam1");
  helper.close();
  return null;
 }
});

代码示例来源:origin: larsgeorge/hbase-book

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

  // ^^ PutExample
  HBaseHelper helper = HBaseHelper.getHelper(conf);
  helper.dropTable("testtable");
  helper.createTable("testtable", "colfam1");
  // vv PutExample
  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf("testtable")); // co PutExample-2-NewTable Instantiate a new client.

  Put put = new Put(Bytes.toBytes("row1")); // co PutExample-3-NewPut Create put with specific row.

  put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"),
   Bytes.toBytes("val1")); // co PutExample-4-AddCol1 Add a column, whose name is "colfam1:qual1", to the put.
  put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual2"),
   Bytes.toBytes("val2")); // co PutExample-4-AddCol2 Add another column, whose name is "colfam1:qual2", to the put.

  table.put(put); // co PutExample-5-DoPut Store row with column into the HBase table.
  table.close(); // co PutExample-6-DoPut Close table and connection instances to free resources.
  connection.close();
  // ^^ PutExample
  helper.close();
  // vv PutExample
 }
}

代码示例来源:origin: larsgeorge/hbase-book

@Override
 public Void run() throws Exception {
  Configuration conf = superuser.getConfiguration();
  HBaseHelper helper = HBaseHelper.getHelper(conf);
  helper.dropTable("testtable");
  helper.createTable("testtable", "colfam1", "colfam2");
  System.out.println("Adding rows to table...");
  helper.fillTable("testtable", 1, 100, 100, "colfam1", "colfam2");
  helper.close();
  return null;
 }
});

代码示例来源:origin: larsgeorge/hbase-book

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, 30, 0, true, "colfam1");

  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf("testtable"));
  // vv ColumnPrefixFilterExample
  Filter filter = new ColumnPrefixFilter(Bytes.toBytes("col-1"));

  Scan scan = new Scan();
  scan.setFilter(filter);
  ResultScanner scanner = table.getScanner(scan);
  // ^^ ColumnPrefixFilterExample
  System.out.println("Results of scan:");
  // vv ColumnPrefixFilterExample
  for (Result result : scanner) {
   System.out.println(result);
  }
  scanner.close();
  // ^^ ColumnPrefixFilterExample
 }
}

代码示例来源:origin: larsgeorge/hbase-book

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, 30, 2, true, "colfam1");

  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf("testtable"));
  // vv ColumnPaginationFilterExample
  Filter filter = new ColumnPaginationFilter(5, 15);

  Scan scan = new Scan();
  scan.setFilter(filter);
  ResultScanner scanner = table.getScanner(scan);
  // ^^ ColumnPaginationFilterExample
  System.out.println("Results of scan:");
  // vv ColumnPaginationFilterExample
  for (Result result : scanner) {
   System.out.println(result);
  }
  scanner.close();
  // ^^ ColumnPaginationFilterExample
 }
}

代码示例来源:origin: larsgeorge/hbase-book

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.fillTableRandom("testtable", /* row */ 1, 5, 0,
    /* col */ 1, 30, 0,  /* val */ 0, 10000, 0, true, "colfam1");

  Connection connection = ConnectionFactory.createConnection(conf);
  table = connection.getTable(TableName.valueOf("testtable"));
  System.out.println("Scan #1");
  // vv KeyOnlyFilterExample
  Filter filter1 = new KeyOnlyFilter();
  scan(filter1);
  // ^^ KeyOnlyFilterExample
  System.out.println("Scan #2");
  // vv KeyOnlyFilterExample
  Filter filter2 = new KeyOnlyFilter(true);
  scan(filter2);
  // ^^ KeyOnlyFilterExample
 }
}

代码示例来源:origin: larsgeorge/hbase-book

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");
 Connection connection = ConnectionFactory.createConnection(conf);
 table = connection.getTable(TableName.valueOf("testtable"));
 // vv DependentColumnFilterExample
 filter(true, CompareFilter.CompareOp.NO_OP, null);
 filter(false, CompareFilter.CompareOp.NO_OP, null); // co DependentColumnFilterExample-2-Filter Call filter method with various options.
 filter(true, CompareFilter.CompareOp.EQUAL,
  new BinaryPrefixComparator(Bytes.toBytes("val-5")));
 filter(false, CompareFilter.CompareOp.EQUAL,
  new BinaryPrefixComparator(Bytes.toBytes("val-5")));
 filter(true, CompareFilter.CompareOp.EQUAL,
  new RegexStringComparator(".*\\.5"));
 filter(false, CompareFilter.CompareOp.EQUAL,
  new RegexStringComparator(".*\\.5"));
}
// ^^ DependentColumnFilterExample

代码示例来源:origin: larsgeorge/hbase-book

public static void main(String[] args)
 throws IOException, InterruptedException {
 Configuration conf = HBaseConfiguration.create();
 // ^^ RenameTableExample
 HBaseHelper helper = HBaseHelper.getHelper(conf);
 helper.dropTable("testtable");
 helper.createTable("testtable", "colfam1");
 System.out.println("Adding rows to table...");
 helper.fillTable("testtable", 1, 100, 100, "colfam1");
 // vv RenameTableExample
 Connection connection = ConnectionFactory.createConnection(conf);
 Admin admin = connection.getAdmin();
 TableName name = TableName.valueOf("testtable");
 Table table = connection.getTable(name); // co RenameTableExample-07-Test1 Check the content of the original table. The helper method (see full source code) prints the first value of the first row.
 printFirstValue(table);
 TableName rename = TableName.valueOf("newtesttable");
 renameTable(admin, name, rename); // co RenameTableExample-08-Rename Rename the table calling the above method.
 Table newTable = connection.getTable(rename); // co RenameTableExample-09-Test2 Perform another check on the new table to see if we get the same first value of the first row back.
 printFirstValue(newTable);
 table.close();
 newTable.close();
 admin.close();
 connection.close();
}
// ^^ RenameTableExample

代码示例来源:origin: larsgeorge/hbase-book

public static void main(String[] args) throws IOException {
 // ^^ ScanSlicingExample
 Configuration conf = HBaseConfiguration.create();
 HBaseHelper helper = HBaseHelper.getHelper(conf);
 helper.dropTable("testtable");
 helper.createTable("testtable", "colfam1", "colfam2");
 helper.fillTable("testtable", 1, 10, 10, 2, true, "colfam1", "colfam2");
 Connection connection = ConnectionFactory.createConnection(conf);
 table = connection.getTable(TableName.valueOf("testtable"));
 // vv ScanSlicingExample
 /*...*/
 scan(1, 11, 0, 0, 2, -1, true);
 scan(2, 11, 0, 4, 2, -1, true);
 scan(3, 5, 0, 0, 2, -1, false);
 scan(4, 11, 2, 0, 5, -1, true);
 scan(5, 11, -1, -1, -1, 1, false);
 scan(6, 11, -1, -1, -1, 10000, false);
 /*...*/
 // ^^ ScanSlicingExample
 table.close();
 connection.close();
 helper.close();
 // vv ScanSlicingExample
}
// ^^ ScanSlicingExample

相关文章