Skip to content

Commit

Permalink
to add file
Browse files Browse the repository at this point in the history
  • Loading branch information
easesstone committed Jul 12, 2017
1 parent 5fb89e2 commit 83132b3
Show file tree
Hide file tree
Showing 31 changed files with 1,517 additions and 119 deletions.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion ch04/src/main/java/filters/PageFilterExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static void main(String[] args) throws IOException {
Table table = connection.getTable(TableName.valueOf("testtable"));

// vv PageFilterExample
// 逻辑,通过设置每次返回的行数,
// 判断当前页的最后一行是否空
Filter filter = new PageFilter(15);

int totalRows = 0;
Expand All @@ -54,7 +56,7 @@ public static void main(String[] args) throws IOException {
int localRows = 0;
Result result;
while ((result = scanner.next()) != null) {
System.out.println(localRows++ + ": " + result);
// System.out.println(localRows++ + ": " + result);
totalRows++;
lastRow = result.getRow();
}
Expand Down
2 changes: 1 addition & 1 deletion ch04/src/main/java/filters/PrefixFilterExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void main(String[] args) throws IOException {
}
scanner.close();

Get get = new Get(Bytes.toBytes("row-5"));
Get get = new Get(Bytes.toBytes("row-1"));
get.setFilter(filter);
Result result = table.get(get);
// ^^ PrefixFilterExample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void main(String[] args) throws IOException {
Bytes.toBytes("col-5"),
CompareFilter.CompareOp.NOT_EQUAL,
new SubstringComparator("val-5"));
filter.setFilterIfMissing(true);
filter.setFilterIfMissing(false);

Scan scan = new Scan();
scan.setFilter(filter);
Expand Down
15 changes: 15 additions & 0 deletions demoldl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
<artifactId>hadoop-client</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
package ldl_utils;
package com.hzgosun;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;


/**
* Created by lenovo on 2017/6/28.
*/
public class HBaseUtil {
public class HBaseHelper {
private Configuration configuration = null;
private Admin admin = null;
private Connection connection =null;

public HBaseUtil(Configuration configuration) throws IOException {

public Connection getConnection(){
return this.connection;
}
// 构造删除
public HBaseHelper(Configuration configuration) throws IOException {
this.configuration = configuration;
connection = ConnectionFactory.createConnection(configuration);
admin = connection.getAdmin();
}

public BufferedMutator getMutator(String table) throws IOException {
return connection.getBufferedMutator(TableName.valueOf(table));
}

// 判断表格是否存在
public boolean exitTable(String name) throws IOException {
return this.admin.tableExists(TableName.valueOf(name));
}

public static HBaseUtil getHBaseUtils(Configuration configuration) throws IOException {
return new HBaseUtil(configuration);
// 返回HbaseUtil
public static HBaseHelper getHBaseHelper(Configuration configuration) throws IOException {
return new HBaseHelper(configuration);
}
// 删除表
public void dropTable(String name) throws IOException {
Expand All @@ -40,7 +48,8 @@ public void dropTable(String name) throws IOException {

// 删除表
public void dropTable(TableName name) throws IOException {
if (admin.tableExists(name)){
boolean flag = admin.tableExists(name);
if (flag){
if (admin.isTableEnabled(name)){
admin.disableTable(name);
}
Expand All @@ -58,17 +67,27 @@ public void createTable(TableName name, String... colfams) throws IOException {
createTable(name, 1, colfams);
}

// 创建表格
public void createTable(String name, int maxVersions, String... colfams) throws IOException {
createTable(TableName.valueOf(name), maxVersions, colfams);
}

// 创建表格
public void createTable(TableName name, int maxVersions, String... colfams) throws IOException {
boolean flag = admin.tableExists(name);
if (admin.tableExists(name)){
System.out.println("Table exit");
return;
}
HTableDescriptor hTableDescriptor = new HTableDescriptor(name);
for (String colfam:colfams){
HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(colfam);
hColumnDescriptor.setMaxVersions(maxVersions);
hTableDescriptor.addFamily(hColumnDescriptor);
}
// HTableDescriptor descriptor = admin.getTableDescriptor(name);
boolean nima = true;
System.out.println();
admin.createTable(hTableDescriptor);
}

Expand All @@ -77,7 +96,9 @@ public Table getTable(String name) throws IOException {
return this.connection.getTable(TableName.valueOf(name));
}

// 关闭连接
public void close() throws IOException {
admin.close();
connection.close();
}
}
152 changes: 152 additions & 0 deletions demoldl/src/main/java/com/hzgosun/ObjectInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.hzgosun;

import java.util.Arrays;

public class ObjectInfo {
private String id; // rowkey
private String name; // 姓名
private String idcard; // 身份证
private byte sex; // 性别
private byte[] photo; // 照片
private String reason; // 理由
private String pkey; // 人员类型key
private String tag; // 是人还是车
private String creator; // 布控人
private String cphone; // 布控人联系方式
private String createtime; // 创建时间
private String updatetime; // 修改时间

public ObjectInfo() {
}

public ObjectInfo(String id, String name, String idcard, byte sex,
byte[] photo, String reason, String pkey, String tag,
String createtime, String updatetime, String creator, String cphone) {
this.id = id;
this.name = name;
this.idcard = idcard;
this.sex = sex;
this.photo = photo;
this.reason = reason;
this.pkey = pkey;
this.tag = tag;
this.createtime = createtime;
this.updatetime = updatetime;
this.creator = creator;
this.cphone = cphone;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getIdcard() {
return idcard;
}

public void setIdcard(String idcard) {
this.idcard = idcard;
}

public byte getSex() {
return sex;
}

public void setSex(byte sex) {
this.sex = sex;
}

public byte[] getPhoto() {
return photo;
}

public void setPhoto(byte[] photo) {
this.photo = photo;
}

public String getReason() {
return reason;
}

public void setReason(String reason) {
this.reason = reason;
}

public String getPkey() {
return pkey;
}

public void setPkey(String pkey) {
this.pkey = pkey;
}

public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}

public String getCreatetime() {
return createtime;
}

public void setCreatetime(String createtime) {
this.createtime = createtime;
}

public String getUpdatetime() {
return updatetime;
}

public void setUpdatetime(String updatetime) {
this.updatetime = updatetime;
}

public String getCreator() {
return creator;
}

public void setCreator(String creator) {
this.creator = creator;
}

public String getCphone() {
return cphone;
}

public void setCphone(String cphone) {
this.cphone = cphone;
}

@Override
public String toString() {
return "ObjectInfo{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", idcard='" + idcard + '\'' +
", sex=" + sex +
", photo=" + Arrays.toString(photo) +
", reason='" + reason + '\'' +
", pkey='" + pkey + '\'' +
", tag='" + tag + '\'' +
", creator='" + creator + '\'' +
", cphone='" + cphone + '\'' +
", createtime='" + createtime + '\'' +
", updatetime='" + updatetime + '\'' +
'}';
}
}
70 changes: 70 additions & 0 deletions demoldl/src/main/java/com/hzgosun/ObjectInfoHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.hzgosun;

import java.util.List;
import java.util.Map;

public interface ObjectInfoHandler {

/**
* 针对单个对象信息的添加处理
* @param platformId 表示的是平台的ID, 平台的唯一标识。
* @param person K-V 对,里面存放的是字段和值之间的一一对应关系,
* 例如:传入一个Map 里面的值如下map.put("idcard", "450722199502196939")
* 表示的是身份证号(idcard)是450722199502196939,其中的K 的具体,请参考给出的数据库字段设计
* @return 返回值为0,表示插入成功,返回值为1,表示插入失败
*/
public byte addObjectInfo(String platformId, Map<String, String>person);

/**
* 删除对象的信息
* @param Id 具体的一个人员信息的ID,值唯一
* @return 返回值为0,表示删除成功,返回值为1,表示删除失败
*/
public int deleteObjectInfo(String Id);

/**
* 修改对象的信息
* @param person K-V 对,里面存放的是字段和值之间的一一对应关系,参考添加里的描述
* @return返回值为0,表示更新成功,返回值为1,表示更新失败
*/
public int updateObjectInfo(Map<String, String> person);

/**
* 可以匹配精确查找,以图搜索人员信息,模糊查找,关键看输入的是什么内容。
* 如果输入只有一个kv 对,且K 的内容id,则是根据ID 进行查找
* 如果输入只有一个kv 对,且K 的内容是身份证号,则根据身份证号模糊查找
* 如果输入的是一些列的KV 对,则进行模糊查找
* @param platformId 对应的是平台的ID
* @param id 对应的是一个人在HBase 数据库中的唯一标志
* @param image 传过来的图片
* @param threshold 图片比对的阈值
* @param pkeys 人员类型列表
* @param rowClomn 一些列的KV 对,即查找的条件
* @param start 需要返回的起始行
* @param pageSize 需要返回的每页的大小
* @param serachId 搜索Id
* @return 返回一个ObjectSearchResult 对象,里面包含了本次查询ID,查询成功标识,查询照片ID(无照片,此参数为空),结果数,人员信息列表
*/
public ObjectSearchResult getObjectInfo(String platformId, String id, byte[] image, int threshold, List<String> pkeys,
Map<String, String> rowClomn, long start, long pageSize, int serachId);

/**
* 可以只传入一个精确的id ,或者身份证号进行查找,(单个人员的查找)
* @param id 精确的rowkey 或者是身份证id
* @return 返回一个ObjectSearchResult 对象,里面包含了本次查询ID,查询成功标识,查询照片ID(无照片,此参数为空),结果数,人员信息列表
*/
public ObjectSearchResult getObjectInfo(String id);


/**
* 根据搜索Id 重新搜索一遍
* @param paltformId 平台的唯一标识
* @param searchID 搜索ID,即图片的ID,
* @return
*/
public ObjectSearchResult getObjectInfo(String paltformId, String searchID);


// rowkey 的设计: 身份证号+平台id+人员类型Key+ 性别(会超过16个字节,理论上rowkeys 的设计越短越好)
// row
}
Loading

0 comments on commit 83132b3

Please sign in to comment.