gpt4 book ai didi

Json_tuple 表示 hive 中的无效 json

转载 作者:可可西里 更新时间:2023-11-01 15:55:59 30 4
gpt4 key购买 nike

我正在解析存储为表中的行的 json

它解析具有简单字符串但不包含文件路径的 json 行

例如:

{
"CustomerID": "C101",
"BillLocation": "C:\Customer\Files\C101\1.txt",
"CustomerLocation": "NY",
"Company":"XYZ"
}

我尝试了在线 json 验证器,它在账单位置给出了错误,但是当将\附加到所有存在\的地方时,它验证了,像这样 C:\\Customer\\Files\C101\\1.txt

select a.CustomerID,
a.BillLocation,
a.CustomerLocation,
Company from db.jsontable b
LATERAL VIEW json_tuple(b.json,'CustomerId','BillLocation','CustomerLocation','CustomerLocation') a as CustomerId,BillLocation,CustomerLocation,CustomerLocation

最佳答案

select  a.*

from jsontable b

lateral view

json_tuple
(
regexp_replace(b.json,'\\\\','\\\\\\\\')
,'CustomerID','BillLocation','CustomerLocation','CustomerLocation','Company'
) a as CustomerId,BillLocation,CustomerLocation,CustomerLocation,Company

+------------+------------------------------+------------------+---------+
| customerid | billlocation | customerlocation | company |
+------------+------------------------------+------------------+---------+
| C101 | C:\Customer\Files\C101\1.txt | NY | XYZ |
+------------+------------------------------+------------------+---------+

关于Json_tuple 表示 hive 中的无效 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43847196/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com