Copyright © 2022-2025 aizws.net · 网站版本: v1.2.6·内部版本: v1.25.2·
页面加载耗时 0.00 毫秒·物理内存 145.0MB ·虚拟内存 1438.6MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
列表是用于列出HBase中所有表的命令。下面给出的是list命令的语法。
hbase(main):001:0 > list
当您输入此命令并在HBase提示符下执行时,它将显示HBase中所有表的列表,如下所示。
hbase(main):001:0> list TABLE emp
在这里你可以观察一个名为emp的表。
按照以下步骤使用Java API获取HBase中的表的列表。
你有一个方法叫 listTables() 在类 HBaseAdmin 获得在HBase的所有表的列表。此方法返回一个 HTableDescriptor 对象数组。
//creating a configuration object Configuration conf = HBaseConfiguration.create(); //Creating HBaseAdmin object HBaseAdmin admin = new HBaseAdmin(conf); //Getting all the list of tables using HBaseAdmin object HTableDescriptor[] tableDescriptor = admin.listTables();
您可以使用 HTableDescriptor 类的长度变量获取 HTableDescriptor [] 数组的长度。使用 getNameAsString() 方法从此对象获取表的名称。使用这些循环运行'for'循环,并获取HBase中的表格列表。
下面给出的是使用Java API列出HBase中所有表的程序。
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class ListTables {
public static void main(String args[])throws MasterNotRunningException, IOException{
// Instantiating a configuration class
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class
HBaseAdmin admin = new HBaseAdmin(conf);
// Getting all the list of tables using HBaseAdmin object
HTableDescriptor[] tableDescriptor = admin.listTables();
// printing all the table names.
for (int i=0; i<tableDescriptor.length;i++ ){
System.out.println(tableDescriptor[i].getNameAsString());
}
}
}
编译并执行上述程序,如下所示。
$javac ListTables.java $java ListTables
以下应该是输出:
User emp
1. 使用HBase Shell禁用表要删除表格或更改其设置,您需要先使用disable命令禁用表格。您可以使用enable命令重新启用它。下面给出的是禁用表的语法:disable ‘emp’范例 ...