Huawei H13-723_V2.0 Exam - Topic 1 Question 17 Discussion
There are the following business scenarios: User online log files have been stored inHDFSabove, the log file content format the formula is: each online record has three fields, namely name, gender, and online time, and the fields are separated by ",";It is required to print out all female netizens who spend more than two hours online. Which of the following code snippets can achieveThe above business scenario? (multiple choice)
A) sc.textFile('/data/file/path'').map(.split(',')).map(p=>FemaleInfo(p
(O),p(1),p(2).trim.toInt)).toDF.registerTemp Table('FemaleinfoTable'')sqlContext.sql
('select name,sum(stay Time)as stay Time from FemaleInfoTable where gender=
female'group by name'').filter('stay Time >=120'').collect).foreach(printin) and C) val text=sc.textFile('/data/fle/path')
val data=text.filter(_.contains('female'))
Val fermaleData:RDD(String,Int) =data.map{line=>val t=line.split(',')
(t(0),t(2).toInt)
}.reduceByKey(_+_)
Val result=femaleData.filter(line=>line.2>120)
Rusult.collect.map(x=>x._1 + ',' + x._2).foreach(println) and D) val text=sc.textFile('/data/fle/path'')
val data=text.filter(_.contains('female''))
Val fermaleData:RDD(String,Int) =data.map(line=>val t=line.split(',')
(t(0),t(2).toInt)
}
Val result=femaleData.filter(line=>line.2>120)
Rusult.collect.map(x=>x._1 +','+ x._2).foreach(println)
B) sc.textFile('/data/file/path').map(.split(',')).map(p=>FemaleInfo
(p(O),p(1),p(2).trim.toInt)).toDF.registerTemp Table('Female infoTable')
sqlContext.sq(l 'select name, sum(stay Time)as stay Time from FemaleInfoTable where
gender=female).filter(''stay Time >=120'').collect).foreach(printin)
Arlette
11 months agoCassie
11 months agoBoris
11 months agoWhitley
11 months agoViki
11 months agoAugustine
12 months agoKina
12 months agoAleisha
12 months agoWilda
12 months agoStefanie
12 months agoIra
12 months agoJuliana
12 months agoZena
12 months agoFlorinda
12 months agoTwana
12 months agoHelaine
1 year agoBilli
1 year agoKeneth
1 year agoKanisha
1 year agoTimothy
1 year agoGlendora
1 year agoGlendora
1 year agoSabrina
1 year agoMica
1 year agoJohnna
1 year agoTy
1 year agoLashaunda
1 year agoAlysa
1 year agoMitsue
1 year agoTasia
1 year agoMicah
1 year agoCharlette
1 year ago