本文整理了Java中util.HBaseHelper.dropTable()
方法的一些代码示例,展示了HBaseHelper.dropTable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HBaseHelper.dropTable()
方法的具体详情如下:
包路径:util.HBaseHelper
类名称:HBaseHelper
方法名:dropTable
暂无
代码示例来源:origin: larsgeorge/hbase-book
public void dropTable(String table) throws IOException {
dropTable(TableName.valueOf(table));
}
代码示例来源: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, InterruptedException {
// vv CreateTableExample
Configuration conf = HBaseConfiguration.create();
// ^^ CreateTableExample
HBaseHelper helper = HBaseHelper.getHelper(conf);
helper.dropTable("testtable");
// vv CreateTableExample
Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin(); // co CreateTableExample-1-CreateAdmin Create a administrative API instance.
TableName tableName = TableName.valueOf("testtable");
HTableDescriptor desc = new HTableDescriptor(tableName); // co CreateTableExample-2-CreateHTD Create the table descriptor instance.
HColumnDescriptor coldef = new HColumnDescriptor( // co CreateTableExample-3-CreateHCD Create a column family descriptor and add it to the table descriptor.
Bytes.toBytes("colfam1"));
desc.addFamily(coldef);
admin.createTable(desc); // co CreateTableExample-4-CreateTable Call the createTable() method to do the actual work.
boolean avail = admin.isTableAvailable(tableName); // co CreateTableExample-5-Check Check if the table is available.
System.out.println("Table available: " + avail);
// ^^ CreateTableExample
}
}
代码示例来源:origin: larsgeorge/hbase-book
helper.dropTable("testtable");
helper.createTable("testtable", "colfam1");
代码示例来源: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 {
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
HBaseHelper helper = HBaseHelper.getHelper(conf);
helper.dropTable("testtable");
TableName tableName = TableName.valueOf("testtable");
// vv LoadWithTableDescriptorExample2
HTableDescriptor htd = new HTableDescriptor(tableName); // co LoadWithTableDescriptorExample2-1-Create Use fluent interface to create and configure the instance.
htd.addFamily(new HColumnDescriptor("colfam1"));
/*[*/htd.addCoprocessor(RegionObserverExample.class.getCanonicalName(),
null, Coprocessor.PRIORITY_USER, null);/*]*/ // co LoadWithTableDescriptorExample2-2-AddCP Use the provided method to add the coprocessor.
Admin admin = connection.getAdmin();
admin.createTable(htd);
// ^^ LoadWithTableDescriptorExample2
System.out.println(admin.getTableDescriptor(tableName));
admin.close();
connection.close();
}
}
代码示例来源:origin: larsgeorge/hbase-book
helper.dropTable("testtable");
helper.createTable("testtable", "colfam1");
Connection connection = ConnectionFactory.createConnection(conf);
代码示例来源:origin: larsgeorge/hbase-book
public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
// ^^ LoadWithTableDescriptorExample
HBaseHelper helper = HBaseHelper.getHelper(conf);
helper.dropTable("testtable");
// vv LoadWithTableDescriptorExample
TableName tableName = TableName.valueOf("testtable");
HTableDescriptor htd = new HTableDescriptor(tableName); // co LoadWithTableDescriptorExample-1-Define Define a table descriptor.
htd.addFamily(new HColumnDescriptor("colfam1"));
htd.setValue("COPROCESSOR$1", "|" + // co LoadWithTableDescriptorExample-2-AddCP Add the coprocessor definition to the descriptor, while omitting the path to the JAR file.
RegionObserverExample.class.getCanonicalName() +
"|" + Coprocessor.PRIORITY_USER);
Admin admin = connection.getAdmin(); // co LoadWithTableDescriptorExample-3-Admin Acquire an administrative API to the cluster and add the table.
admin.createTable(htd);
System.out.println(admin.getTableDescriptor(tableName)); // co LoadWithTableDescriptorExample-4-Check Verify if the definition has been applied as expected.
admin.close();
connection.close();
}
}
代码示例来源: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
public static void main(String[] args) throws IOException, InterruptedException {
Configuration conf = HBaseConfiguration.create();
HBaseHelper helper = HBaseHelper.getHelper(conf);
helper.dropTable("testtable");
Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin();
// vv CreateTableWithNamespaceExample
/*[*/NamespaceDescriptor namespace =
NamespaceDescriptor.create("testspace").build();
admin.createNamespace(namespace);/*]*/
TableName tableName = TableName.valueOf("testspace", "testtable");
HTableDescriptor desc = new HTableDescriptor(tableName);
HColumnDescriptor coldef = new HColumnDescriptor(
Bytes.toBytes("colfam1"));
desc.addFamily(coldef);
admin.createTable(desc);
// ^^ CreateTableWithNamespaceExample
boolean avail = admin.isTableAvailable(tableName);
System.out.println("Table available: " + avail);
}
}
代码示例来源: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 RandomRowFilterExample
Filter filter = new RandomRowFilter(0.5f);
for (int loop = 1; loop <= 3; loop++) {
Scan scan = new Scan();
scan.setFilter(filter);
ResultScanner scanner = table.getScanner(scan);
// ^^ RandomRowFilterExample
System.out.println("Results of scan for loop: " + loop);
// vv RandomRowFilterExample
for (Result result : scanner) {
System.out.println(Bytes.toString(result.getRow()));
}
scanner.close();
}
// ^^ RandomRowFilterExample
}
}
代码示例来源: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, 100, 1, "colfam1");
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf("testtable"));
// vv InclusiveStopFilterExample
Filter filter = new InclusiveStopFilter(Bytes.toBytes("row-5"));
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes("row-3"));
scan.setFilter(filter);
ResultScanner scanner = table.getScanner(scan);
// ^^ InclusiveStopFilterExample
System.out.println("Results of scan:");
// vv InclusiveStopFilterExample
for (Result result : scanner) {
System.out.println(result);
}
scanner.close();
// ^^ InclusiveStopFilterExample
}
}
代码示例来源: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
内容来源于网络,如有侵权,请联系作者删除!