hbaseAPI 命名空间



    public static void main(String[] args) throws IOException {

        System.setProperty("hadoop.home.dir", "D:\\hadoop-2.6.0-cdh5.15.0");

        //1.设置
        //  zookeeper.znode.parent  /hbase (该节点由自带zk设置的)
        // hbase.zookeeper.quorum   candle   zk集群的ip地址.
        // hbase.zookeeper.property.clientPort    2181  zk的默认的端口 
        Configuration conf = new Configuration();
        conf.set("zookeeper.znode.parent", "/hbase");
        conf.set("hbase.zookeeper.quorum", "can");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        
        //2.和hbase连接
        Connection connection = ConnectionFactory.createConnection(conf);

        //namespace和ddl操作 都是通过Admin
        Admin admin = connection.getAdmin();


        //创建一个命名空间 create_namespace
        //NamespaceDescriptor
        //admin.createNamespace(NamespaceDescriptor.create("candle").build());

        //NamespaceDescriptor.Builder builder = NamespaceDescriptor.create("candle");
        //NamespaceDescriptor build = builder.build();
        //admin.createNamespace(build);

        //删除命名空间
        //admin.deleteNamespace("candle");

        //alter_namespace  添加属性
//        NamespaceDescriptor  nsdt = admin.getNamespaceDescriptor("hadoop");
//        nsdt.setConfiguration("key1", "value1");
//        admin.modifyNamespace(nsdt);

        //删除属性
        NamespaceDescriptor nsdt = admin.getNamespaceDescriptor("hadoop");
        nsdt.removeConfiguration("key1");
        admin.modifyNamespace(nsdt);

       // Map configuration = nsdt.getConfiguration();


        //list_namespace
        NamespaceDescriptor[] namespaceDescriptors = admin.listNamespaceDescriptors();

        for (int i = 0 ; i < namespaceDescriptors.length;i++) {
            String name = namespaceDescriptors[i].getName();
            System.out.println(name);
        }

        //list_namespace_tables 列出命名空间下 所有的表
        //NamespaceDescriptor nsdt = admin.getNamespaceDescriptor("hadoop");
        HTableDescriptor[] htdt =
                admin.listTableDescriptorsByNamespace("hadoop");

        for( HTableDescriptor tmp:htdt) {
            String nameAsString = tmp.getNameAsString();
            System.out.println(nameAsString);
        }

    }

 

你可能感兴趣的:(hbase)