当前位置:网站首页>Spark SQL generate JSON
Spark SQL generate JSON
2022-06-28 15:06:00 【shengjk1】
background
Want to pass spark sql Inquire about hive The table then assembles the corresponding fields into sql, Be similar to json_object , But unfortunately spark 3.1.x did not json_object function , But also good spark sql Yes to_json function
Example :
SELECT to_json(struct(bis_type,year,douban_rating))
from tv.test where date=20220620
limit 10
SELECT to_json(named_struct('bis_type',bis_type,'year',year,'douban_rating',douban_rating))
from tv.test where date=20220620
limit 10
result , You can keep the original data type . This is the most important point , assemble json, Keep the data type of the original field
{
"bis_type":"xxx","year":2022,"douban_rating":8.3}
How to generate nested json
SELECT to_json(array(named_struct('ruleType', 'datetime', 'ruleDetail', array(map('columnName', 'a1','function','test'),map('columnName', 'a2','function','test')))));
result
[
{
"ruleType": "datetime",
"ruleDetail": [
{
"columnName": "a1",
"function": "test"
},
{
"columnName": "a2",
"function": "test"
}
]
}
]
边栏推荐
- Spacetutorial (continuous updating...)
- R语言ggplot2可视化:使用patchwork包将两个ggplot2可视化结果纵向堆叠起来(stacking)形成组合图、一个可视化结果堆叠在另外一个可视化结果上
- Leetcode (167) -- sum of two numbers II - input ordered array
- 【数字IC精品文章收录】近500篇文章|学习路线|基础知识|接口|总线|脚本语言|芯片求职|安全|EDA|工具|低功耗设计|Verilog|低功耗|STA|设计|验证|FPGA|架构|AMBA|书籍|
- Softing epGate PB系列网关-可将PROFIBUS总线集成到EtherNet/IP网络
- 5000倍回报,南非报业投资腾讯赚了一个省
- R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和数据表格横向组合起来形成最终结果图
- The latest pycharm activation cracking code in 2022 is permanent_ Detailed installation tutorial (applicable to multiple versions)
- 从五大能力到 “1+5+N”,华为让政企转型更稳健
- 云杉网络DeepFlow帮助5G核心网和电信云构建可观测性
猜你喜欢

完整的模型训练套路(一)

Jackie Chan and fast brand, who is the Savior of Kwai?
Yiwen teaches you to quickly generate MySQL database diagram
![[C language] implementation of binary tree and three Traversals](/img/9f/384a73fb82265a76fc5eef884ce279.png)
[C language] implementation of binary tree and three Traversals

新零售线下店逆势起飞,通膨乌云下的消费热情

第四大运营商,难成「鲶鱼」

Softing epGate PB系列网关-可将PROFIBUS总线集成到EtherNet/IP网络

优巨新材冲刺深交所:拟募资6.5亿 年营收3.33亿

成龙和快品牌,谁才是快手的救星?

The latest pycharm activation cracking code in 2022 is permanent_ Detailed installation tutorial (applicable to multiple versions)
随机推荐
seata-server 1.5.0 如何支持mysql8.0?
Yiwen teaches you to quickly generate MySQL database diagram
云杉网络DeepFlow帮助5G核心网和电信云构建可观测性
The hidden crisis of Weilai: past, present and future
老板嘱咐了三遍:低调、低调、低调
Functools: high order functions and operations on callable objects (continuous updating ing...)
【mysql学习笔记24】索引设计原则
Li Kou today's question -522 Longest special sequence
Q-tester 3.2: applicable to development, production and after-sales diagnostic test software
使用LamdbaUpdateWrapper的setSql作用及风险
How to solve the following problems in the Seata database?
Rails进阶——框架理论认知与构建方案建设(一)
2022年最新PyCharm激活破解码永久_详细安装教程(适用多版本)
Not being a meta universe now is like not buying a house 20 years ago!
[C language] nextday problem
利用MySqlBulkLoader实现批量插入数据的示例详解
最长连续序列
Differences between ram ROM flash
【mysql学习笔记23】索引优化
股票开户优惠链接,我如何才能得到?手机开户是安全么?