Pyspark“repeat”函数错误:列不是callab

2024-05-29 09:33:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在select语句中进行一个简单的计算,如下所示:

for d in dataframes:
    d = d.select(
      'request_timestamp',
      'shard_id',
      'account_id',
      repeat(lit('1'), (13 - length('account_id').cast(IntegerType()))).alias('custom'))
    d.show()

repeat函数返回以下错误:

^{pr2}$

我知道用udf可以很容易地做到这一点,但是我想理解为什么即使我把它转换成Integer,我也不能完成这个任务。在


Tags: inidforrequestaccount语句selectlength
1条回答
网友
1楼 · 发布于 2024-05-29 09:33:35

Spark的repeat只能将普通整数作为第二个参数处理。但是配置单元的repeat可以处理计算,并且可以将其与expr一起使用,如下所示:

df.select(expr('repeat(1, 13 - length(account_id))').alias('custom'))

相关问题 更多 >

    热门问题