peopleSchemaRDD.registerTempTable("people") val op=sqlContext.sql("select * from people").count().toString val pw=new PrintWriter(new File("path")) pw.write("count of people:"+op+"\n") pw.close()
create a temporary table called people, then write a query to get the required output and count function, which counts the number of rows after the output converted to tostring. this stored value in the op object is invoked by the print engine to write it to a text file. if in case the people column consists of duplicate values, use a different keyword to distinguish unique values ββin the sql query.
source share