2017-07-18 49 views
0

有沒有辦法讓我打印輸入數據?對於例如我在一個尋找json文件的文件夾上有一個readStream,但是看起來有一個問題,因爲我在聚合輸出中看到'nulls'。結構化流式調試輸入

val schema = StructType(
     StructField("id", LongType, false) :: 
     StructField("sid", IntegerType, true) :: 
     StructField("data", ArrayType(IntegerType, false), true) :: Nil) 

    val lines = spark. 
     readStream. 
     schema(schema). 
     json("in/*.json") 

    val top1 = lines.groupBy("id").count() 

    val query = top1.writeStream 
     .outputMode("complete") 
     .format("console") 
     .option("truncate", "false") 
     .start() 
+0

你爲什麼不'線.writeStream.format(「console」)'然後呢? –

回答

0

要打印數據,您可以在寫入流中添加queryName,通過使用該queryName您可以打印。

在你的榜樣

val query = top1.writeStream 
     .outputMode("complete") 
     .queryName("xyz") 
     .format("console") 
     .option("truncate", "false") 
     .start() 

運行這一點,你可以通過使用SQL查詢

%sql select * from xyz 

顯示數據,也可以創建數據幀

val df = spark.sql("select * from xyz")