【发布时间】:2021-08-19 18:37:45
【问题描述】:
json 文件:
"products":[{"productId":"8d809e13-fdc5-4d15-9271- 953750f6d592","quantity":500,"soldPrice":104.852}, {"productId":"ec15ba1d-53b6-44b0-8a22- 1e498485f1b8","quantity":300,"soldPrice":94.3668}, {"productId":"e672483e-57a8-434a-bc42- ecf827c8a8d4","quantity":1000,"soldPrice":109.57034}], "shippingAddress":{"attention":"Khaleesi Frost","address":"493 Augustine Drive N ","city":"Miramar","state":"FL","zip":"33785"}
我可以使用explode 方法访问“产品”,因为它是ArrayType。但“shippingAddress”的值为 null。
`select(F.col("shippingAddress.attention").alias("shipping_address_attention"),
F.col("shippingAddress.address").alias("shipping_address_address"))`
json 架构:
StructField('shippingAddress' , StructType([ StructField('attention' , StringType(), True), StructField('address' , StringType(), True), StructField('city' , StringType(), True), StructField('state' , StringType(), True), StructField('zip' , IntegerType(), True) ]))
【问题讨论】: