Scala:检查当前的时间戳是否大于数据帧中的时间戳列



假设我有一个数据帧,其中存在Timestamp列。

Timestamp  
2016-04-19T17:13:17  
2016-04-20T11:31:31  
2016-04-20T18:44:31  
2016-04-20T14:44:01  

我必须检查当前timsetamp是否大于Scala 中的Timestamp + 1列(即增加1天)

DataFrame支持两种类型的current_日期和时间戳

让我们考虑一个具有id和event_date列的DataFrame-df。

我们可以执行以下过滤操作:

import sqlContext.implicits._
import org.apache.spark.sql.functions._
// the event_date is before the current timestamp
df.filter('event_date.lt(current_timestamp()))
// the event_date is after the current timestamp
df.filter('event_date.gt(current_timestamp()))

我建议您阅读相关的scala-doc以获取更多信息。您有一整节关于日期和时间戳操作的内容。

编辑:如评论中所述,为了在event_date列中添加一天,您可以使用date_add函数:

df.filter(date_add('event_date,1).lt(current_timestamp()))

你可以这样做。

df.filter(date_add('column_name', 1).lt(current_timestamp()))

最新更新