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

Default value of StateDescriptor is valid when enable state ttl config

    XMLWordPrintableJSON

Details

    Description

      Suppose we declare a ValueState like following:

      ValueStateDescriptor<Tuple2<Long, Long>> descriptor =
                      new ValueStateDescriptor<>(
                              "average", // the state name
                              TypeInformation.of(new TypeHint<Tuple2<Long, Long>>() {}),  
                              Tuple2.of(0L, 0L)); 
      

      and then we add state ttl config to the state:

      descriptor.enableTimeToLive(StateTtlConfigUtil.createTtlConfig(60000));
      

      the default value Tuple2.of(0L, 0L) will be invalid and may cause NPE.

      I don't know if this is a bug cause I see @Deprecated in the comment of the ValueStateDescriptor constructor with argument defaultValue:

      Use {@link #ValueStateDescriptor(String, TypeSerializer)} instead and manually
           *     manage the default value by checking whether the contents of the state is {@code null}.
      

      and if we decide not to use the defaultValue field in the class StateDescriptor, should we add @Deprecated annotation to the field defaultValue?

      Attachments

        Issue Links

          Activity

            People

              lam167 Jianhui Dong
              lam167 Jianhui Dong
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: