pyspark Spark Dataframe时间戳列操作失败,没有任何错误消息

wdebmtf2  于 2022-12-03  发布在  Spark
关注(0)|答案(1)|浏览(117)
aggregate = aggregate.withColumn('DaysSinceFirstUsage', when(months_between(current_date(), col('FirstUsage')) > 120, - (sys.maxsize - 1)).otherwise(days_between(current_date(), col('FirstUsage')))

aggregate = aggregate.withColumn('DaysSinceLastUsage', when(months_between(current_date(), col('LastUsage')) > 120, - (sys.maxsize - 1)).otherwise(days_between(current_date(), col('LastUsage')))
watbbzwu

watbbzwu1#

愚蠢的错误:)结尾的右括号丢失,并且datediff错误地写为days_between。更正后查询运行良好。

aggregate = aggregate.withColumn('DaysSinceFirstUsage', when(months_between(current_date(), col('FirstUsage')) > 120, - (sys.maxsize - 1)).otherwise(datediff(current_date(), col('FirstUsage'))))
aggregate = aggregate.withColumn('DaysSinceLastUsage', when(months_between(current_date(), col('LastUsage')) > 120, - (sys.maxsize - 1)).otherwise(datediff(current_date(), col('LastUsage'))))

相关问题