![](/img/trans.png)
[英]Spark: How can DataFrame be Dataset[Row] if DataFrame's have a schema
[英]How can I read a dataframe using spark streaming with it's schema that I specify
我正在嘗試使用Spark流從AWS S3將csv文件讀取到數據幀中,但是數據並未存儲在所需的列中,而是僅在1列中輸入,其他則為null。 需要一種方法來將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", ",")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.