My Filter

Updated: Aug 24, 2023

This example shows how to modify and personalize the default Filter component in DataPipeline. By offering the capability to tailor the filter behavior, it allows you to control how data is selected or excluded in your processing pipeline.

More information on the usage of MyFilter can be found in Write My Own Filter Or Validator.

 

Java Code Listing

package com.northconcepts.datapipeline.examples.cookbook.customization;

import com.northconcepts.datapipeline.core.Record;
import com.northconcepts.datapipeline.filter.Filter;

public class MyFilter extends Filter {
    
    private final double minimumBalance;
    
    public MyFilter(double minimumBalance) {
        this.minimumBalance = minimumBalance;
    }

    public boolean allow(Record record) {
        return record.getField("Balance").getValueAsDouble() >= minimumBalance;
    }

    public String toString() {
        return "Balance >=  " + minimumBalance;
    }

}

 

Code Walkthrough

MyFilter extends Filter abstract class and can be customized to apply filtration/validation logic based on our needs. The single abstract method allow(Record record) must be overridden and should contain that logic implementation. In the given code, for example, the Balance value of each record is compared with minimumBalance attribute.

 

Mobile Analytics