当前位置:网站首页>Flink Format系列(1)-JSON
Flink Format系列(1)-JSON
2022-07-24 05:19:00 【sf_www】
Flink的json格式支持读和写json格式的数据,只需要指定 'format' = 'json',下面以kafka为例。
CREATE TABLE teacher (
name STRING,
age INT,
title ROW<id INT, name STRING, level INT>,
addr STRING
) WITH (
'connector' = 'kafka',
'topic' = 'test_teacher_info',
'properties.bootstrap.servers' = 'localhost:9092',
'properties.group.id' = 'testGroup',
'format' = 'json',
'json.fail-on-missing-field' = 'false',
'json.ignore-parse-errors' = 'true'
)
关键配置的说明:
json.fail-on-missing-field:就是在json缺失字段时是否报错
json.ignore-parse-errors:在解析json失败时是否报错
一般无法保证json格式,所以以上两个配置是比较重要的。
因为有ROW和ARRAY、MAP的数据类型,所以可以解析复杂的嵌套的json格式,通过xx.xx来访问内部嵌套的json字段。比如上面的就可以通过 select title.name 来访问title这个子json里的name值。比如来的数据是:
{"name":"jack", "age":44, "title":{"id":1, "name":"副教授", "level": 3}, "addr":"xxxx1"}
{"name":"rose", "age":47, "title":{"id":1, "name":"副教授", "level": 2}, "addr":"xxxx2"}
这里注意title的嵌套json的格式,别写成了 "title":\"{\"id\":1, \"name\":\"副教授\", \"level\": 3}\"这种格式,不然会报错,无法将TextNode转化为ObjectNode。
一些使用注意说明:
1)Json 中的每个 {} 都需要用 Row 类型来表示
2)Json 中的每个 [] 都需要用 Arrary 类型来表示
3)数组的下标是从 1 开始的不是 0
4)SQL中字段名是关键字时,需要用反引号修饰 例如:`timestamp`
5)select 语句中的字段类型和顺序一定要和结果表的字段类型和顺序保持一致
json类型和flink sql类型的对应关系
边栏推荐
- Summary of data types
- 16进制转rgb
- Function_ This keyword
- Mapboxgl + GeoServer configuration local map tutorial
- 关于DAO流动性双币质押挖矿开发原理分析
- The project is deployed to the public network for free (intranet penetration)
- 函数多种类型
- How can the multiple-choice and single choice results of PHP be displayed in the foreground?
- 6. Draw a Bezier curve and a Bezier surface on the screen
- 动画 效果
猜你喜欢
随机推荐
LP双币流动性质押挖矿系统逻辑开发分析
Polkadot | 一文解读颠覆传统社媒的Liberty计划如何在波卡落地
Why is music NFT popular? Polkadot may become the best choice for developing music NFT
canvas - 圆形
Geoserver自动化上传Shapefile
Oracle数据库的逻辑结构
【虚拟化】如何将虚拟机从workstation转换到esxi
Draw a square on the screen and use ice BMP texture maps the square; Draw a yellow teapot after the square. Assuming that the square is transparent, draw the mixed effect of teapot and square; Adjust
整站下载器推荐
一文node安装下载和配置
WASM VS EVM,波卡的选择预示了公链未来
还原ui设计稿
The repetition detection function of PHP multi line text content and count the number of repetitions
按钮 渐变
Vulnhub solidstate: 1 target penetration test
THREE——OrbitControls轨道控制器
Interpretation of the randomness of POS mechanism, how does poca's randomness principle work?
PyCharm设置代码模板
自定义MVC 1.0
How to use phpstudy to build WordPress website locally









