Apache Drill:保留字“user”作为json数据文件中的列名之一

时间:2017-10-20 12:10:28

标签: json keyword apache-drill

我正在查询嵌套的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}

我有一个名为“user”的嵌套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文件更改列的名称,如何解决此问题?

1 个答案:

答案 0 :(得分:1)

我在文档中查了一下。使用反引号作为保留字。

  

因为列别名包含特殊空格字符,所以也要在后面的刻度中包含别名,如下例所示

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

在你的情况下:

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