zoukankan      html  css  js  c++  java
  • 列出HBASE所有表的相关信息,如表名、创建时间等。

    import java.io.IOException;
    import java.util.Collection;
    import java.util.Iterator;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.HColumnDescriptor;
    import org.apache.hadoop.hbase.HTableDescriptor;
    import org.apache.hadoop.hbase.TableName;
    import org.apache.hadoop.hbase.client.Admin;
    import org.apache.hadoop.hbase.client.Connection;
    import org.apache.hadoop.hbase.client.ConnectionFactory;
    import org.apache.hadoop.hbase.client.Table;
    
    
    public class A_getAllInfo {
        public static Configuration configuration;
        public static Connection connection;
        public static Admin admin;
        
        /**
         * @param args
         */
        public static void main(String[] args)throws IOException {
            getAllInfo();
            // TODO Auto-generated method stub
    
        }
        //建立连接
        public static void init(){
            configuration  = HBaseConfiguration.create();
            configuration.set("hbase.rootdir","hdfs://localhost:9000/hbase");
            try{
                connection = ConnectionFactory.createConnection(configuration);
                admin = connection.getAdmin();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        //关闭连接
        public static void close(){
            try{
                if(admin != null){
                    admin.close();
                }
                if(null != connection){
                    connection.close();
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        public static void getAllInfo() throws IOException {
            init();
            HTableDescriptor hTableDescriptors[] = admin.listTables();
            for(HTableDescriptor hTableDescriptor :hTableDescriptors){
                System.out.println(hTableDescriptor.getNameAsString());
                Table table = connection.getTable(TableName.valueOf(hTableDescriptor.getNameAsString()));
                HTableDescriptor HTableDes = table.getTableDescriptor();
                Collection<HColumnDescriptor> a = HTableDes.getFamilies();
                Iterator<HColumnDescriptor> it = a.iterator() ;
                while(it.hasNext())
                {
                    HColumnDescriptor next = it.next();
                    System.out.println(next);
                }
                table.close();
            }
            close();
        }
    
    }
  • 相关阅读:
    小技巧
    常用的交互设计软件
    Android studio 使用SVN需要忽略的文件
    android studio 使用SVN 锁定文件,防止别人修改(基于Android studio 1.4 )
    git 和 github 关系?
    Double 数据保留两位小数一:五舍六入
    设计模式
    Java中关于日期类那些方法
    ios 开源免费接口
    华为招聘机试整理5:简单四则运算
  • 原文地址:https://www.cnblogs.com/MiraculousB/p/13958111.html
Copyright © 2011-2022 走看看