Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.hadoop.hbase.Cell;
- import org.apache.hadoop.hbase.exceptions.DeserializationException;
- import org.apache.hadoop.hbase.filter.Filter;
- import org.apache.hadoop.hbase.filter.FilterBase;
- import org.apache.hadoop.hbase.filter.PageFilter;
- import org.apache.hadoop.hbase.util.Bytes;
- import java.io.IOException;
- public class CustomFlightFilter extends FilterBase {
- private float delay;
- //private boolean remain_cancelled;
- private boolean remove_it;
- public CustomFlightFilter() {
- super();
- //this.remain_cancelled = true; //if no parameters then remain cancelled flights
- this.remove_it = true;
- }
- public CustomFlightFilter(float delay) {
- this.delay = delay;
- //this.remain_cancelled = false; //if delay has been set then remove cancelled
- this.remove_it = true;
- }
- @Override
- public ReturnCode filterKeyValue(Cell cell) throws IOException {
- String column = new String(
- cell.getQualifierArray(),
- cell.getQualifierOffset(),
- cell.getQualifierLength());
- String str_value = new String(
- cell.getValueArray(),
- cell.getValueOffset(),
- cell.getValueLength());
- float value = (float)777; //dummy
- if (column.equals("cancelled") || column.equals("arr_delay_new")) {
- if (str_value.equals("")) {
- value = (float)0;
- } else {
- value = Float.parseFloat(str_value);
- }
- }
- if ((float)777 != value) {
- if (delay > 0.0) {
- if (column.equals("arr_delay_new") && value > delay) {
- remove_it = false;
- }
- } else {
- if (column.equals("cancelled") && (float)1 == value) {
- remove_it = false;
- }
- }
- }
- /*
- if (column.equals("arr_delay_new")) {
- if ((float)(-1) != value && value > delay) {
- remove_it = false;
- }
- }
- if (column.equals("cancelled")) {
- if ((float)(-1) != value && (float)1 == value) {
- remove_it = false;
- }
- }*/
- /* if (remain_cancelled) {
- if (column.equals("cancelled")) {
- if ((float) 1 == Float.parseFloat(value)) {
- //row with cancelled flight. keep it
- remove_it = false;
- }
- }
- }
- if (!remain_cancelled) {
- if (column.equals("arr_delay_new")) {
- if (!value.isEmpty() && Float.parseFloat(value) > delay) {
- //row with appropriate delay. keep it
- remove_it = false;
- }
- }
- }*/
- return ReturnCode.INCLUDE;
- //insert this cell into processed row like <cell> + <cell> + <cell> ...
- //all the cells should remain in processed row
- }
- public static Filter parseFrom(byte[] pbBytes) throws DeserializationException{
- return new CustomFlightFilter(Bytes.toFloat(pbBytes));
- }
- @Override
- public byte[] toByteArray() throws IOException {
- return Bytes.toBytes(delay);
- }
- @Override
- public boolean filterRow() throws IOException {
- return remove_it;
- }
- @Override
- public void reset() throws IOException {
- remove_it = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement