Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Hbase

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use Hbase, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.

Compare with MySQL:

1 To create a table, you only need to specify the famly column family. You do not need to specify specific columns and types.

@PostConstruct

public boolean createTable() {

log.info("create table start");

TableName tableName = TableName.valueOf(this.getTableName());

try {

Admin admin = connection.getAdmin();

if (! admin.tableExists(tableName)) {

log.info(tableName.toString() + "is not exist,create it");

HTableDescriptor tdesc = new HTableDescriptor(tableName);

HColumnDescriptor colDesc = new HColumnDescriptor(FAMILY);

tdesc.addFamily(colDesc);

admin.createTable(tdesc);

admin.close();

}

log.info("create table end");

return true;

} catch ( IOException e) {

log.error("create table error {} {}", tableName, e.getLocalizedMessage());

return false;

}

}

2 Storage data format HBASE value All byte[] byte data format storage

Advantages: 1 No need to process data types in advance unified use Bytes.toByte() so storage speed is higher

2 Compared with the original data type, serialized byte[] form storage can save bytes

3 can be based on rowKey range search, this need to rowKey design properly.

@Override

public List getByRange(String start, String end) {

try {

Table table = connection.getTable(TableName.valueOf(getTableName()));

Scan scan = new Scan();

scan.withStartRow(start.getBytes(), true)

.withStopRow(end.getBytes(), true);

ResultScanner scanner = table.getScanner(scan);

List list = new ArrayList();

for (Result result : scanner) {

list.add(getObj(result));

}

return list;

} catch (Exception e) {

log.error("HBase failed to get data in bulk", e);

}

return Collections.emptyList();}

Thank you for reading this article carefully. I hope that the article "How to Use Hbase" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support you a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report