首页 > 网络 > 云计算 > 正文
scala解析json日志
2017-04-28       个评论      
收藏    我要投稿
scala解析json日志:scala如何解析json日志,希望下面的文章对大家有所帮助。

package com.ys.scala
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.sql.SQLContext


object ProductInfoDemo {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("ProductInfoDemo").setMaster("local[2]")
val sc = new SparkContext(conf)

val sqlContext = new SQLContext(sc)
val lines = sc.textFile("productInfo.json", 2)
val words = lines.flatMap(_.split("\\s"))
val filterdWords = words.filter { _.length > 20 }
//filterdWords.foreach(println)

val productInfoDF = sqlContext.read.json(filterdWords)
productInfoDF.registerTempTable("productInfo")

val productInfo = sqlContext.sql("select count(Querystorebyproductid.productId) from productInfo")
productInfo.foreach(println)
}
}

2017-04-25 17:18:59,173 - {"Querystorebyproductid":{"productId":"8844882","storeId":"11240051","userId":"1320046117","latitude":"10108.11","longitude":"10086.37"}}
2017-04-25 17:18:59,173 - {"Querystorebyproductid":{"productId":"8844883","storeId":"11240052","userId":"1320046118","latitude":"10109.11","longitude":"10087.37"}}
2017-04-25 17:18:59,173 - {"Querystorebyproductid":{"productId":"8844884","storeId":"11240053","userId":"1320046119","latitude":"10110.11","longitude":"10088.37"}}
2017-04-25 17:18:59,173 - {"Querystorebyproductid":{"productId":"8844885","storeId":"11240054","userId":"1320046120","latitude":"10111.11","longitude":"10089.37"}}
2017-04-25 17:18:59,173 - {"Querystorebyproductid":{"productId":"8844886","storeId":"11240055","userId":"1320046121","latitude":"10112.11","longitude":"10090.37"}}
2017-04-25 17:18:59,173 - {"Querystorebyproductid":{"productId":"8844887","storeId":"11240056","userId":"1320046122","latitude":"10113.11","longitude":"10091.37"}}

 

点击复制链接 与好友分享!回本站首页
上一篇:scala解析json
下一篇:最后一页
相关文章
图文推荐
文章
推荐
点击排行

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训
版权所有: 红黑联盟--致力于做实用的IT技术学习网站