我试图从Hive表中检索列的列表并将结果存储在spark数据框中。对Spark数据框/ Hive结果集进行排序
var my_column_list = hiveContext.sql(s""" SHOW COLUMNS IN $my_hive_table""")
但我无法按字母顺序排序数据帧甚至显示列查询的结果。我尝试使用sort和orderBy()。
如何按字母顺序排列结果?
更新:加入我的代码示例
import org.apache.spark.{ SparkConf, SparkContext }
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.hive.HiveContext
val hiveContext = new HiveContext(sc)
hiveContext.sql("USE my_test_db")
var lv_column_list = hiveContext.sql(s""" SHOW COLUMNS IN MYTABLE""")
//WARN LazyStruct: Extra bytes detected at the end of the row! Ignoring similar problems
lv_column_list.show //Works fine
lv_column_list.orderBy("result").show //Error arises
这里排序不是问题,它与'show columns'命令的结果有关。 – cheseaux