我如何使用 spark streaming 和我指定的模式读取数据帧

How can I read a dataframe using spark streaming with it's schema that I specify

我正在尝试使用 Spark 流将 csv 文件从 AWS S3 读取到数据帧中,但是数据没有存储在所需的列中,而是只输入 1 列,其他列为空。 需要一种方法如何将 csv 文件作为格式输入。

我试过添加架构。 删除架构并尝试推断架构声明必须指定架构。

var schema = StructType(
  StructField("date", StringType, true) ::
    StructField("close",StringType, true) ::
    StructField("volume", StringType, true) ::
    StructField("open", StringType, true) ::
    StructField("high",StringType,true) ::
    StructField("low", StringType,true) :: Nil)

val ds = spark
  .readStream
  .option("sep", ";")
  .format("csv")
  .option("thousands",",")
  .schema(schema)
  .option("header",true)
  .load(path)

val df = ds.select("*")

df.writeStream.outputMode("append")
  .format("console")
  .trigger(Trigger.ProcessingTime("5 seconds"))
  .start("/home/admin1/IdeaProjects/StockPricePrediction/src/main/output/")
  .awaitTermination()

我应该是一个数据框,每列都有数据,但它显示如下:

Batch: 0
-------------------------------------------
19/07/02 18:53:46 INFO CodeGenerator: Code generated in 20.170544 ms
+--------------------+-----+------+----+----+----+
|                date|close|volume|open|high| low|
+--------------------+-----+------+----+----+----+
|0,2019/06/28,1080...| null|  null|null|null|null|
|1,2019/06/27,1076...| null|  null|null|null|null|
|2,2019/06/26,1079...| null|  null|null|null|null|
|3,2019/06/25,1086...| null|  null|null|null|null|
|4,2019/06/24,1115...| null|  null|null|null|null|
+--------------------+-----+------+----+----+----+

如有任何帮助,我们将不胜感激。谢谢

您的分隔符似乎设置不正确。 由于所有数据似乎都聚集在日期列中。

.option("delimiter", ",")