【发布时间】:2019-03-01 07:39:16
【问题描述】:
我必须将条形码 (offset=1) 的滞后值更新为条形码
case
when ( lag(barcode,1) over (order by barcode )
and Datediff(SS, eventdate,lag(next_eventdate,1) over (order by barcode)) < 3*3600 )
THEN 1
ELSE 0
END as FLAG
我已经在 pyspark 上实现了它,但是给我一个错误
from pyspark.sql.functions import col, unix_timestamp
timeDiff = unix_timestamp('eventdate', format="ss")- unix_timestamp(F.lag('next_eventdate', 1), format="ss")
ww= Window.orderBy("barcode")
Tgt_df_tos = Tgt_df_7.withColumn('FLAG',F.when((F.lag('barcode', 1)) & ( timeDiff <= 10800),"1").otherwise('0'))
我遇到的错误
AnalysisException: "cannot resolve '(lag(`barcode`, 1, NULL) AND ((unix_timestamp(`eventdate`, 'ss') - unix_timestamp(lag(`next_eventdate`, 1, NULL), 'ss')) <= CAST(10800 AS BIGINT)))' due to data type mismatch: differing types in '(lag(`barcode`, 1, NULL) AND ((unix_timestamp(`eventdate`, 'ss') - unix_timestamp(lag(`next_eventdate`, 1, NULL), 'ss')) <= CAST(10800 AS BIGINT)))' (int and boolean).
【问题讨论】:
-
如果您遇到错误,请同时发布
标签: tsql pyspark pyspark-sql lag lead