spark SQL学习(综合案例-日志分析)
2017-03-07 20:27
204 查看
日志分析
scala> import org.apache.spark.sql.types._ scala> import org.apache.spark.sql.Row scala> val logRDD = sc.textFile("hdfs://master:9000/student/2016113012/data/log.txt").map(_.split("#")) logRDD: org.apache.spark.rdd.RDD[Array[String]] = MapPartitionsRDD[2] at map at <console>:21 val schema = StructType( Array( StructField("ipAddress",StringType,true), StructField("clientIndentd",StringType,true), StructField("userId",StringType,true), StructField("dateTime",StringType,true), StructField("protocal",StringType,true), StructField("responseCode",StringType,true), StructField("contentSize",IntegerType,true) ) ) val rowRDD = logRDD.map(p => Row(p(0),p(1),p(2),p(3),p(4),p(5),p(6).toInt)) val logDF = sqlContext.createDataFrame(rowRDD,schema) logDF.registerTempTable("logs") //统计访问文件大小的平均值,最大值,最小值 scala> sqlContext.sql("select avg(contentSize),min(contentSize),max(contentSize) from logs").show() 17/03/07 17:04:20 INFO ParseDriver: Parsing command: select avg(contentSize),min(contentSize),max(contentSize) from logs 17/03/07 17:04:20 INFO ParseDriver: Parse Completed 17/03/07 17:04:21 INFO FileInputFormat: Total input paths to process : 1 17/03/07 17:04:22 INFO deprecation: mapred.tip.id is deprecated. Instead, use mapreduce.task.id 17/03/07 17:04:22 INFO deprecation: mapred.task.id is deprecated. Instead, use mapreduce.task.attempt.id 17/03/07 17:04:22 INFO deprecation: mapred.task.is.map is deprecated. Instead, use mapreduce.task.ismap 17/03/07 17:04:22 INFO deprecation: mapred.task.partition is deprecated. Instead, use mapreduce.task.partition 17/03/07 17:04:22 INFO deprecation: mapred.job.id is deprecated. Instead, use mapreduce.job.id +------+----+----+ | _c0| _c1| _c2| +------+----+----+ |3506.0|2000|5554| +------+----+----+ //统计响应代码的数量 scala> sqlContext.sql("select responseCode,count(*) from logs group by responseCode").show() 17/03/07 17:52:26 INFO ParseDriver: Parsing command: select responseCode,count(*) from logs group by responseCode 17/03/07 17:52:26 INFO ParseDriver: Parse Completed +------------+---+ |responseCode|_c1| +------------+---+ | 304| 1| | 200| 2| +------------+---+ //统计大于1次的ip地址 scala> sqlContext.sql("select ipAddress,count(1) as total from logs group by ipAddress having total > 1").show() 17/03/07 17:55:20 INFO ParseDriver: Parsing command: select ipAddress,count(1) as total from logs group by ipAddress having total > 1 17/03/07 17:55:20 INFO ParseDriver: Parse Completed +----------+-----+ | ipAddress|total| +----------+-----+ |10.0.0.153| 3| +----------+-----+
问题:如何将p(4)里面的继续切分
相关文章推荐
- Linux--netfilter/iptables+squid综合案例分析
- 用 HPjtune 分析 GC 日志(一个实际案例的诊断过程)
- 因为diagwait未配置导致RAC脑裂日志记录不完整的分析案例
- 【性能诊断】十、性能问题综合分析(案例1,windbg、Network Monitor)
- 系统分析师笔记-案例综合题-系统分析
- 在Sbo中通过单据事务日志进行物料的期初、期末、出入库综合分析
- Hadoop学习笔记—20.网站日志分析项目案例(一)项目介绍
- Jboss-eap-6日志输出与案例分析
- 10分布式数据仓库 HIVE -- HIVE案例实战1 apache common日志分析
- Hadoop学习笔记—20.网站日志分析项目案例(三)统计分析
- C#事件-综合案例分析
- 2012下半年(11月)信息系统项目管理师考试题型分析(综合知识、案例分析、论文)
- 傲天AC log日志分析用户下线原因案例
- 网站日志统计案例分析与实现
- Android中对Log日志文件的分析 (ANR重点,具体案例详细分析)
- iptables+squid综合案例分析
- C#事件-综合案例分析
- SAS9.3 邮件日志数据经典案例分析(图文并茂版) 可下载
- Hadoop学习笔记—20.网站日志分析项目案例(二)数据清洗
- Hadoop学习笔记—20.网站日志分析项目案例(二)数据清洗