是否有一个变量来识别火花流中的每批数据?
Is there a variable to identify each batch data in spark streaming?
在spark streaming中,数据是按照batch interval进行处理的。如果我将批处理间隔设置为 5 秒 (val ssc = new StreamingContext(sc, Seconds(5))
):
1s~5s is first batch of data
6s~10s is second batch of data
10s~15s is third batch of data
……
spark streaming中是否有一个变量来标识每批数据?如果有这样的变量:
var batchID = 0
我可以获取 batchID
的值来识别哪一批数据,或者我可以按 batchID 过滤数据,例如:window(……).filter(_.batchId == 1)
.
或者有什么办法区分每批数据?
您可以使用类型为 (rdd: RDD[T], time: Time) => Unit
的 foreachRDD
。时间是数据流中 RDD
的标记,这意味着在对两个连续批次的两次连续调用中,时间参数将相差一个批次间隔持续时间。
您可以在此处找到 foreachRDD
的 API:
https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.streaming.dstream.DStream
如果你需要select一些RDD
s特定的时间间隔,你可以简单地使用slice
函数,这在上面的link中也有指定.
在spark streaming中,数据是按照batch interval进行处理的。如果我将批处理间隔设置为 5 秒 (val ssc = new StreamingContext(sc, Seconds(5))
):
1s~5s is first batch of data
6s~10s is second batch of data
10s~15s is third batch of data
……
spark streaming中是否有一个变量来标识每批数据?如果有这样的变量:
var batchID = 0
我可以获取 batchID
的值来识别哪一批数据,或者我可以按 batchID 过滤数据,例如:window(……).filter(_.batchId == 1)
.
或者有什么办法区分每批数据?
您可以使用类型为 (rdd: RDD[T], time: Time) => Unit
的 foreachRDD
。时间是数据流中 RDD
的标记,这意味着在对两个连续批次的两次连续调用中,时间参数将相差一个批次间隔持续时间。
您可以在此处找到 foreachRDD
的 API:
https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.streaming.dstream.DStream
如果你需要select一些RDD
s特定的时间间隔,你可以简单地使用slice
函数,这在上面的link中也有指定.