public static void Main (string[] args) throws IOException {//scan class Common method description//Specify required family or column, if no add is called Family or column, will return all columns;//scan.addfamily (); Scan.addcolumn (); Scan.setmaxversions (); Specifies the maximum number of versions. If you call setmaxversions without any arguments, it means that all versions are taken. If you do not drop the setmaxversions, only the latest version will be taken. Scan.settimerange (); Specifies the maximum timestamp and the minimum timestamp that can be obtained only by the cell within this range. Scan.settimestamp (); Specify time stamp//Scan.setfilter (); Specify filter to filter out unwanted information//Scan.setstartrow (); Specifies the starting line. If not called, start from the table header;//Scan.setstoprow (); Specify the end of the line (not including this line);//Scan.setbatch (); Specifies the maximum number of cells to return. Used to prevent excessive data in a row, resulting in outofmemory errors. Filter//1, filterlist represents a filter list//filterlist.operator.must_pass_all-->and//filterlist.operator.mus T_pass_one-->or//eg, filterlist list = new filterlist (FilterList.Operator.MUST_PASS_ONE); 2, Singlecolumnvaluefilter//3, Columnprefixfilter for specifying column name prefix values equal//4, Multiplecolumnprefixfilter and COlumnprefixfilter behaves the same, but multiple prefixes can be specified. 5. Qualifierfilter is a filter based on the column name. 6, RowFilter//7, Regexstringcomparator is a comparator that supports regular expressions. 8, Substringcomparator is used to detect whether a substring exists in the value, case insensitive. Htable table= (htable) Gethtablepool (). GetTable ("Tb_stu"); Scan scan=new scan (); Scan.setmaxversions (); Specifies the maximum number of cells to return. Used to prevent excessive data in a row, resulting in outofmemory errors. Scan.setbatch (1000); Scan.settimestamp (Numberutils.tolong ("1370336286283")); Scan.settimerange (Numberutils.tolong ("1370336286283"), Numberutils.tolong ("1370336337163")); Scan.setstartrow (Bytes.tobytes ("Quanzhou")); Scan.setstoprow (Bytes.tobytes ("Xiamen")); Scan.addfamily (bytes.tobytes ("info")); Scan.addcolumn (bytes.tobytes ("info"), bytes.tobytes ("id")); Query column arrowheads is info, column ID value is 1 Records//method one (single query)//filter filter = new Singlecolumnvaluefilter (//Bytes.to Bytes ("info"), bytes.tobytes ("id"), compareop.equal, Bytes.tobytes ("1")); Scan.setfilter (filter); Method two (combination query)//filterlist filterlist=new filterlist (); Filter filter = new Singlecolumnvaluefilter (//Bytes.tobytes ("info"), bytes.tobytes ("id"), compareop.equal, B Ytes.tobytes ("1")); Filterlist.addfilter (filter); Scan.setfilter (filterlist); Resultscanner rs = table.getscanner (scan); for (Result R:rs) {for (KeyValue Kv:r.raw ()) {System.out.println (String.Format ("row:%s, FA mily:%s, qualifier:%s, qualifiervalue:%s, timestamp:%s., Bytes.tostring (Kv.getrow ()), Bytes.tostring (kv.getfamily ()), bytes.tostring (Kv.getqualifier ()), Bytes.tostring (Kv.getvalue ()), Kv.gettimestamp ()); }} rs.close (); }
Methods of Hbase Scan