【问题标题】:Error in querying embedded json using apache drill使用 Apache Drill 查询嵌入式 json 时出错
【发布时间】:2015-08-27 07:36:53
【问题描述】:

donutTest.json(在我的本地系统 /home/dev 中):

{
   "id":"0001",
   "type":"donut",
   "name":"Cake",

   "batter":{
            "id":"1001",
            "type":"Regular"
           },

   "topping":[
             { "id":"5001", "type":"None"},
             { "id":"5002", "type":"Glazed"}  
             ]
 }

此查询运行良好。

 select topping[0].id as topping_id, topping[3].type as topping_type from dfs.`/home/dev/donutTest.json`;

但是当我尝试时:

select batter.id as batter_id, batter.type as batter_type from dfs.`/home/dev/donutTest.json`;

显示错误。

找不到表'batter'

topping[0]batter 都是嵌入文档仍然错误。

【问题讨论】:

    标签: apache-drill


    【解决方案1】:

    尝试使用表别名,然后在 select 语句中引用它。

    select donut.batter.id as batter_id, donut.batter.type as batter_type from dfs.`/home/dev/donutTest.json` as donut;
    

    这样,Drill 引用了实际的表别名,然后是下面的嵌套结构。

    【讨论】:

    • 为什么在 topping[0].id 的情况下不需要表格符号?
    • 这不是一个很有启发性的答案,但它来自文档apache.github.io/drill/docs/json-data-model/#analyzing-json,其中说 y、y[z] 或 y[z].x 引用并不模棱两可,但 Drill目前明确需要一个表前缀来引用另一个字段 (t.y.z) 中的字段。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多