无法将流写入镶木地板水槽

Cannot write a stream into a parquet sink

我在 Databricks 上工作,这是一个基于 Spark 的数据处理平台,具有类似 HDFS 的文件系统,所以基本上我相信那些熟悉 Spark 和 HDFS 的人即使没有 Databricks 经验也能帮助我。

我使用结构化流从 Kafka 读取数据:

var streamingInputDF = 
  spark.readStream
    .format("kafka")
    .option("kafka.bootstrap.servers", "<XX.XX.XXX.XX:9092")
    .option("subscribe", "answers")     
    .option("startingOffsets", "earliest")  
    .option("minPartitions", "1")  
    .option("failOnDataLoss", "true")
    .load()

做一些转换:

 val streamingSelectDF = streamingInputDF
  .withWatermark("timestamp","1 days")
  .select(explode(split($"value".cast("string"), "\s+")).as("word"), col("timestamp"))
  .groupBy(window($"timestamp", "1 minute"), $"word")
  .count
  .where("count >= 11")

然后我通过打印到控制台来确保有一些数据:

+--------------------+----+-----+
|              window|word|count|
+--------------------+----+-----+
|[2019-06-10 14:33...| the|  763|
|[2019-06-09 20:48...| the|  523|
|[2019-06-10 14:33...| and|  489|
|[2019-06-10 14:33...|   a|  479|
|[2019-06-08 19:07...| the|  435|
|[2019-06-10 14:33...|  to|  430|
|[2019-06-10 14:33...|  of|  365|
|[2019-06-09 20:48...|   a|  314|
|[2019-06-09 20:48...| and|  303|
|[2019-06-09 20:48...|  to|  285|
|[2019-06-10 14:33...|  is|  272|
|[2019-06-08 19:07...|   a|  264|
|[2019-06-08 19:07...| and|  250|
|[2019-06-08 19:07...|  to|  233|
|[2019-06-09 20:48...|  of|  231|
|[2019-06-10 14:33...|  in|  219|
|[2019-06-10 14:33...|that|  211|
|[2019-06-08 19:07...|  of|  186|
|[2019-06-10 14:33...| for|  166|
|[2019-06-09 20:48...|  is|  158|
+--------------------+----+-----+
only showing top 20 rows

然后,我想将数据流式传输到 parquet 文件中:

val query =
  streamingSelectDF
    .writeStream
    .format("parquet")
    .option("path", "/mnt/kafka/answers")
    .option("checkpointLocation", "/mnt/kafka/checkpoint")
    .partitionBy("window")
    .start()

但是没有创建任何文件。仅创建了一个 "kafka" 目录:

ls /mnt/

path               name     size
dbfs:/mnt/kafka/   kafka/   0

我已经解决了问题。

我使用了 /mnt/ 路径,这是一个用于连接 blob 存储的位置。

由于我想将镶木地板存储在 DBFS 上,我不得不使用除 /mnt/ 之外的任何路径,所以我将其改为 /tmp/。