Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

TestFilter.java

By: nneverwei on Feb 22nd, 2012  |  syntax: Java 5  |  size: 1.83 KB  |  views: 78  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.io.DataInput;
  2. import java.io.DataOutput;
  3. import java.io.IOException;
  4.  
  5. import org.apache.hadoop.hbase.KeyValue;
  6. import org.apache.hadoop.hbase.filter.Filter;
  7. import org.apache.hadoop.hbase.filter.FilterBase;
  8. import org.apache.hadoop.hbase.util.Bytes;
  9.  
  10. /**
  11.  * Test Filter<br/>
  12.  * @author weic
  13.  * @version 1.0 Feb 22, 2012
  14.  * @see
  15.  */
  16. public class TestFilter extends FilterBase implements Filter{
  17.        
  18.         /**
  19.          * Default constructor, filters nothing. Required though for RPC
  20.          * deserialization.
  21.          */
  22.         public TestFilter(){
  23.                 super();
  24.         }
  25.        
  26.         @Override
  27.         public ReturnCode filterKeyValue(KeyValue v) {
  28.                 System.out.println("[filterKeyValue] family:" + Bytes.toString(v.getFamily()) + "|qualifier:" + Bytes.toString(v.getQualifier()) + "|value:" + Bytes.toStringBinary(v.getValue()));
  29.                 ReturnCode code = super.filterKeyValue(v);
  30.                 if(code == ReturnCode.INCLUDE){
  31.                         //once get a kv, jump to next row
  32.                         System.out.println("[filterKeyValue] ReturnCode is: " + ReturnCode.NEXT_ROW);
  33.                         return ReturnCode.NEXT_ROW;
  34.                 }else{
  35.                         System.out.println("[filterKeyValue] ReturnCode is: " + code.name());
  36.                         return code;
  37.                 }
  38.         }
  39.        
  40.         @Override
  41.         public boolean filterRow() {
  42.                 boolean filterRow = super.filterRow();
  43.                 System.out.println("[filterRow] filterOutRow:" + filterRow);
  44.                 return filterRow;
  45.         }
  46.        
  47.         @Override
  48.         public boolean filterRowKey(byte[] rowKey, int offset, int length) {
  49.                 System.out.println("[filterRowKey]" + Bytes.toStringBinary(rowKey));
  50.                 return super.filterRowKey(rowKey, offset, length);
  51.         }
  52.        
  53.         @Override
  54.         public void reset() {
  55.                 System.out.println("[reset]");
  56.                 super.reset();
  57.         }
  58.  
  59.         @Override
  60.         public void write(DataOutput out) throws IOException {
  61.                 // TODO Auto-generated method stub
  62.         }
  63.  
  64.         @Override
  65.         public void readFields(DataInput in) throws IOException {
  66.                 // TODO Auto-generated method stub
  67.         }
  68. }
clone this paste RAW Paste Data