如何以格式("console")输出以控制数据帧的格式?

How to output to console the format of the dataFrames in format("console")?

我正在执行 readStream format("rate") 的输出,我想获取 dataframe 的开箱即用值字段的格式。我在文档中找到的唯一选项是 truncate,但我找不到如何强制获得类似的东西

Batch: 3
-------------------------------------------
+-----------------------+---------+
|timestamp:String       |value:Int|
+-----------------------+---------+
|2021-10-14 14:28:58.981|0        |
+-----------------------+---------+

而不是那个

Batch: 3
-------------------------------------------
+-----------------------+-----+
|timestamp              |value|
+-----------------------+-----+
|2021-10-14 14:28:58.981|0    |
+-----------------------+-----+

输出代码为:

df
      .writeStream
      .format("console")
      .option("truncate", "false")
      .start().awaitTermination(20000)

感谢@m_vemuri

解决方案是

println("Rate schema:")
println(rate.schema.fields.mkString)

从那以后我知道 ratevalue 生成的类型是什么:

Rate schema:
StructField(timestamp,TimestampType,true)StructField(value,LongType,true)