我在Scala中使用Spark,並且我的聚合列是匿名的。有沒有一種方便的方法來重命名數據集中的多個列?我想加一個as
的模式,但關鍵列是一個結構(由於groupBy
操作),我不知道如何定義一個case class
與StructType
在其中。如何命名聚合列?
我試着定義模式如下:
val returnSchema = StructType(StructField("edge", StructType(StructField("src", IntegerType, true),
StructField("dst", IntegerType), true)),
StructField("count", LongType, true))
edge_count.as[returnSchema]
但我得到一個編譯錯誤:
Message: <console>:74: error: overloaded method value apply with alternatives:
(fields: Array[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType <and>
(fields: java.util.List[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType <and>
(fields: Seq[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType
cannot be applied to (org.apache.spark.sql.types.StructField, org.apache.spark.sql.types.StructField, Boolean)
val returnSchema = StructType(StructField("edge", StructType(StructField("src", IntegerType, true),
你能告訴我們的代碼?那麼也許我可以制定一個更好的方法? –
假裝你有一個包含三列的數據集。前兩名分組,第三名計數。關鍵是一個元組。我在Spark 1.6.2上。謝謝@AlbertoBonsanto! – Emre