Database Reference
In-Depth Information
The output expected here is as per the function it should return ["a", "b", "c",
"d"] , so for the preceding tuples in the stream I would get the following output:
//for input tuple [10, 2, 30] loop in the function executes
twice //value of b=2
[10, 2, 30, 0]
[10, 2, 30, 1]
//for input tuple [4, 1, 6] loop in the function executes
once value //of b =1
[4, 1, 6, 0]
//for input tuple [3, 0, 8]
//no output because the value of field b is zero and the
for loop //would exit in first iteration itself value of
b=0
Filters
Filters are no misnomers; their execution is exactly the same as their name suggests: they
help us decide whether or not we have to keep a tuple or not—they do exactly what filters
do, that is, remove what is not required as per a given criteria.
Let's have a look at the following snippet to see a working illustration of filter functions:
public class MyLocalFilterFunction extends BaseFunction {
public boolean isKeep(TridentTuple tuple) {
return tuple.getInteger(0) == 1 &&
tuple.getInteger(1) == 2;
}
}
Let's look at the sample tuples on the input stream with the fields as [ "a" , "b" ,
"c"] :
[1,2,3]
[2,1,1]
[2,3,4]
We execute or call the function as follows:
Search WWH ::




Custom Search