Part IV data search using HBASE API to realize conditional query

Because Mapreduce is required for data cleaning, the problem of hbase should be solved first. You can use the command to save simple data in hbase for query, and then just replace the data to realize the original function

Before looking at this section, make sure that Hase API Yes, I understand a little

subject

  1. Use the HBASE API to realize the condition query function. The details are as follows:

(1) Search for access records during this period based on the start time and end time. Input information is start time and end time, separated by '|' character)

(2) Search the user's access record according to the user ID. The input information is one or more user IDs separated by '|' characters (and)

(3) Search the user query term record containing the keyword according to the keyword. The input information is one or more keywords separated by '|' characters (intersection)

(4) Search the URL access records of relevant websites according to keywords (such as baidu). The input information is one or more keywords separated by '|'

(5) Realize the union search of any combination of the above four conditions. The four conditions are separated by '+' characters (joint search requires all conditions to be met at the same time)

analysis

After careful analysis, the five topics are very similar, that is, the filter knowledge is used, and the code is very similar.

CompareFilter.CompareOp.
LESS  <
LESS_OR_EQUAL <=
EQUAL =
NOT_EQUAL <>
GREATER_OR_EQUAL >=
GREATER >

Take (4) as an example

public static void selectURLs(String[] urls) throws IOException {
    //Filter connection MUST_PASS_ALL(and) MUST_PASS_ONE(or)
    FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
    //Create a single column value filter
    for(String url:urls){
        SingleColumnValueFilter singleColumnValueFilter =
                new SingleColumnValueFilter(Bytes.toBytes("hc"),Bytes.toBytes("URL"),
                        CompareFilter.CompareOp.EQUAL,new SubstringComparator(url));
        //Add to filter
        filterList.addFilter(singleColumnValueFilter);
    }
    Table table = HbaseUtils.getTable(Constants.TABLENAME);
    HbaseUtils.showFilter(table,filterList);
    HbaseUtils.close(table);
}

After analyzing (5), the point of comparison is that you may think of using split to cut

If you enter the condition +1++, the final result is only 1, so you need to cycle the bad string to cut

String[] parts={"","","",""};
int cnt = 0;
for(int i=0;i<line.length();i++){
    if(line.charAt(i)!='+'){
        parts[cnt]+=line.charAt(i);
    }else{
        cnt++;
    }
}

Posted by b-ware on Tue, 31 May 2022 23:26:17 +0530