【发布时间】:2022-01-19 22:06:24
【问题描述】:
我有事件开始时间的DataFrame:
val dailySummariesDfVisualize =
dailySummariesDf
.orderBy("event_time").registerTempTable("raw")
val df = sqlContext.sql("select * from raw")
df.show()
+--------------------+-------------------+-------------+-----------------+---------------+
| event_type| event_time|event_payload|coffee_machine_id|digital_twin_id|
+--------------------+-------------------+-------------+-----------------+---------------+
|Large_Cup_Button_...|2021-03-24 07:06:34| null| NP20100005| NP20100005|
|Large_Cup_Button_...|2021-03-24 07:07:41| null| NP20100005| NP20100005|
我希望每个 event_time 行都是时间范围的开始,event_time+1 minute 是时间范围的结束,并且时间范围的数量与上面 DataFrame 中的行数一样多。我想查询并从另一个表中提取到新的 DataFrame ,只有每个时间范围的开始和结束之间的项目。我怎样才能做到这一点?在这里加入是唯一的选择,还是网络查询有用?或者可能只有 DataFrame 上的 foreach 有帮助?
【问题讨论】:
-
可能是一个窗口函数,但你能指定你期望的输出吗?因为描述有点不清楚。
-
@Kombajnzbożowy 发现从相对较小的数据集中提取 where 子句以从大数据集中提取唯一需要的数据对我的情况很好,我将添加答案
标签: scala apache-spark apache-spark-sql apache-zeppelin