准备测试数据集(spark2.3.0,scala2.11)
val df = Seq(
("001", 1, 10, "2021-11-20 11:50:41"),
("002", 1, 40, "2021-11-20 11:50:43"),
("004", 1, 20, "2021-11-20 11:50:52"),
("005", 1, 20, "2021-11-20 11:50:52"),
("003", 1, 80, "2021-11-20 11:50:45"),
("006", 2, 80, "2021-11-20 11:51:45")
).toDF("key", "type", "amount", "end_time")
获取当前窗口-15秒到15秒的内容
df..withColumn("ts", $"end_time".cast(DataTypes.TimestampType).cast(DataTypes.LongType))
.withColumn("window_sum",
sum("amount").over(Windo