【问题标题】:Cannot write a stream into a parquet sink无法将流写入镶木地板水槽
【发布时间】:2019-10-29 09:31:12
【问题描述】:

我在 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

【问题讨论】:

  • 尝试不分区。
  • 不确定我是否会在 Streaming 中使用镶木地板。

标签: scala apache-spark parquet databricks spark-structured-streaming


【解决方案1】:

我已经解决了这个问题。

我使用了 /mnt/ 路径,该路径是为连接 blob 存储而保留的位置。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 2021-03-26
    • 2019-02-09
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    相关资源
    最近更新 更多