创建配置单元视图

tv6aics1  于 2021-06-28  发布在  Hive
关注(0)|答案(1)|浏览(499)

我有一个名为find\u distance的配置单元udf,它计算一对lat long坐标之间的坐标距离。我还有一个表格,里面有城市名称和它们各自的纬度坐标。因此,目前如果我需要找到两个城市之间的距离,比如丹佛和圣何塞,我需要执行自连接:

Select find_Distance(cityA.latitude, cityA.longitude, cityB.latitude, cityB.longitude) from
(select latitude, longitude from city_data.map_info where city = 'Denver') cityA
join
(select latitude, longitude from city_data.map_info where city = 'San Jose') cityB;

如何构建一个只接受城市名称作为参数的视图?所以实际上我可以

SELECT distance from city_distance where cityA = 'Denver' and cityB = 'San Jose'
cgvd09ve

cgvd09ve1#

尝试此视图:

CREATE VIEW city_distance AS
SELECT
  cityA.city as city_from,
  cityA.city as city_to,
  find_Distance(cityA.latitude, cityA.longitude, cityB.latitude, cityB.longitude) as distance
FROM
  (SELECT city, latitude, longitude FROM city_data.map_info) cityA
  CROSS JOIN
  (SELECT city, latitude, longitude FROM city_data.map_info) cityB;

相关问题