请查找数据格式
c3f36c25-2546-48b2-bd72-1b5e5dcae2ab/1620247529/{6032:{"advertisers":{"Amoma":[{"eurocents":17256,"breakfast":false}]
试过下面的
valsschema=List(
("Userid", StringType, true),
("unix_time", IntegerType, true),
("hotelresults",MapType(IntegerType,true,StructType(("advertisers",MapType(StringType,true,ArrayType(StructType("eurocents",IntegerType,true,"breakfast",BooleanType,true))))))
)
1条答案
按热度按时间ycl3bljg1#
使用add方法生成structtype可能更容易。
似乎您的整个文件是一个csv格式,带有“/”(斜杠)分隔符:
您的第3列json无效,因此在此更改:
使用
from_json
方法(使用通配符导入以确保导入所有内容):基于注解编辑(直接解析平面文件)
内置的csv解析器只能解析带有一个分隔符的文件。解决方法是使用split scala string方法。
结果