我有一個帶有標準 Kafka 模式的 Kafka 流。我想添加一堆列以使此流可以合并。我想重用架構變數
val schema = StructType(
StructField("id", LongType, nullable = false) ::
StructField("Energy Data", StringType, nullable = false) ::
StructField("Distance", StringType, nullable = false) ::
StructField("Humidity", StringType, nullable = false) ::
StructField("Ambient Temperature", StringType, nullable = false) ::
StructField("Cold Water Temperature", StringType, nullable = false) ::
StructField("Vibration Value 1", StringType, nullable = false) ::
StructField("Vibration Value 2", StringType, nullable = false) ::
StructField("Handle Movement", StringType, nullable = false) ::
StructField("Make Coffee", StringType, nullable = false) ::
Nil)
有沒有像
.withColumns(schema)
不是復制結構,而是重用與要添加的列的串列源相同的模式?
更新:
val iter=schema.iterator
while(iter.hasNext)
{
controlDataFrame=controlDataFrame.withColumn(iter.next.name,lit(""))
}
為我作業
uj5u.com熱心網友回復:
也許你可以嘗試這樣的事情:
xs.withColumn("y", lit(null).cast(StringType))
添加空列。您可以從中獲取架構,xs.schema但如果您想重用原始變數,我不確定這是否能解決您的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/360753.html
