多谢回答。
如果我想保存到HDFS呢 有没有什么方法呢
下面是我的代码:
[mw_shl_code=scala,true] val userPrincipal = "miner"
val userKeytabPath = "/opt/user.keytab"
val krb5ConfPath = "/opt/krb5.conf"
System.setProperty("hadoop.home.dir", "/opt/FI-Client/HDFS/hadoop/")
val hadoopConf: Configuration = new Configuration()
LoginUtil.login(userPrincipal, userKeytabPath, krb5ConfPath, hadoopConf);
// Configure Spark application name
val sparkConf = new SparkConf().setAppName("FemaleInfo")
val sc = new SparkContext(sparkConf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext.implicits._
// Convert RDD to DataFrame through the implicit conversion, then register table.
sc.textFile(args(0)).map(_.split(","))
.map(p => FemaleInfo(p(0), p(1), p(2).trim.toInt))
.toDF.registerTempTable("FemaleInfoTable")
// Via SQL statements to screen out the time information of female stay on the Internet , and aggregated the same names.
val femaleTimeInfo = sqlContext.sql("select name,sum(stayTime) as " +
"stayTime from FemaleInfoTable where gender = 'female' group by name")
// Filter information about female netizens who spend more than 2 hours online.
val c = femaleTimeInfo.filter("stayTime >= 120").collect().foreach(println)
sc.stop() }[/mw_shl_code]
|