我正在嘗試使用此代碼重新排列 spark scala 中資料框的列
def performTransformations(commonArgs: Map[String, Any], dataDf: Dataset[Row]): Dataset[Row] = {
// Create local var as a copy of data
var data = dataDf
*all the transformations here*
val data2 = data.select(reorderedColNames: _*)
data = data2
}
reorderdColNames 是一個陣列,其中所有列都按我想要的順序排列。
但我收到了這個錯誤
error: type mismatch;
[ERROR] found : Unit
[ERROR] required: org.apache.spark.sql.Dataset[org.apache.spark.sql.Row]
我該如何管理?謝謝
我試圖用其他方法排列列,但我做不到。
uj5u.com熱心網友回復:
根據您的評論,問題在于您的函式被定義為回傳Dataset[Row],但實際上它回傳Unit,因為函式的最后一條陳述句是變數賦值(data = data2)。
將您的功能更改為:
def performTransformations(commonArgs: Map[String, Any], dataDf: Dataset[Row]): Dataset[Row] = {
// Create local var as a copy of data
var data = dataDf
// all the transformations here
data.select(reorderedColNames: _*)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/527652.html
