我正在做一个Spark的框架,看起来像这样:
x1c 0d1x的数据
我想subscurt(如果它的utc-)/add(如果它的utc+)“utc_time”小时量到“local 2”日期时间。我想使用expr函数来完成。我想使用的是,如果“utc”是+,将“utc_time”添加到“local 2”日期时间。下面你可以看到我的代码:
df = df.withColumn('updated_local', when((substring('utc', 4, 1))=='+',(df.local2 + expr(format_string("INTERVAL %s HOURS", "utc_time"))) ).otherwise('whatever'))
字符串
但我得到一个'列是不可迭代'的错误时,使用这个。
如果我不使用格式字符串并像这样构造它,它就可以工作:
df = df.withColumn('updated_local', when((substring('utc', 4, 1))=='+',(df.local2 + expr("INTERVAL 10 HOURS")) ).otherwise('whatever'))
型
我喜欢expr函数以外的方法,如果你们有的话。
1条答案
按热度按时间wkftcu5l1#
你可以使用下面的代码,它应该工作:
字符串
问候