提交 ef7fa71a 编写于 作者: A alphg 提交者: GitHub

Add files via upload

上级 68308387
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.study</groupId>
<artifactId>hbase.bitcomparator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hbase.bitcomparator</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
</dependencies>
</project>
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This file contains protocol buffers that are used for filters
option java_package = "com.study.hbase.bitcomparator.core.protos";
option java_outer_classname = "RowKeyBitProtos";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
option optimize_for = SPEED;
// This file contains protocol buffers that are used for comparators (e.g. in filters)
message RowKeyBitComparator {
required fixed32 md5urlhash = 1;
required fixed32 sitecodehash = 2;
required fixed32 status=3;
required fixed32 code=4;
required fixed32 sdate=5;
required fixed32 type=6;
required fixed32 free=7;
required fixed32 close=8;
required fixed32 queue=9;
required fixed32 scantype=10;
}
{ "_id" : { "$oid" : "584a6e030cf29ba18da2fcd5"} , "url" : "http://www.nmlc.gov.cn/zsyz.htm" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 404 , "stime" : 1481272834722 , "sdate" : 20161209 , "sitecode" : "1509250008" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272835222} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 1 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf224463e76c162"} , "url" : "http://www.xzxzzx.gov.cn:8000/wbsprj/indexlogin.do" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 503 , "stime" : 1481272828174 , "sdate" : 20161209 , "sitecode" : "3203000002" , "ip" : "10.117.8.89" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834887} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf27d1a31f617e0"} , "url" : "http://www.nmds.gov.cn/portal/bsfw/nsfd/list_1.shtml" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 404 , "stime" : 1481272822971 , "sdate" : 20161209 , "sitecode" : "15BM010001" , "ip" : "10.162.86.176" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834846} , "free" : 0 , "close" : 0 , "queue" : 0 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf29ba18da2fcd4"} , "url" : "http://beijing.customs.gov.cn/publish/portal159/tab60561/" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 503 , "stime" : 1481272832559 , "sdate" : 20161209 , "sitecode" : "bm28020001" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834766} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf29ba18da2fcd3"} , "url" : "http://www.nss184.com/web2/newlist_index.aspx?classid=1" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 404 , "stime" : 1481272826788 , "sdate" : 20161210 , "sitecode" : "BT10000001" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834732} , "free" : 0 , "close" : 1 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf2847bb13af52c"} , "url" : "http://cgw.bjdch.gov.cn/n1569/n4860273/n9719314/index.html" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 503 , "stime" : 1481272803601 , "sdate" : 20161208 , "sitecode" : "1101010059" , "ip" : "10.117.187.7" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834150} , "free" : 1 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf29ba18da2fcd2"} , "url" : "http://www.qdn.gov.cn/zwdt/ztfw/shbzfw.htm" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 404 , "stime" : 1481272833479 , "sdate" : 20161209 , "sitecode" : "5226000038" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834046} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e010cf29ba18da2fcd1"} , "url" : "http://www.caac.gov.cn/E1/E2/" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 404 , "stime" : 1481272833297 , "sdate" : 20161209 , "sitecode" : "bm70000001" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272833723} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e010cf22c906fb6f846"} , "url" : "http://www.ny.xwie.com/Thought/" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 404 , "stime" : 1481272821713 , "sdate" : 20161209 , "sitecode" : "4408250003" , "ip" : "10.168.156.196" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272833498} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e010cf29ba18da2fcd0"} , "url" : "http://www.guoluo.gov.cn/html/1746/List.html" , "md5url" : "e353cd577fd721eb71538d0938d041f7" , "status" : -1 , "code" : 404 , "stime" : 1481272832723 , "sdate" : 20161209 , "sitecode" : "6326000004" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272833472} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e030cf29ba18da2fcd5"} , "url" : "http://www.nmlc.gov.cn/zsyz.htm" , "md5url" : "ea67a96f233d6fcfd7cabc9a6a389283" , "status" : -1 , "code" : 404 , "stime" : 1481272834722 , "sdate" : 20161209 , "sitecode" : "1509250008" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272835222} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 1 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf224463e76c162"} , "url" : "http://www.xzxzzx.gov.cn:8000/wbsprj/indexlogin.do" , "md5url" : "fd38c0fb8f6e839be56b67c69ad2baa5" , "status" : -1 , "code" : 503 , "stime" : 1481272828174 , "sdate" : 20161209 , "sitecode" : "3203000002" , "ip" : "10.117.8.89" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834887} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf27d1a31f617e0"} , "url" : "http://www.nmds.gov.cn/portal/bsfw/nsfd/list_1.shtml" , "md5url" : "d51abcd8edff79d23ca4a9a0576a1996" , "status" : -1 , "code" : 404 , "stime" : 1481272822971 , "sdate" : 20161209 , "sitecode" : "15BM010001" , "ip" : "10.162.86.176" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834846} , "free" : 0 , "close" : 0 , "queue" : 0 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf29ba18da2fcd4"} , "url" : "http://beijing.customs.gov.cn/publish/portal159/tab60561/" , "md5url" : "e27bbc9192e760bacc23c226ffd90219" , "status" : -1 , "code" : 503 , "stime" : 1481272832559 , "sdate" : 20161209 , "sitecode" : "bm28020001" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834766} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf29ba18da2fcd3"} , "url" : "http://www.nss184.com/web2/newlist_index.aspx?classid=1" , "md5url" : "cbc2c0571464621024c89aa019cd09ef" , "status" : -1 , "code" : 404 , "stime" : 1481272826788 , "sdate" : 20161210 , "sitecode" : "BT10000001" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834732} , "free" : 0 , "close" : 1 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf2847bb13af52c"} , "url" : "http://cgw.bjdch.gov.cn/n1569/n4860273/n9719314/index.html" , "md5url" : "00a18048ed95f1c057fccc8928ddf610" , "status" : -1 , "code" : 503 , "stime" : 1481272803601 , "sdate" : 20161208 , "sitecode" : "1101010059" , "ip" : "10.117.187.7" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834150} , "free" : 1 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e020cf29ba18da2fcd2"} , "url" : "http://www.qdn.gov.cn/zwdt/ztfw/shbzfw.htm" , "md5url" : "e6bfa0a07e773e3bab27a37f36ff221a" , "status" : -1 , "code" : 404 , "stime" : 1481272833479 , "sdate" : 20161209 , "sitecode" : "5226000038" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272834046} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e010cf29ba18da2fcd1"} , "url" : "http://www.caac.gov.cn/E1/E2/" , "md5url" : "e6217482388cbc57aa80422c3f64bb35" , "status" : -1 , "code" : 404 , "stime" : 1481272833297 , "sdate" : 20161209 , "sitecode" : "bm70000001" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272833723} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e010cf22c906fb6f846"} , "url" : "http://www.ny.xwie.com/Thought/" , "md5url" : "b7912f3bdb50be7b58f5a67d65273201" , "status" : -1 , "code" : 404 , "stime" : 1481272821713 , "sdate" : 20161209 , "sitecode" : "4408250003" , "ip" : "10.168.156.196" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272833498} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
{ "_id" : { "$oid" : "584a6e010cf29ba18da2fcd0"} , "url" : "http://www.guoluo.gov.cn/html/1746/List.html" , "md5url" : "e353cd577fd721eb71538d0938d041f7" , "status" : -1 , "code" : 404 , "stime" : 1481272832723 , "sdate" : 20161209 , "sitecode" : "6326000004" , "ip" : "10.168.106.153" , "port" : 5200 , "type" : 2 , "intime" : { "$date" : 1481272833472} , "free" : 0 , "close" : 0 , "queue" : 1 , "scantype" : 0 , "scanmemo" : ""}
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://192.168.0.202:9000/hbase</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>192.168.0.202</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
</configuration>
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
package com.study.hbase.bitcomparator.core;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.filter.ByteArrayComparable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.log4j.Logger;
import com.google.protobuf.InvalidProtocolBufferException;
import com.study.hbase.bitcomparator.core.protos.RowKeyBitProtos;
/**
*
* @author 410s
*
*/
public class RowKeyEqualComparator extends ByteArrayComparable{
Logger logger=Logger.getLogger(RowKeyEqualComparator.class);
protected byte[] data;
protected byte[] templete=null;
public RowKeyEqualComparator(byte[] value) {
super(value);
this.data=value;
if(this.templete==null)
{
logger.info("hahahahahahahahhaha1");
templete=Bytes.copy(this.data);
for(int i=0;i<templete.length;i=i+4){
int k=Bytes.toInt(templete,i,4);
if(k!=0){
for(int j=0;j<4;j++){
templete[i+j]|=0xff;
}
}
}
}else{
logger.info("dadadadadadada2");
}
}
@Override
public byte[] toByteArray() {
RowKeyBitProtos.RowKeyBitComparator.Builder builder=
RowKeyBitProtos.RowKeyBitComparator.newBuilder();
int md5urlHash=Bytes.toInt(this.data, 0, 4);
int siteCodeHash=Bytes.toInt(this.data,4,4);
int status=Bytes.toInt(this.data,8,4);
int code=Bytes.toInt(this.data,12,4);
int sdate=Bytes.toInt(this.data,16,4);
int type=Bytes.toInt(this.data,20,4);
int free=Bytes.toInt(this.data,24,4);
int close=Bytes.toInt(this.data,28,4);
int gueue=Bytes.toInt(this.data,32,4);
int scantype=Bytes.toInt(this.data,36,4);
builder.setMd5Urlhash(md5urlHash);
builder.setSitecodehash(siteCodeHash);
builder.setStatus(status);
builder.setCode(code);
builder.setSdate(sdate);
builder.setType(type);
builder.setFree(free);
builder.setClose(close);
builder.setQueue(gueue);
builder.setScantype(scantype);
return builder.build().toByteArray();
}
public static RowKeyEqualComparator parseFrom(final byte[] bytes) throws DeserializationException{
RowKeyBitProtos.RowKeyBitComparator proto=null;
try{
proto=RowKeyBitProtos.RowKeyBitComparator.parseFrom(bytes);
int md5urlHash=proto.getMd5Urlhash();
int siteCodeHash=proto.getSitecodehash();
int status=proto.getStatus();
int code=proto.getCode();
int sdate=proto.getSdate();
int type=proto.getType();
int free=proto.getFree();
int close=proto.getClose();
int queue=proto.getQueue();
int scantype=proto.getScantype();
byte[][] bs={
Bytes.toBytes(md5urlHash),
Bytes.toBytes(siteCodeHash),
Bytes.toBytes(status),
Bytes.toBytes(code),
Bytes.toBytes(sdate),
Bytes.toBytes(type),
Bytes.toBytes(free),
Bytes.toBytes(close),
Bytes.toBytes(queue),
Bytes.toBytes(scantype)
};
return new RowKeyEqualComparator(Bytes.add(bs));
}catch (InvalidProtocolBufferException e) {
throw new DeserializationException(e);
}
}
public int compareTo(byte[] value){
return compareTo(value,0,value.length);
}
@Override
public int compareTo(byte[] value, int offset, int length) {
//0 的话相等,大于小于,
if(length!=this.data.length){
return 1;
}
//复制一份data对像,用于修改,注意不可以直接 byte[] tmp=this.data;
byte[] tmp=Bytes.copy(this.data);
//第二步使用过滤模板与rowkey进行 与 操作,并将值存入tmp中
for(int i=templete.length-1;i>=0;i--){
//与操作,过滤不作比较的字段
tmp[i]=(byte) ((templete[i]&value[i+offset])&0xff);
}
//第三步判断是否相同
for(int i=tmp.length-1;i>=0;i--){
if(tmp[i]!=this.data[i])
return 1;
}
return 0;
}
}
package com.study.hbase.bitcomparator.core;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.filter.ByteArrayComparable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.log4j.Logger;
import com.google.protobuf.InvalidProtocolBufferException;
import com.study.hbase.bitcomparator.core.protos.RowKeyBitProtos;
/**
* 判断RowKey中某一段大于或小于某值,注意不能比较大于0或小于0
* 如果构造比较器的值有多段大于0的值则只判断左起第一个不为0的数字
* @author 410s
*
*/
public class RowKeyGLComparator extends ByteArrayComparable{
Logger logger=Logger.getLogger(RowKeyGLComparator.class);
protected byte[] data;
public RowKeyGLComparator(byte[] value) {
super(value);
this.data=value;
}
@Override
public int compareTo(byte[] value) {
return this.compareTo(value, 0, value.length);
}
@Override
public int compareTo(byte[] value, int offset, int length) {
//0 的话相等,大于小于,
if(length!=this.data.length){
return 0;
}
for(int i=0;i<this.data.length;i=i+4){
int k=Bytes.toInt(this.data,i,4);
if(k!=0){
logger.info("tatatata:"+(Bytes.toInt(value,i+offset,4)-k));
return k-Bytes.toInt(value,i+offset,4);
}
}
return 0;
}
@Override
public byte[] toByteArray() {
RowKeyBitProtos.RowKeyBitComparator.Builder builder=
RowKeyBitProtos.RowKeyBitComparator.newBuilder();
int md5urlHash=Bytes.toInt(this.data, 0, 4);
int siteCodeHash=Bytes.toInt(this.data,4,4);
int status=Bytes.toInt(this.data,8,4);
int code=Bytes.toInt(this.data,12,4);
int sdate=Bytes.toInt(this.data,16,4);
int type=Bytes.toInt(this.data,20,4);
int free=Bytes.toInt(this.data,24,4);
int close=Bytes.toInt(this.data,28,4);
int gueue=Bytes.toInt(this.data,32,4);
int scantype=Bytes.toInt(this.data,36,4);
builder.setMd5Urlhash(md5urlHash);
builder.setSitecodehash(siteCodeHash);
builder.setStatus(status);
builder.setCode(code);
builder.setSdate(sdate);
builder.setType(type);
builder.setFree(free);
builder.setClose(close);
builder.setQueue(gueue);
builder.setScantype(scantype);
return builder.build().toByteArray();
}
public static RowKeyGLComparator parseFrom(final byte[] bytes) throws DeserializationException{
RowKeyBitProtos.RowKeyBitComparator proto=null;
try{
proto=RowKeyBitProtos.RowKeyBitComparator.parseFrom(bytes);
int md5urlHash=proto.getMd5Urlhash();
int siteCodeHash=proto.getSitecodehash();
int status=proto.getStatus();
int code=proto.getCode();
int sdate=proto.getSdate();
int type=proto.getType();
int free=proto.getFree();
int close=proto.getClose();
int queue=proto.getQueue();
int scantype=proto.getScantype();
byte[][] bs={
Bytes.toBytes(md5urlHash),
Bytes.toBytes(siteCodeHash),
Bytes.toBytes(status),
Bytes.toBytes(code),
Bytes.toBytes(sdate),
Bytes.toBytes(type),
Bytes.toBytes(free),
Bytes.toBytes(close),
Bytes.toBytes(queue),
Bytes.toBytes(scantype)
};
return new RowKeyGLComparator(Bytes.add(bs));
}catch (InvalidProtocolBufferException e) {
throw new DeserializationException(e);
}
}
}
package com.study.hbase.bitcomparator.main;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.RowFilter;
import org.apache.hadoop.hbase.util.Bytes;
import com.study.hbase.bitcomparator.core.RowKeyEqualComparator;
import com.study.hbase.bitcomparator.core.RowKeyGLComparator;
import com.study.hbase.bitcomparator.util.HbaseUtil;
import net.sf.json.JSONObject;
public class ConnectionInfo {
private static String tableName = "connectionInfo";
private static String[] families = new String[] { "property" };
private static String fileName = "D:\\Workspace\\eclipse\\hbase.bitcomparator\\resources\\connection.json";
public static void main(String[] args) throws Exception{
//HbaseUtil.dropTable(tableName);
//HbaseUtil.createTable(tableName, families);
//HbaseUtil.insert(tableName, loadConnections());
testEqualSelect();
testGLSelect();
testAll();
}
/**
* 精确查找测试
*
* 查找md5url=00a18048ed95f1c057fccc8928ddf610,siteCode=1101010059,sdate=20161209 的数据
*
* @throws Exception
*/
public static void testEqualSelect() throws Exception{
Table table=HbaseUtil.getHTable(tableName);
Scan scan = new Scan();
List<Filter> filterList = new ArrayList<Filter>();
int md5UrlHash="00a18048ed95f1c057fccc8928ddf610".hashCode();
int siteCodeHash="1101010059".hashCode();
int sdate=20161209;
int status=0;//0;
int code=0;//0;
int type=0;
int free=0;
int close=0;
int queue=0;
int scantype=0;
byte[][] bs={
Bytes.toBytes(md5UrlHash),
Bytes.toBytes(siteCodeHash),
Bytes.toBytes(status),
Bytes.toBytes(code),
Bytes.toBytes(sdate),
Bytes.toBytes(type),
Bytes.toBytes(free),
Bytes.toBytes(close),
Bytes.toBytes(queue),
Bytes.toBytes(scantype)
};
Filter rowFilter=new RowFilter(CompareFilter.CompareOp.EQUAL,new RowKeyEqualComparator(Bytes.add(bs)));
filterList.add(rowFilter);
FilterList fls=new FilterList(filterList);
scan.setFilter(fls);
ResultScanner resultScanner = null;
try {
resultScanner = table.getScanner(scan);
for (Result result : resultScanner) {
System.out.println(Bytes.toString(result.getValue(Bytes.toBytes("property"),Bytes.toBytes("json"))));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (resultScanner != null) {
resultScanner.close();
}
}
}
/**
* 测试范围查找 找查日期大于等于20161209 code小于502 queue小于1的数据
* @throws Exception
*/
public static void testGLSelect() throws Exception{
Table table=HbaseUtil.getHTable(tableName);
Scan scan = new Scan();
List<Filter> filterList = new ArrayList<Filter>();
int md5UrlHash=0;
int siteCodeHash=0;
int sdate=0;
int status=0;
int code=0;
int type=0;
int free=0;
int close=0;
int queue=0;
int scantype=0;
byte[][] bs={
Bytes.toBytes(md5UrlHash),
Bytes.toBytes(siteCodeHash),
Bytes.toBytes(status),
Bytes.toBytes(code),
Bytes.toBytes(20161209),
Bytes.toBytes(type),
Bytes.toBytes(free),
Bytes.toBytes(close),
Bytes.toBytes(queue),
Bytes.toBytes(scantype)
};
byte[][] bs2={
Bytes.toBytes(md5UrlHash),
Bytes.toBytes(siteCodeHash),
Bytes.toBytes(status),
Bytes.toBytes(502),
Bytes.toBytes(sdate),
Bytes.toBytes(type),
Bytes.toBytes(free),
Bytes.toBytes(close),