zoukankan      html  css  js  c++  java
  • 学习进度笔记

    学习进度笔记24

    读取文件演示

    import org.apache.spark.SparkConf

    import org.apache.spark.streaming.{Seconds, StreamingContext}

    import org.apache.spark.streaming.StreamingContext._

    object FileWordCount {

      def main(args: Array[String]) {

        val sparkConf = new SparkConf().setAppName("FileWordCount").setMaster("local[2]")

        // 创建Streaming的上下文,包括Spark的配置和时间间隔,这里时间为间隔20秒

        val ssc = new StreamingContext(sparkConf, Seconds(20))

        // 指定监控的目录,在这里为/home/hadoop/temp/

        val lines = ssc.textFileStream("/home/hadoop/temp/")

        // 对指定文件夹变化的数据进行单词统计并且打印

        val words = lines.flatMap(_.split(" "))

        val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _)

        wordCounts.print()

           // 启动Streaming

        ssc.start()

        ssc.awaitTermination()

      }

    }

  • 相关阅读:
    「CF1039D」You Are Given a Tree
    「NOIP2016」换教室
    「NOIP2014」飞扬的小鸟
    「AMPPZ2014」The Prices
    POj-3104 Drying 二分+贪心
    HDOJ1312<DFS>
    STL入门2
    HDU1425 <sort 快排>
    2304: Lights Out(枚举)
    1018:放苹果(递归)
  • 原文地址:https://www.cnblogs.com/xueqiuxiang/p/14467003.html
Copyright © 2011-2022 走看看