Commit c61aee65 authored by 王志伟's avatar 王志伟

过滤异常数据

parent 01b6c36b
...@@ -42,11 +42,12 @@ object Search_keywords_count { ...@@ -42,11 +42,12 @@ object Search_keywords_count {
//定义异常捕获 //定义异常捕获
def catch_error(x:String)={ def catch_error(x:String)={
val in =JSON.parseFull(x)
try{ try{
val result=JSON.parseFull(x) in.toString
} }
catch { catch {
case e: ArithmeticException => println(e) case e: ArithmeticException => {e.printStackTrace();e.toString}
} }
} }
...@@ -80,7 +81,7 @@ object Search_keywords_count { ...@@ -80,7 +81,7 @@ object Search_keywords_count {
) )
search_count.show() search_count.show()
val get_result =search_keywords.rdd.map(x=>{try{val result=JSON.parseFull(x.toString())}catch {case e: ArithmeticException => println(e)}}).map((_, 1)).reduceByKey(_ + _) val get_result =search_keywords.rdd.map(x=>catch_error(x.toString())).map((_, 1)).reduceByKey(_ + _)
.sortBy(_._2,false) .sortBy(_._2,false)
val temp=get_result.collect() val temp=get_result.collect()
for (i <- 0 until temp.length ) { for (i <- 0 until temp.length ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment