2017-10-20 60 views
0

我查詢一個嵌套的JSON文件,結構看起來類似如下阿帕奇鑽:保留字「用戶」作爲JSON數據文件中的列名的一個

{"user_id":1234, 
"text":"example text" 
"first_nested":{ 
       "field1":"dummy string 1", 
       "field2":"dummy string 2" 
       }, 
    "user":{ 
      "field3":"dummy string 3", 
      "field4":"dummy string 4" 
      }, 
    "last":1} 

我有一個名爲嵌套JSON結構「用戶」,當查詢以下內容:

SELECT tbl.user AS us FROM dfs.`/filepath/trial.json` as tbl WHERE user_id=221 

SELECT tbl.user.field1 AS us FROM dfs.`/filepath/trial.json` as tbl WHERE tbl.user_id=221 

我得到以下錯誤:

UserRemoteException: PARSE ERROR: Encountered ". user" at line 1, column 11. Was expecting one of: "FROM" ... "," ... "AS" ... ... ... ... ... ... "." ... "NOT" ... "IN" ... "BETWEEN" ... "LIKE" ... "SIMILAR" ... "=" ... ">" ... "<" ... "<=" ... ">=" ... "<>" ... "+" ... "-" ... "*" ... "/" ... "||" ... "AND" ... "OR" ... "IS" .. 

當我簡單地使用user與tbl解除引用。 ,查詢將返回擁有當前鑽取簡檔的用戶的名稱。

我不能從這個json文件中更改列的名稱,我該如何解決這個問題?

+0

*當我簡單地使用 「用戶」 不與TBL提領。 – user3516188

回答

1

我在文檔中查了一下。使用反引號保留字。

Because the column alias contains the special space character, also enclose the alias in back ticks, as shown in the following example

https://drill.apache.org/docs/lexical-structure/

你的情況:

SELECT tbl.`user`.field1 AS us FROM ...