我想重寫Clojure中的Spark結構化流示例。在Clojure中寫Spark結構化流示例時出現錯誤
的例子是用Scala編寫如下:
https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html
(ns flambo-example.streaming-example
(:import [org.apache.spark.sql Encoders SparkSession Dataset Row]
[org.apache.spark.sql.functions]
))
(def spark
(->
(SparkSession/builder)
(.appName "sample")
(.master "local[*]")
.getOrCreate)
)
(def lines
(-> spark
.readStream
(.format "socket")
(.option "host" "localhost")
(.option "port" 9999)
.load
)
)
(def words
(-> lines
(.as (Encoders/STRING))
(.flatMap #(clojure.string/split % #" "))
))
上述代碼導致以下例外。
;;由java.lang.IllegalArgumentException引發 ;;找不到匹配的方法:flatMap for class ;; org.apache.spark.sql.Dataset
我該如何避免錯誤?