我想觀察火花流如何使用DStream內的RDD加入兩個DStreams,但看到奇怪的結果,這是令人困惑。火花流加入奇怪的結果
在我的代碼中,我從套接字流中收集數據,通過某種邏輯將它們分成2個PairedDStreams。爲了收集一些批次加入,我創建了一個窗口來收集最後三批。然而,加入的結果是無能爲力的。請幫助我理解。
object Join extends App {
val conf = new SparkConf().setMaster("local[4]").setAppName("KBN Streaming")
val sc = new SparkContext(conf)
sc.setLogLevel("ERROR")
val BATCH_INTERVAL_SEC = 10
val ssc = new StreamingContext(sc, Seconds(BATCH_INTERVAL_SEC))
val lines = ssc.socketTextStream("localhost", 8091)
//println(s"lines.slideDuration : ${lines.slideDuration}")
//lines.print()
val ds = lines.map(x => x)
import scala.util.Random
val randNums = List(1, 2, 3, 4, 5, 6)
val less = ds.filter(x => x.length <= 2)
val lessPairs = less.map(x => (Random.nextInt(randNums.size), x))
lessPairs.print
val greater = ds.filter(x => x.length > 2)
val greaterPairs = greater.map(x => (Random.nextInt(randNums.size), x))
greaterPairs.print
val join = lessPairs.join(greaterPairs).window(Seconds(30), Seconds(30))
join.print
ssc.start
ssc.awaitTermination
}
測試結果:
---------------------------------- ---------時間:1473344240000毫秒 ------------------------------------ -------(1,b)(4,s)
----------------------------- --------------時間:1473344240000毫秒 ------------------------------- ------------(5,333)
------------------------------- ------------ Ti me:1473344250000 ms -------------------------------------------(2 ,x)
-------------------------------------------時間:1473344250000毫秒 -------------------------------------------(4 ,)
-------------------------------------------時間:1473344260000毫秒 -------------------------------------------(2 ,a)(0,b)
-------------------------------------- -----時間:1473344260000 ms ---------------------------------------- ---(2,ten)(1,one)(3,2)
------------------------------------------- Time:1473344260000 ms -------------------------------------------(4,(b,兩個))