spark在将嵌套json作为数据源时,schema的构造问题

    val schema = new StructType()
      .add("data",
        new StructType()
          .add("channel", "string", true)
          .add("mid", "string", true)
          .add("page", "string", true)
          .add("keyword", "string", true)
          .add("stay_time", "int", true))
      .add("distinct", "string", true)
      .add("time", "string", true)
      .add("type", "string", true)
      .add("event", "string", true)
      .add("properties",
        new StructType()
          .add("referer", "string", true)
          .add("ip", "string", true)
          .add("user_agent", "string", true))

对应的数据格式为:

{
   "data": {
       "channel": "channel",
       "mid": "mid",
       "page": "page",
       "keyword": "keyword"
   },
   "distinct_id": "distinct_id",
   "time": time,
   "type": "type",
   "event": "open/close",
   "properties": {
       "ip": "ip",
       "user_agent": "user_agent"
   }
}

你可能感兴趣的:(spark)