导读:在日常开发中常有这么一个场景,采集如日志等数据后以JSON形式存储到Kafka中,再由Flink从Kafka中获取数据并进行处理。但是有时候JSON比较复杂(多层嵌套),在FlinkSQL中解析起来比较麻烦,下面将讨论Flink SQL(1.10版本) 如何解析复杂JSON。
官网Demo
//JSON Format
https://ci.apache.org/projects/flink/flink-docs-release-1.10/dev/table/connect.html#table-formats
首先查看官网给出的一个例子,大致的解决思路为使用 format.json-schema,自定义一个format schema。
//官网例子CREATE TABLE MyUserTable ( ...) WITH ( 'format.type' = 'json', -- required: specify the format type 'format.fail-on-missing-field' = 'true' -- optional: flag whether to fail if a field is missing or not, false by default 'format.fields.0.name' = 'lon', -- optional: define the schema explicitly usin