You can create a new array of structs column and concat to the existing column:
import pyspark.sql.functions as F
english = F.struct(F.lit('10').alias('code'),
F.lit('English Language').alias('description'),
F.lit('English').alias('name')
)
df2 = df.withColumn(
'languageknowList',
F.when(
~F.array_contains(F.col('languageknowList'), english),
F.concat(
F.col('languageknowList'),
F.array(english)
)
).otherwise(
F.col('languageknowList')
)
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…