简体   繁体   English

从 pysapk 中的时间戳列中减去持续时间

[英]Subtracting time duration from timestamp column in pysaprk

I am trying to subtract a column with minutes stored from a timestamp column我正在尝试从时间戳列中减去存储分钟的列

And i know the following works for subtracting a fixed duration我知道以下用于减去固定持续时间的方法

from pyspark.sql.functions import current_timestamp, expr

(spark.range(1).select(
    current_timestamp().alias("now"), 
    (current_timestamp() + expr("INTERVAL 12 MINUTES")).alias("now_plus_twelve")))

Is there a way to call this duration value from a column with stored value?有没有办法从存储值的列中调用这个持续时间值?

something like this:像这样的东西:

(spark.range(1).select(
    current_timestamp().alias("now"), 
    (current_timestamp() + expr("INTERVAL col('duration_column) MINUTES")).alias("now_plus_twelve")))

I figured out this way it works:我发现它是这样工作的:

(spark.range(1).select(
    current_timestamp().alias("now"), 
    (current_timestamp() + col('duration_column')*expr("INTERVAL 1 minutes")).alias("now_plus_twelve")))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM