Apache Drill 查询 JSON 列名中有空格

Apache Drill to query JSON having whitespace in column name

我的数据集格式如下:

    {  
   "business_id":"5UmKMjUEUNdYWqANhGckJw",
   "full_address":"4734 Lebanon Church Rd\nDravosburg, PA 15034",
   "hours":{  
      "Friday":{  
         "close":"21:00",
         "open":"11:00"
      },
      "Tuesday":{  
         "close":"21:00",
         "open":"11:00"
      },
      "Thursday":{  
         "close":"21:00",
         "open":"11:00"
      },
      "Wednesday":{  
         "close":"21:00",
         "open":"11:00"
      },
      "Monday":{  
         "close":"21:00",
         "open":"11:00"
      }
   },
   "open":true,
   "categories":[  
      "Fast Food",
      "Restaurants"
   ],
   "city":"Dravosburg",
   "review_count":4,
   "name":"Mr Hoagie",
   "neighborhoods":[  

   ],
   "longitude":-79.9007057,
   "state":"PA",
   "stars":4.5,
   "latitude":40.3543266,
   "attributes":{  
      "Take-out":true,
      "Drive-Thru":false,
      "Good For":{  
         "dessert":false,
         "latenight":false,
         "lunch":false,
         "dinner":false,
         "brunch":false,
         "breakfast":false
      },
      "Caters":false,
      "Noise Level":"average",
      "Takes Reservations":false,
      "Delivery":false,
      "Ambience":{  
         "romantic":false,
         "intimate":false,
         "classy":false,
         "hipster":false,
         "divey":false,
         "touristy":false,
         "trendy":false,
         "upscale":false,
         "casual":false
      },
      "Parking":{  
         "garage":false,
         "street":false,
         "validated":false,
         "lot":false,
         "valet":false
      },
      "Has TV":false,
      "Outdoor Seating":false,
      "Attire":"casual",
      "Alcohol":"none",
      "Waiter Service":false,
      "Accepts Credit Cards":true,
      "Good for Kids":true,
      "Good For Groups":true,
      "Price Range":1
   },
   "type":"business"
}

我想查询数据集的属性。但是,许多属性名称中都有 space。如何使用 space 引用属性名称?示例 - 我想查找维加斯餐馆的平均值 'Price Range'。我尝试使用以下方式引用它:

select avg(`t.attributes.Price Range`) from `mongo.274_BI`.`yelp_dataset`t where t.city = 'Las Vegas';

它returns 无效。由于价格和范围之间的 space 存在问题。我查询 'Parking' 字段没有问题。我该如何解决这个问题?

使用以下查询:

select avg(t.attributes.`Price Range`) from `mongo.274_BI`.`yelp_dataset`t where t.city = 'Las Vegas';

此外,您可能需要 CAST attributes.Price Range 作为 int 或 double。

示例:

select avg(cast(t.attributes.`Price Range` as double)) from `mongo.274_BI`.`yelp_dataset`t where t.city = 'Las Vegas';