streaming-with-flink/examples-scala

Understand TempIncreaseAlertFunction#processElement in chapter 6

bithw1 opened this issue · 2 comments

TempIncreaseAlertFunction#processElement has the following code to check and remove the registered timer

It has a condition prevTemp = 0.0, I would ask when this condition is true? As far as I can think, it happens for the first time that processElement method is called, but, when it is first called, should we need to delete the timer? It has not been registered yet.

Does this condition check has some special concern?

Thanks!

    if (prevTemp == 0.0 || r.temperature < prevTemp) {
      // temperature decreased. Delete current timer.
      ctx.timerService().deleteProcessingTimeTimer(curTimerTimestamp)
      currentTimer.clear()
    }

Hi @bithw1, thanks for your question. The purpose of the prevTemp = 0.0 condition is to prevent to fall into the else if branch because we don't want the first reading to be compared with 0.0 which would always be considered as a temperature increase.

But you're right, we should make that more clear in the code example.
I'll update the example.

Thanks, Fabian

Thanks @fhueske for the reply and updating the code, the logic looks much clear