In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Https://github.com/zhang-xzhi/simplehbase/
Https://github.com/zhang-xzhi/simplehbase/wiki
Simplehbase is a lightweight middleware between java and hbase.
It mainly includes the following functions.
* data type mapping: data conversion between java type and bytes of hbase.
* simple operation encapsulation: put,get,scan and other operations such as hbase are encapsulated as simple java operations.
* hbase query encapsulation: filter encapsulated with hbase. You can use sql-like to operate hbase.
* dynamic query encapsulation: similar to myibatis, you can use xml configuration dynamic statements to query hbase.
* insert,update support: based on hbase's checkAndPut.
* hbase multi-version support: provides an API to query and map hbase multi-version data.
* hbase native APIs are supported.
# # simplehbase example (SampleMain.java)
# use simplehbaseclient to operate hbase
SimpleHbaseClient simpleHbaseClient = getSimpleHbaseClient ()
/ / insert one record.
Person one = new Person ()
One.setId (1)
One.setName ("allen")
One.setAge (30)
One.setGender (Gender.MALE)
SimpleHbaseClient.putObject (new PersonRowKey (1), one)
/ / insert another record.
Person two = new Person ()
Two.setId (2)
Two.setName ("dan")
Two.setAge (31)
Two.setGender (Gender.FEMALE)
SimpleHbaseClient.putObject (new PersonRowKey (2), two)
/ / search by row key.
Person result = simpleHbaseClient.findObject (new PersonRowKey (1)
Person.class)
Log.info (result)
/ / search by range.
List resultList = simpleHbaseClient.findObjectList (
New PersonRowKey (1), new PersonRowKey (3), Person.class)
Log.info (resultList)
/ / HQL query.
Map para = new HashMap ()
Para.put ("id", 1)
ResultList = simpleHbaseClient.findObjectList (new PersonRowKey (1)
New PersonRowKey (3), Person.class, "queryById", para)
Log.info (resultList)
/ / dynamic HQL.
Para.put ("name", "allen")
Para.put ("age", 0)
ResultList = simpleHbaseClient.findObjectList (new PersonRowKey (1)
New PersonRowKey (3), Person.class, "queryByNameAndAge", para)
Log.info (resultList)
/ / batch delete.
SimpleHbaseClient.deleteObjectList (new PersonRowKey (0)
New PersonRowKey, Person.class)
# initialize simplehbase
HBaseDataSource hbaseDataSource = new HBaseDataSource ()
List hbaseConfigResources = new ArrayList ()
/ / If run on hbase cluster, modify the following config files.
/ / If run on hbase stand alone mode, comment out the following config files.
HbaseConfigResources.add (new CachedFileSystemResource (
"sample\\ hbase_site"))
HbaseConfigResources
.add (new CachedFileSystemResource ("sample\\ zk_conf"))
HbaseDataSource.setHbaseConfigResources (hbaseConfigResources)
HbaseDataSource.init ()
HBaseTableConfig hbaseTableConfig = new HBaseTableConfig ()
/ / simplehbase config file.
HbaseTableConfig.setConfigResource (new CachedFileSystemResource (
"sample\\ myRecord.xml"))
HbaseTableConfig.init ()
SimpleHbaseClient tClient = new SimpleHbaseClientImpl ()
TClient.setHbaseDataSource (hbaseDataSource)
TClient.setHbaseTableConfig (hbaseTableConfig)
Return tClient
# configuring xml for simplehbase
Contains the configuration of htable and 2 dynamic queries
Select where id greaterequal # id#
Name equal # name#
Age greater # age#
Select where id equal # id#
# define DO object
@ HBaseTable (defaultFamily = "MyRecordFamily")
Public class Person {
@ HBaseColumn (qualifier = "id")
Private int id
@ HBaseColumn (qualifier = "name")
Private String name
@ HBaseColumn (qualifier = "date")
Private Date date
@ HBaseColumn (qualifier = "gender")
Private Gender gender
@ HBaseColumn (qualifier = "age")
Private int age
}
# define the rowkey corresponding to the DO object
Public class PersonRowKey implements RowKey {
Private int row
Public PersonRowKey (int row) {
This.row = row
}
@ Override
Public byte [] toBytes () {
Return Bytes.toBytes (row)
}
}
Instructions for using simphbase simplehbaseviewer
# simplehbase/simplehbaseviewer version
0.5.1 / 0.6 / 0.7
# jdk
Jdk/jre 1.6
# maven
Maven2
# Code download
Download the latest simplehbase code.
Https://github.com/zhang-xzhi/simplehbase
Download zip in the lower right corner.
Download the simplehbase version with the version.
Https://github.com/zhang-xzhi/simplehbase/releases
Download the latest simplehbaseviewer code.
Https://github.com/zhang-xzhi/simplehbaseviewer
Download zip in the lower right corner.
Download the simplehbaseviewer version with the version.
Https://github.com/zhang-xzhi/simplehbaseviewer/releases
# Simplehbase local verification
After the code is downloaded, it is imported into eclipse after mvn eclipse:eclipse.
Test that runs simplehbase. (Junit)
Currently, the default test environment for simplehbase is
Hbase.zookeeper.quorum=hbdev-1.alipay.net,hbdev-2.alipay.net,hbdev-3.alipay.net,hbdev-4.alipay.net,hbdev-5.alipay.net
Hbase.zookeeper.property.clientPort=2181
Zookeeper.znode.parent=/hbase-94
* 1 if you cannot connect, modify the test/zk_conf file (used by the integration test, modify the sample/zk_conf file (used by the sample program).
* 2 build a test table. Run CreateTestTable to create a new MyRecordV05 table.
* 3 after the table is successfully created, rerun test and run it later. There is no need to re-establish the test table.
* 4 add the configuration of htable. Please refer to the configuration of the existing table.
# Simplehbaseviewer local verification
Install simplehbase to the local warehouse.
In the simplehbase project, mvn install.
After the simplehbaseviewer code is downloaded, it is imported into eclipse after mvn eclipse:eclipse.
Run Main.
Visit http://localhost:4040/hbaseviewer/
See if simplehbaseview starts properly.
Currently, the default test environment for simplehbaseviewer is
Hbase.zookeeper.quorum=hbdev-1.alipay.net,hbdev-2.alipay.net,hbdev-3.alipay.net,hbdev-4.alipay.net,hbdev-5.alipay.net
Hbase.zookeeper.property.clientPort=2181
Zookeeper.znode.parent=/hbase-94
* 1 if you cannot connect, modify the config/zk_conf file.
* 2 build a test table. Run CreateTestTable to create a new MyRecordV05 table.
* 3 after the table is successfully created, rerun Main.
# Simplehbase jar package dependency
Pom dependency, please refer to simplehbase's pom file.
Among them, hadoop and hbase can be modified to the version currently used by the group hbase.
The version of hbase used in Simplehbase development and testing is 0.94.0.
In theory, hbase0.92 can also be used, but without testing, you can run test to test it.
# Simplehbaseclient configuration
SimpleHbaseClient is the core interface of simplehbase.
For more information on Java configuration, please see simplehbase's SampleMain.
For Spring configuration, please refer to simplehbaseviewer's
\ hbaseviewer\ WEB-INF\ spring\ simplehbase.xml
You can refer to or view the code directly for how to configure:
Https://github.com/zhang-xzhi/si... -% E9%85%8D%E7%BD%AE
# doc
* https://github.com/zhang-xzhi/simplehbase/wiki
* https://github.com/zhang-xzhi/simplehbaseviewer/wiki
* simplehbase\ doc after simplehbase download
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.