2015-08-26 34 views
0

donutTest.json(在我的本地系统中的/ home/DEV)查询嵌入式JSON:错误使用Apache钻

{ 
    "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

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

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

这种方式Drill具有对实际表别名的引用,然后引用下面的嵌套结构。

+0

为什么表格符号在顶部[0] .id的情况下不需要? –

+1

这不是一个非常有启发性的答案,但它来自文档http://apache.github.io/drill/docs/json-data-model/#analyzing-json,它表示y,y [z]或y [z] .x引用不是不明确的,但Drill当前明确需要一个表前缀来引用另一个字段(tyz)内的字段。 – catpaws

+0

@catpaws您的评论是有帮助的.... + 1为此 –