我正在为一个程序写一个测试用例。为此,我正在读取一个csv文件,其中包含以下格式的数据。 account_number,struct_data 123456789,{"key1":"value","key2":"value2","keyn":"valuen"} 987678909,{"key1":"value0","key2":"value20","keyn":"valuen0"}
有几百排这样的队伍。
我需要把第二列当作一个结构来读。但我得到了错误 struct type expected, string type found
我尝试强制转换为structtype,然后得到错误为“stringtype无法转换为structtype”。
我应该改变我的csv吗?我还能做什么?
2条答案
按热度按时间fd3cxomn1#
如果所有json记录都具有相同的模式,那么可以定义该模式并使用sparks
from_json()
完成你的任务。此代码段产生以下输出:
ijxebb2r2#
我在scala spark中给出了我的解决方案,它可能会对您的查询提供一些见解