2017-05-08 127 views
1

我解析存儲爲行JSON表中的Json_tuple說,在蜂巢

它解析它具有簡單的字符串而不是文件路徑

例如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 
+0

1)是否有問題? 2)在發佈之前是否檢查過您的代碼? (顯然不是)3)如果你聲稱Json_tuple返回一個錯誤(我懷疑它)將其添加到您的文章 –

回答

0
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  | 
+------------+------------------------------+------------------+---------+