You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Nirmalya Sengupta <se...@gmail.com> on 2016/02/03 02:36:07 UTC

Understanding code of CountTrigger

Hello all,

Here's a code comment from
org.apache.flink.streaming.api.windowing.triggers.Trigger:

/**
         * Result type for trigger methods. This determines what happens
which the window.
         *
         * <p>
         * On {@code FIRE} the pane is evaluated and results are emitted. *The
contents of the window*
         * *are kept*. {@code FIRE_AND_PURGE} acts like {@code FIRE} but
the contents of the pane
         * are purged. On {@code CONTINUE} nothing happens, processing
continues. On {@code PURGE}
         * the contents of the window are discarded and now result is
emitted for the window.
*/

And, here's the code snippet from
org.apache.flink.streaming.api.windowing.triggers.CountTrigger:

@Override
        public TriggerResult onElement(Object element, long timestamp, W
window, TriggerContext ctx) throws IOException {
                OperatorState<Long> count = ctx.getKeyValueState("count",
0L);
                long currentCount = count.value() + 1;
                count.update(currentCount);
                if (currentCount >= maxCount) {
                        count.update(0L);
                        return TriggerResult.FIRE;
                }
                return TriggerResult.CONTINUE;
        }


Following the code-comment, I understand that elements are *not* *PURGE*d
from a CountWindow, only *FIRE*d. The contents on the Window stay *forever*.

Now, that is counter-intuitive to me. Something is not right about this.

What am I missing? Help me to plug the holes in my understanding.

-- Nirmalya

-- 
Software Technologist
http://www.linkedin.com/in/nirmalyasengupta
"If you have built castles in the air, your work need not be lost. That is
where they should be.
Now put the foundation under them."

Re: Understanding code of CountTrigger

Posted by Till Rohrmann <tr...@apache.org>.
Hi Nirmalya,

the CountTrigger always works together with the CountEvictor which will
make sure that only count elements are kept in the window. Evictors can
evict elements from the window after the trigger event. That is the reason
why the CountTrigger does not have to purge the window explicitly.

Cheers,
Till
​

On Wed, Feb 3, 2016 at 2:36 AM, Nirmalya Sengupta <
sengupta.nirmalya@gmail.com> wrote:

> Hello all,
>
> Here's a code comment from
> org.apache.flink.streaming.api.windowing.triggers.Trigger:
>
> /**
>          * Result type for trigger methods. This determines what happens
> which the window.
>          *
>          * <p>
>          * On {@code FIRE} the pane is evaluated and results are emitted. *The
> contents of the window*
>          * *are kept*. {@code FIRE_AND_PURGE} acts like {@code FIRE} but
> the contents of the pane
>          * are purged. On {@code CONTINUE} nothing happens, processing
> continues. On {@code PURGE}
>          * the contents of the window are discarded and now result is
> emitted for the window.
> */
>
> And, here's the code snippet from
> org.apache.flink.streaming.api.windowing.triggers.CountTrigger:
>
> @Override
>         public TriggerResult onElement(Object element, long timestamp, W
> window, TriggerContext ctx) throws IOException {
>                 OperatorState<Long> count = ctx.getKeyValueState("count",
> 0L);
>                 long currentCount = count.value() + 1;
>                 count.update(currentCount);
>                 if (currentCount >= maxCount) {
>                         count.update(0L);
>                         return TriggerResult.FIRE;
>                 }
>                 return TriggerResult.CONTINUE;
>         }
>
>
> Following the code-comment, I understand that elements are *not* *PURGE*d
> from a CountWindow, only *FIRE*d. The contents on the Window stay
> *forever*.
>
> Now, that is counter-intuitive to me. Something is not right about this.
>
> What am I missing? Help me to plug the holes in my understanding.
>
> -- Nirmalya
>
> --
> Software Technologist
> http://www.linkedin.com/in/nirmalyasengupta
> "If you have built castles in the air, your work need not be lost. That is
> where they should be.
> Now put the foundation under them."
>