package os.hbase.index;
import java.io.IOException;
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.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class HbaseDaoDemo {
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
//Configuration conf = new Configuration();
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum","os-1:2181,os-2:2181,os-3:2181");
//DDL操作用的客户端对象
HBaseAdmin hBaseAdmin = new HBaseAdmin(conf);
TableName cart = TableName.valueOf("cart");
//构建表的描述对象
HTableDescriptor desc = new HTableDescriptor(cart);
//在表描述对象中封装所必须指定的信息
HColumnDescriptor hColumnDescriptor = new HColumnDescriptor("product");
HColumnDescriptor goods = new HColumnDescriptor("goods");
//保存的版本数量
hColumnDescriptor.setMaxVersions(3);
goods.setMaxVersions(2);
//指定列族
desc.addFamily(hColumnDescriptor);
desc.addFamily(goods);
//通过hBaseAdmin客户端将表描述对象所描述的表在hbase集群中创建出来
hBaseAdmin.createTable(desc);
hBaseAdmin.close();
}
}
hbase客户端api--建表
最新推荐文章于 2024-01-23 01:28:37 发布