使用apache drill查询嵌入式json时出错

时间:2015-08-26 10:48:11

标签: apache-drill

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`;

显示错误。

  

表'击球手'找不到

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

1 个答案:

答案 0 :(得分:1)

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

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

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