【发布时间】:2018-12-20 14:40:38
【问题描述】:
我正在使用 JSON 对象,并希望基于 Spark SQL 数据帧/数据集将 object.hours 转换为关系表。
我尝试使用“explode”,它并不真正支持“structs array”。
json 对象如下:
{
"business_id": "abc",
"full_address": "random_address",
"hours": {
"Monday": {
"close": "02:00",
"open": "11:00"
},
"Tuesday": {
"close": "02:00",
"open": "11:00"
},
"Friday": {
"close": "02:00",
"open": "11:00"
},
"Wednesday": {
"close": "02:00",
"open": "11:00"
},
"Thursday": {
"close": "02:00",
"open": "11:00"
},
"Sunday": {
"close": "00:00",
"open": "11:00"
},
"Saturday": {
"close": "02:00",
"open": "11:00"
}
}
}
到如下关系表,
CREATE TABLE "business_hours" (
"id" integer NOT NULL PRIMARY KEY,
"business_id" integer NOT NULL FOREIGN KEY REFERENCES "businesses",
"day" integer NOT NULL,
"open_time" time,
"close_time" time
)
【问题讨论】:
标签: apache-spark apache-spark-sql