通过更新同一列来实现滞后功能



我已经将条形码(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).

我不熟悉pyspark,但在我看来,问题是在案例语句中。

CASE WHEN (
        LAG(barcode,1) OVER (ORDER BY barcode ) 
    AND
        DATEDIFF(SS, eventdate, LAG(next_eventdate, 1) OVER(ORDER BY barcode)) < 3*3600
)

有两个表达式:"滞后(条形码,1)(条形码订单)",将整数评估。

"日期(ss,eventdate,lag(next_eventdate,1)off(按条形码订购))&lt; 3*3600",对布尔值进行评估(由于不等式)。

这些表达式与通常用于结合两个布尔表达式的运算符结合。我相信这是造成错误的原因。

滞后(条形码,1)(条形码订单)评估整数而不是布尔值。

所以表达式看起来像:

CASE WHEN (324857 AND True) THEN 1 ELSE 0 END as FLAG
AnalysisException: "cannot resolve .... (int and boolean).

相关内容

  • 没有找到相关文章

最新更新