八、HBase列出表

编程入门 行业动态 更新时间:2024-10-26 04:21:03

八、<a href=https://www.elefans.com/category/jswz/34/1763617.html style=HBase列出表"/>

八、HBase列出表

list 是用来列出HBase中所有表的命令。下面给出了 list 命令的语法。

hbase(main):001:0 > list

当输入这个命令,并在HBase提示符下执行,它会显示HBase中的所有表的列表,如下图所示。

hbase(main):001:0> list
TABLE
emp

在这里,可以看到一个名为表emp。

使用Java API列出表

按照下面给出的步骤来使用Java API从HBase获得表的列表。

第1步

在类HBaseAdmin中有一个方法叫 listTables(),列出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();

第1步

就可以得到使用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 classConfiguration conf = HBaseConfiguration.create();// Instantiating HBaseAdmin classHBaseAdmin admin = new HBaseAdmin(conf);// Getting all the list of tables using HBaseAdmin objectHTableDescriptor[] 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

更多推荐

八、HBase列出表

本文发布于:2024-02-12 20:15:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1689258.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HBase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!