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

Allow `null` user values in map state with TTL

    Details

      Description

      Thanks for the StateTtl feature,this is exactly what I need now! But I found an issue.

      In the previous version or when StateTtl is not enabled,MapState allows `null` value,that means after

      mapState.put("key", null)

      , then

      mapState.contains("key")

      will return true, but when StateTtl is enabled,

      mapState.contains("key")

      will return false(the key has not expired).
      So I think the field `userValue` in `org.apache.flink.runtime.state.ttl.TtlValue` should allow `null` value. User state is null may not means the TtlValue should be null.

       

      /**
       * This class wraps user value of state with TTL.
       *
       * @param <T> Type of the user value of state with TTL
       */
      class TtlValue<T> implements Serializable {
       private final T userValue;
       private final long lastAccessTimestamp;
      TtlValue(T userValue, long lastAccessTimestamp) {
       Preconditions.checkNotNull(userValue);
       this.userValue = userValue;
       this.lastAccessTimestamp = lastAccessTimestamp;
       }
      T getUserValue() {
       return userValue;
       }
      long getLastAccessTimestamp() {
       return lastAccessTimestamp;
       }
      }
      

      Am I understanding right?

      This is my test class.

      StateWithTtlTest.scala StateWithOutTtlTest.scala

      Thanks!

        Attachments

        1. StateWithOutTtlTest.scala
          1 kB
          chengjie.wu
        2. StateWithTtlTest.scala
          2 kB
          chengjie.wu

          Issue Links

            Activity

              People

              • Assignee:
                azagrebin Andrey Zagrebin
                Reporter:
                wucj chengjie.wu
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: