Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-3039

Trigger KeyValueState cannot be Scala Int

    XMLWordPrintableJSON

Details

    Description

      It is not possible to use a Scala Int as a KeyValueState in a Trigger function because TriggerContext.getKeyValueState requires that the state is Serializable.

      override def onElement(e: (Int, Short), t: Long, w: TimeWindow, ctx: TriggerContext): TriggerResult = {
            val cnt = ctx.getKeyValueState[Int]("cnt", 0)
            ...
      }
      

      will fail with

      Error:(116, 44) type arguments [Int] do not conform to method getKeyValueState's type parameter bounds [S <: java.io.Serializable]
            val cnt = ctx.getKeyValueState[Int]("cnt", 0)
                                                 ^
      

      If I change Int to Integer, the code compiles.

      Attachments

        Activity

          People

            Unassigned Unassigned
            fhueske Fabian Hueske
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: