• flink添加水位线


    flink1.11添加水位线

    object UpdateWindowResultWithLateEvent {
      def main(args: Array[String]): Unit = {
        val env = StreamExecutionEnvironment.getExecutionEnvironment
        env.setParallelism(1)
        env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
    
        val stream = env
          .socketTextStream("db2", 9999, '
    ')
          .map(r => {
            val arr = r.split(" ")
            (arr(0), arr(1).toLong * 1000L)
          })
          .assignTimestampsAndWatermarks(
            WatermarkStrategy
              .forBoundedOutOfOrderness[(String, Long)](Duration.ofSeconds(5))
              .withTimestampAssigner(new SerializableTimestampAssigner[(String, Long)] {
                override def extractTimestamp(element: (String, Long), recordTimestamp: Long): Long = element._2
              })
          )
          .keyBy(r => r._1)
          .timeWindow(Time.seconds(5))
          .allowedLateness(Time.seconds(5))
          .process(new CountWindow)
    
        stream.print()
    
        env.execute()
      }
    
      class CountWindow extends ProcessWindowFunction[(String, Long), String, String, TimeWindow] {
        override def process(key: String, context: Context, elements: Iterable[(String, Long)], out: Collector[String]): Unit = {
          // note that here is window state!!! only for current key and current window
          val isUpdate = context.windowState.getState(
            new ValueStateDescriptor[Boolean]("is-update", Types.of[Boolean])
          )
    
          if (!isUpdate.value()) {
            out.collect("first calculate window result!!!!")
            isUpdate.update(true)
          } else {
            out.collect("update window result!!!!")
          }
        }
      }
    }
  • 相关阅读:
    EntityFramework ,ef 介绍
    MVC controller and View
    MVC 模型
    mvc 控制器,视图,Razor 语法
    MVC 安装
    MVC 介绍
    vue 3.0 项目搭建移动端 (三) computed 和 methods 和 watch
    vue 3.0 项目搭建移动端 (二) Vue-router: router-link 与 router-view keep-alive
    添加网络js文件
    过滤 filter
  • 原文地址:https://www.cnblogs.com/ttyypjt/p/15152910.html
Copyright © 2020-2023  润新知