【发布时间】:2018-09-06 08:38:55
【问题描述】:
尝试测试 Spark Structured Streams ...但失败了...如何正确测试它们?
我遵循了来自here 的一般 Spark 测试问题,我最接近的尝试是 [1] 看起来像:
import simpleSparkTest.SparkSessionTestWrapper
import org.scalatest.FunSpec
import org.apache.spark.sql.types.{StringType, IntegerType, DoubleType, StructType, DateType}
import org.apache.spark.sql.streaming.OutputMode
class StructuredStreamingSpec extends FunSpec with SparkSessionTestWrapper {
describe("Structured Streaming") {
it("Read file from system") {
val schema = new StructType()
.add("station_id", IntegerType)
.add("name", StringType)
.add("lat", DoubleType)
.add("long", DoubleType)
.add("dockcount", IntegerType)
.add("landmark", StringType)
.add("installation", DateType)
val sourceDF = spark.readStream
.option("header", "true")
.schema(schema)
.csv("/Spark-The-Definitive-Guide/data/bike-data/201508_station_data.csv")
.coalesce(1)
val countSource = sourceDF.count()
val query = sourceDF.writeStream
.format("memory")
.queryName("Output")
.outputMode(OutputMode.Append())
.start()
.processAllAvailable()
assert(countSource === 70)
}
}
}
遗憾的是,org.apache.spark.sql.AnalysisException: Queries with streaming sources must be executed with writeStream.start() 总是失败
我还在 spark-testing-base 存储库中找到了这个 issue,我想知道是否可以测试 Spark 结构化流?
我想要进行集成测试,甚至可能在顶部使用 Kafka 来测试检查点或特定的损坏数据场景。有人可以帮帮我吗?
最后但并非最不重要的一点是,我认为版本可能也是一个限制 - 我目前针对 2.1.0 进行开发,因为 Azure HDInsight 部署选项我需要它。如果这是拖累,自托管是一种选择。
【问题讨论】:
-
尝试
.trigger(Trigger.Once())和query.awaitTermination()看看是否会得到不同的结果spark.apache.org/docs/latest/…
标签: apache-spark integration-testing scalatest