Is there a way to get column names using hiveContext?

I have "iplRDD", which is json, and I do the below steps and request through hivecontext. I get results, but without column headers. Is there a way to get column names along with values?

val teamRDD = hiveContext.jsonRDD(iplRDD) 
teamRDD.registerTempTable("teams") 
hiveContext.cacheTable("teams") 

val result = hiveContext.sql("select * from teams where  team_name = "KKR" ) 
result.collect.foreach(println) 

Any thoughts please?

+4
source share
3 answers

teamRDD.schema.fieldNames must contain the names of the headers.

+2
source

You can save your “result” in a data frame with a header as a CSV file:

result.write().format("com.databricks.spark.csv").option("header", "true").save(outputPath);
+1
source

, :

result.schema().fields();
+1

All Articles