我有这个schema 1:
我尝试对结构体上的元素进行排序,并在schema 2中的任何位置添加一些新元素作为NULL:
我试过这个:
df.withColumn("sample",
expr("transform(sample, x -> struct(x.elem1, x.elem2, 'NULL' as elem2, x.elem3,x.elem4, x.elem5, x.elem6 , x.elem7))"))
我得到了这个错误:
只有可折叠字符串表达式才允许出现在奇数位置,得到:NamePlaceholder,NamePlaceholder,NamePlaceholder,NamePlaceholder,NamePlaceholder,NamePlaceholder,NamePlaceholder;线1位置45;
有人帮忙吗?谢谢
1条答案
按热度按时间mdfafbf11#
作品制作:
使用struct将为null引入生成的列名,因此:
产量:
因此,您需要通过named_struct指定名称。
至于你得到的错误,不知道,它看起来很奇怪。使用withColumn和expr也不会失败。你用的是什么Spark版本?