HBase 建表API使用

2021-09-07 23:08:31 字數 1919 閱讀 4421

string table = "table";

configuration conf = hbaseconfiguration.create();

connection conn = connectionfactory.createconnection(conf);

admin admin = conn.getadmin();

//刪除指定的表要先disable,然後在刪除

admin.disabletable(tablename.valueof(table));

admin.deletetable(tablename.valueof(table));

//建立表,設定指定的屬性值

storeengine是在2.0以後的版本才有的

//設定列族的屬性

columnfamilydescriptor columnfamilydescriptor = columnfamilydescriptorbuilder.newbuilder("cf".getbytes())

.setcompresstags(true)

.setinmemorycompaction(memorycompactionpolicy.adaptive)

.setminversions(2)

.settimetolive(60 * 60 * 24 * 7)

.setvalue("hbase.hstore.engine.class","org.apache.hadoop.hbase.regionserver.datetieredstoreengine")

.setvalue("hbase.hstore.blockingstorefiles","60")

.setvalue("hbase.hstore.compaction.min","2")

.setvalue("hbase.hstore.compaction.max","60")

.build();

//設定表的屬性

tabledescriptor td = tabledescriptorbuilder.newbuilder(tablename.valueof(table))

.setmemstoreflushsize(256 * 1024 * 1024)

.setcolumnfamily(columnfamilydescriptor)

.setcompactionenabled(true)

.setmaxfilesize(1024 * 1024 * 1024)

.setvalue("hbase.hstore.engine.class","org.apache.hadoop.hbase.regionserver.datetieredstoreengine")

.setvalue("hbase.hstore.blockingstorefiles","60")

.setvalue("hbase.hstore.compaction.min","2")

.setvalue("hbase.hstore.compaction.max","60")

.setvalue("blocksize","65536").build();

//設定預分割槽的值,rowkey安裝字典序列排序,目前是按照開頭數字是1-9分成10個分割槽

byte splitkeys = ;

//建立表

admin.createtable(td,splitkeys);

最後在webui上檢視表的描述狀態如下:

region的資訊如下:

在三颱機器上的分布如下:

HBASE 預分割槽建表

在create乙個表時如果不指定預分配region,則缺省會先分配乙個region,這樣在大資料並行載入時效能比較低,因為所有的資料都往乙個region灌入,容易引起單節點負載公升高,從而影響入庫效能,乙個好的方法時在建立表時預先分配數個region。方法有兩種,主要針對不同版本可供選擇。1.使用r...

HBase(09) HBase 建表高階屬性

預設情況下,在建立hbase表的時候會自動建立乙個region分割槽,當匯入資料的時候,所有的hbase客戶端都向這乙個region寫資料,直到這個region足夠大了才進行切分。一種可以加快批量寫入速度的方法是通過預先建立一些空的regions,這樣當資料寫入hbase時,會按照region分割槽...

Hbase之建表高階應用 1

1 bloomfilter 預設是none 是否使用布隆過慮及使用何種方式 布隆過濾可以每列族單獨啟用。使用 hcolumndescriptor.setbloomfiltertype none row rowcol 對列族單獨啟用布隆。2 versions 預設是1 這個引數的意思是資料保留1個 版...