2017-11-07 5 views
0

は、我々は次のようにgroupByとイベント時間にウィンドウ操作を行うことができます。spark.sql.Dataset.groupByKeyは、groupByのようなウィンドウ操作をサポートしていますか?スパーク構造化されたストリーミングで

import spark.implicits._ 

val words = ... // streaming DataFrame of schema { timestamp: Timestamp, word: String } 

// Group the data by window and word and compute the count of each group 
val windowedCounts = words.groupBy(
    window($"timestamp", "10 minutes", "5 minutes"), 
    $"word" 
).count() 

groupByKeyは、ウィンドウ操作をサポートしていますか?

ありがとうございました。

答えて

1

はい、いいえ。それが唯一のSQL/DataFrame APIに適用可能であることは、直接使用することはできませんが、あなたは常にウィンドウのフィールドを持つレコードを拡張することができます。

val dfWithWindow = df.withColumn("window", window(...))) 

case class Window(start: java.sql.Timestamp. end: java.sql.Timestamp) 
case class MyRecordWithWindow(..., window: Window) 

とグループ化のためにそれを使用します。

dfWithWindow.as[MyRecordWithWindow].groupByKey(_.window).mapGroups(...) 
関連する問題