Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

apache spark - why doesn't lit() function work in selectExpr()?

df.selectExpr(func.lit(20)).show()
df.selectExpr("func.lit(20)").show()

Throwing Error :

raise TypeError("Column is not iterable")
TypeError: Column is not iterable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should either use

df.select(func.lit(20))

or

df.selectExpr("20")

selectExpr expects a raw SQL string that can be selected, while select expects a column object, such as func.lit(20), or a column name as a string.

columns should not be used in selectExpr.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...