flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Komal Mariam <komal.mar...@gmail.com>
Subject Re: Passing parameters to filter function (in DataStreams)
Date Thu, 10 Oct 2019 02:00:46 GMT
Thank you @Chesnay!

I also managed to pass arguments to a RichFilterFunction:  new
MyFilterFunc(Integer threshold)  by defining its constructor.
If there's a better way to pass arguments I'd appreciate it if you let me
know.

On Tue, 8 Oct 2019 at 19:58, Chesnay Schepler <chesnay@apache.org> wrote:

> You can compute the threshold ahead of time and reference it directly in
> the filter function.
>
> (Below are 2 examples, depending on whether you like lambdas or not)
>
> final int threshold = computeThreshold();temperatureStream.filter(new FilterFunction<Integer>()
{
>    @Override   public boolean filter(Integer temperature) {
>       return temperature > threshold;   }
> });
>
> final int threshold = computeThreshold();temperatureStream.filter(temperature -> temperature
> threshold);
>
>
> On 08/10/2019 12:46, Komal Mariam wrote:
>
> Hi everyone,
>
> Suppose I have to compute a filter condition
>
> Integer threshold = compute threshold();
>
> If I:
>
> temperatureStream.filter(new FilterFunction<temperature>() {
> @Override
> public boolean filter(Integer temperature) throws Exception {
> Integer threshold = compute threshold();
> return temperature > threshold
> }
>
> would this mean I have computed threshold over and over again, for every
> new element in the stream?
>
> my threshold does not changes once it computed. I don't want to recompute
> it every time for new elements? is there way I can pass it as a parameter
> to the filter function?
>
>
>

Mime
View raw message