Advertisement
Ladies_Man

filter parsefrom not used

Jan 5th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. import org.apache.hadoop.hbase.Cell;
  2. import org.apache.hadoop.hbase.exceptions.DeserializationException;
  3. import org.apache.hadoop.hbase.filter.Filter;
  4. import org.apache.hadoop.hbase.filter.FilterBase;
  5. import org.apache.hadoop.hbase.util.Bytes;
  6.  
  7. import java.io.IOException;
  8.  
  9. public class CustomFlightFilter extends FilterBase {
  10.     private float delay;
  11.     private boolean remain_cancelled;
  12.     private boolean remove_it;
  13.  
  14.     public CustomFlightFilter() {
  15.         super();
  16.         this.remain_cancelled = true;   //if no parameters then remain cancelled flights
  17.     }
  18.  
  19.     public CustomFlightFilter(float delay) {
  20.         this.delay = delay;
  21.         this.remain_cancelled = false;  //if delay has been set then remove cancelled
  22.     }
  23.  
  24.     @Override
  25.     public ReturnCode filterKeyValue(Cell cell) throws IOException {
  26.         String qualifier = new String(
  27.                 cell.getQualifierArray(),
  28.                 cell.getQualifierOffset(),
  29.                 cell.getQualifierLength());
  30.  
  31.         String value = new String(
  32.                 cell.getValueArray(),
  33.                 cell.getValueOffset(),
  34.                 cell.getValueLength());
  35.  
  36.         if (remain_cancelled) {
  37.             if (qualifier.equals("cancelled")) {
  38.                 if (!value.equals("") && (float) 1 == Float.parseFloat(value)) {
  39.  
  40.                     //dont remove this row with cancelled flight from final set
  41.                     remove_it = false;
  42.                 }
  43.             }
  44.  
  45.         }
  46.  
  47.         if (!remain_cancelled) {
  48.             if (qualifier.equals("arr_delay_new")) {
  49.                 if (!value.equals("") &&
  50.                         Float.parseFloat(value) > delay) {
  51.  
  52.                     //remove this row with delay > set_delay from final set
  53.                     remove_it = true;
  54.                 }
  55.             }
  56.  
  57.         }
  58.         return ReturnCode.INCLUDE;
  59.         //insert this cell into processed row like <cell> + <cell> + <cell> ...
  60.     }
  61.  
  62.     public static Filter parseFrom(byte[] pbBytes) throws DeserializationException{
  63.         return new CustomFlightFilter(Bytes.toFloat(pbBytes));
  64.     }
  65.  
  66.     @Override
  67.     public byte[] toByteArray() throws IOException {
  68.         return Bytes.toBytes(delay);
  69.     }
  70.  
  71.     @Override
  72.     public boolean filterRow() throws IOException {
  73.         return remove_it;
  74.     }
  75.  
  76.     @Override
  77.     public void reset() throws IOException {
  78.         remove_it = true;
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement