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.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
- }
- public CustomFlightFilter(float delay) {
- this.delay = delay;
- this.remain_cancelled = false; //if delay has been set then remove cancelled
- }
- @Override
- public ReturnCode filterKeyValue(Cell cell) throws IOException {
- String qualifier = new String(
- cell.getQualifierArray(),
- cell.getQualifierOffset(),
- cell.getQualifierLength());
- String value = new String(
- cell.getValueArray(),
- cell.getValueOffset(),
- cell.getValueLength());
- if (remain_cancelled) {
- if (qualifier.equals("cancelled")) {
- if (!value.equals("") && (float) 1 == Float.parseFloat(value)) {
- //dont remove this row with cancelled flight from final set
- remove_it = false;
- }
- }
- }
- if (!remain_cancelled) {
- if (qualifier.equals("arr_delay_new")) {
- if (!value.equals("") &&
- Float.parseFloat(value) > delay) {
- //remove this row with delay > set_delay from final set
- remove_it = true;
- }
- }
- }
- return ReturnCode.INCLUDE;
- //insert this cell into processed row like <cell> + <cell> + <cell> ...
- }
- 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