【发布时间】:2019-07-15 22:41:26
【问题描述】:
我的 T-SQL 代码在下面,我在 Pyspark 中进行了转换,但给了我错误
CASE
WHEN time_on_site.eventaction = 'IN' AND time_on_site.next_action = 'OUT' AND time_on_site.timespent_sec < 72000 THEN 1 -- 20 hours
WHEN time_on_site.eventaction = 'IN' AND time_on_site.next_action = 'OUT' AND time_on_site.timespent_sec >= 72000 THEN 0
WHEN time_on_site.eventaction = 'IN' AND time_on_site.next_action = 'IN' AND time_on_site.timespent_sec <= 28800 THEN 2 -- 8 hours
WHEN time_on_site.eventaction = 'IN' AND time_on_site.next_action = 'IN' AND time_on_site.timespent_sec > 28800 THEN 3
WHEN time_on_site.type_flag = 'TYPE4' THEN 4
ELSE NULL
END AS "type"
下面是我抛出错误的 Pyspark 脚本
from pyspark.sql.functions import when
TOS=TOS.withColumn('type', F.when( (col('eventaction') == 'IN') & (col('next_action') == 'OUT') & ("timespent_sec < 72000") , 1).
when( (col('eventaction') == 'IN') & (col('next_action') == 'OUT') & ("timespent_sec >= 72000") , 0).
when( (col('eventaction') == 'IN') & (col('next_action') == 'IN') & ("timespent_sec <= 28800") , 2).
when( (col('eventaction') == 'IN') & (col('next_action') == 'IN') & ("timespent_sec > 28800") , 3).
when(col('type_flag')=='TYPE4', 4).otherwise('NULL')
)
我哪里错了!?
【问题讨论】:
-
我看不出您的代码有任何明显错误。错误是什么?
标签: tsql pyspark apache-spark-sql case-when .when