【发布时间】:2019-03-09 05:42:50
【问题描述】:
有一个带有时间戳列(时间戳类型)的数据框,称为“maxTmstmp”,另一个带有小时的列,以整数表示,称为“WindowHours”。 我想动态减去时间戳和整数列以获得更低的时间戳。
我的数据和期望的效果(“minTmstmp”列):
+-----------+-------------------+-------------------+
|WindowHours| maxTmstmp| minTmstmp|
| | |(maxTmstmp - Hours)|
+-----------+-------------------+-------------------+
| 1|2016-01-01 23:00:00|2016-01-01 22:00:00|
| 2|2016-03-01 12:00:00|2016-03-01 10:00:00|
| 8|2016-03-05 20:00:00|2016-03-05 12:00:00|
| 24|2016-04-12 11:00:00|2016-04-11 11:00:00|
+-----------+-------------------+-------------------+
root
|-- WindowHours: integer (nullable = true)
|-- maxTmstmp: timestamp (nullable = true)
我已经找到了一个带有小时间隔解决方案的表达式,但它不是动态的。下面的代码无法按预期工作。
standards.
.withColumn("minTmstmp", $"maxTmstmp" - expr("INTERVAL 10 HOURS"))
.show()
在 Spark 2.4 和 scala 上运行。
【问题讨论】:
标签: scala apache-spark dataframe