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();
        }
    
    }
  • 相关阅读:
    中断触发方式的比较(转载)
    extern使用方法详解(转载)
    C#面向对象设计模式纵横谈(视频课程讲师:李建忠) 转载
    软件产品保障
    扩展字段设计
    ASP.NET(5):虚拟路径转换到物理路径的一种实现方法,不用MapPath
    将内容文件输出到测试项目中目录中。
    “”(十六进制值 0x1D)是无效的字符
    A Join extension method for the dynamic Linq
    软件就要做的神形兼备
  • 原文地址:https://www.cnblogs.com/MiraculousB/p/13958111.html
Copyright © 2011-2022 走看看