Json_tuple 表示 hive 中的无效 json

标签 json parsing hadoop hive

我正在解析存储为表中的行的 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/

相关文章:

hadoop - 使用 sqlcontext spark 执行 sql join

javascript - 使用JS从JSON文件中读取并计算数据

json - 为什么struct field的格式串总是小写

c# - 解析 Visual Studio 解决方案文件

regex - perl 解析格式错误的括号文本

java - 使用键名包含句点 (.) 的 gson 解析 JSON

java - 通过 Mapreduce 压缩解压缩 Hdfs 文件时附加制表符分隔列

hadoop - 什么先运行 : the partitioner or the combiner?

python - Django REST json解析id而不是name

c# - 具有抽象类作为方法参数的 WCF 服务