Skip to content

Commit 86dd7db

Browse files
committed
第一次提交
0 parents  commit 86dd7db

16 files changed

Lines changed: 1322 additions & 0 deletions

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/
32+
33+
.mvn/

pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.common.data.hbase.read</groupId>
8+
<artifactId>hbase-read-alone</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>8</maven.compiler.source>
13+
<maven.compiler.target>8</maven.compiler.target>
14+
<msgpack.version>0.8.20</msgpack.version>
15+
<jackson.version>2.9.10</jackson.version>
16+
<hadoop.version>2.10.1</hadoop.version>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.msgpack</groupId>
22+
<artifactId>msgpack-core</artifactId>
23+
<version>${msgpack.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.fasterxml.jackson.core</groupId>
27+
<artifactId>jackson-databind</artifactId>
28+
<version>${jackson.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.apache.hadoop</groupId>
32+
<artifactId>hadoop-client</artifactId>
33+
<version>${hadoop.version}</version>
34+
<exclusions>
35+
<exclusion>
36+
<groupId>javax.servlet</groupId>
37+
<artifactId>servlet-api</artifactId>
38+
</exclusion>
39+
<exclusion>
40+
<groupId>com.sun.jersey</groupId>
41+
<artifactId>jersey-core</artifactId>
42+
</exclusion>
43+
<exclusion>
44+
<groupId>com.sun.jersey</groupId>
45+
<artifactId>jersey-client</artifactId>
46+
</exclusion>
47+
</exclusions>
48+
49+
</dependency>
50+
<dependency>
51+
<groupId>org.apache.hbase</groupId>
52+
<artifactId>hbase-client</artifactId>
53+
<version>2.1.10</version>
54+
</dependency>
55+
56+
57+
58+
</dependencies>
59+
60+
</project>

readme.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
使用这个库,读取HBase时可以像JPB的方式一样去获取数据,使用api相关的工程
2+
3+
使用教程
4+
5+
1、使用前的准备要配置好HBase 集群的连接
6+
7+
2、配置仓库地址
8+
9+
[![](https://jitpack.io/v/WTree/HBase-Reader.svg)](https://jitpack.io/#WTree/HBase-Reader)
10+
11+
```
12+
<repositories>
13+
<repository>
14+
<id>jitpack.io</id>
15+
<url>https://jitpack.io</url>
16+
</repository>
17+
</repositories>
18+
19+
20+
21+
<dependency>
22+
<groupId>com.github.WTree</groupId>
23+
<artifactId>HBase-Reader</artifactId>
24+
<version>v0.1</version>
25+
</dependency>
26+
27+
```
28+
29+
3、配置要读取的实体
30+
31+
```
32+
@HBaseInfo(tableName = "product", tableNameSpace = "ay")
33+
public class ProductInfo implements IFieldCheck, Serializable {
34+
35+
@HBaseFieldName(PackType = EnumPack.PACK_BYTES, HBaseKey = "i")
36+
private String id;
37+
38+
@HBaseFieldName(PackType = EnumPack.PACK_BYTES, HBaseKey = "t")
39+
private String title;
40+
41+
@HBaseFieldName(PackType = EnumPack.PACK_BYTES, HBaseKey = "p")
42+
private String price;
43+
44+
//这个为了允许实体里面的部分字段为空
45+
@Override
46+
public boolean isEmptyValue() {
47+
return StringUtils.isEmpty(id);
48+
}
49+
50+
```
51+
52+
4、读取
53+
54+
```
55+
byte[] rowKey = DigestUtils.sha1Hex("34514").getBytes();
56+
//这个callBack是为了只读取部分字段而设置的
57+
IGetFieldCallBack callBack = () -> new String[]{"id", "price"};
58+
//getConnection() 自己集群的连接池
59+
ProductInfo info = HBaseReadHelper.read(getConnection(), ProductInfo.class, callBack, rowKey);
60+
61+
//如果想把几个想读的字段直接转成JSON 对象,可以使用这个
62+
BeanFactoryInterceptorHelper.intercept(info, callBack.fieldValue())
63+
64+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.common.data.hbase.read;
2+
3+
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
5+
6+
/**
7+
* @author wtree
8+
*/
9+
public abstract class AbstractHBaseInfo {
10+
11+
@JsonIgnore
12+
private byte[] row;
13+
14+
/**
15+
* 优先获取这里的字段
16+
*/
17+
@JsonIgnore
18+
private String tableName;
19+
20+
public byte[] getRow() {
21+
return row;
22+
}
23+
24+
public void setRow(byte[] row) {
25+
this.row = row;
26+
}
27+
28+
public String getTableName() {
29+
return tableName;
30+
}
31+
32+
public void setTableName(String tableName) {
33+
this.tableName = tableName;
34+
}
35+
}

0 commit comments

Comments
 (0)