本文整理汇总了Scala中org.apache.spark.sql.functions.window类的典型用法代码示例。如果您正苦于以下问题:Scala window类的具体用法?Scala window怎么用?Scala window使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了window类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: OnlineHotestItems
//设置package包名称以及导入依赖的类
package com.jjzhk.sparkexamples.streaming
import java.sql.Timestamp
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.window
object OnlineHotestItems {
def main(args: Array[String]): Unit = {
val spark = SparkSession.builder().master("spark://Master:7077").appName("OnlineHotestItems").getOrCreate()
val lines = spark.readStream.format("socket").option("host", "Master").option("port", 9999)
.option("includeTimestamp", true).load()
import spark.implicits._
val words = lines.as[(String, Timestamp)].flatMap(line =>
line._1.split(" ").map(word => (word, line._2))
).toDF("word", "timestamp")
import spark.implicits._
val windowedCounts = words.groupBy(
window($"timestamp", "", ""), $"word"
).count().orderBy("window")
// Start running the query that prints the windowed word counts to the console
val query = windowedCounts.writeStream
.outputMode("complete")
.format("console")
.option("truncate", "false")
.start()
}
}