一、目的
在Hive的with嵌套语句时,HQL报错Line 2:5 Ambiguous table alias 't2'
二、报错详情
org.apache.hadoop.hive.ql.parse.SemanticException: Line 2:5 Ambiguous table alias 't2'
三、原SQL语句
with a2 as( with t2 as( select get_json_object(event_json,'$.id') id, get_json_object(event_json,'$.deviceNo') device_no, get_json_object(event_json,'$.createTime') create_time, get_json_object(event_json,'$.objList') obj_list from hurys_dc_ods.ods_event) select get_json_object(list_json,'$.id') id, t2.device_no, create_time, get_json_object(list_json,'$.eventType') event_type, ''lane_no, ''speed, get_json_object(list_json,'$.posX') pos_x, get_json_object(list_json,'$.posY') pos_y, ''brand,''source_image, ''source_num, ''source_type, ''source_url, ''direction_radar, ''congestion_grade,''target_count, ''lane_no_original, ''event_type_detail, get_json_object(list_json,'$.targetLen') target_len, ''queue_len,''queue_count,'' pos_head,''pos_tail, date(t2.create_time) day from t2 lateral view explode(split(regexp_replace(regexp_replace(obj_list, '\[|\]','') , '\}\,\{','\}\;\{'), '\;') )list_obj as list_json where t2.obj_list is not null group by t2.device_no, get_json_object(list_json,'$.id'), create_time, get_json_object(list_json,'$.eventType'), get_json_object(list_json,'$.posX'), get_json_object(list_json,'$.posY'), get_json_object(list_json,'$.targetLen')) select a2.id, device_no, create_time, event_type, lane_no, speed, pos_x, pos_y, brand, source_image, source_num, source_type, source_url, direction_radar, congestion_grade, target_count, lane_no_original, event_type_detail, target_len, queue_len, queue_count, pos_head, pos_tail, day from a2 ;
四、报错原因
看报错提示,Ambiguous table alias 't2',似乎是with嵌套子语句命名t2报错,但是我试了很多其他命名,都报类似的错误,如果大家知道原因的话还望告知,谢谢!
五、解决方式
既然不能使用with嵌套子语句,那就换种方式。
(一)with语句等同与另一种SQL方式
1、原有SQL方式
> select w.word,count(1) num from
> (select explode(split(line,"\\s")) word from wordcount) w
> group by w.word order by num desc;
2、with语句
> with
> t1 as (select explode(split(line,"\\s")) word from wordcount)
> select t1.word,count(1) num from t1 group by word order by num desc;
(二)新的SQL如下
with a2 as ( select get_json_object(list_json,'$.id') id, t2.device_no, create_time, get_json_object(list_json,'$.eventType') event_type, ''lane_no, ''speed, get_json_object(list_json,'$.posX') pos_x, get_json_object(list_json,'$.posY') pos_y, ''brand,''source_image, ''source_num, ''source_type, ''source_url, ''direction_radar, ''congestion_grade,''target_count, ''lane_no_original, ''event_type_detail, get_json_object(list_json,'$.targetLen') target_len, ''queue_len,''queue_count,'' pos_head,''pos_tail, date(t2.create_time) day from ( select get_json_object(event_json,'$.id') id, get_json_object(event_json,'$.deviceNo') device_no, get_json_object(event_json,'$.createTime') create_time, get_json_object(event_json,'$.objList') obj_list from hurys_dc_ods.ods_event) as t2 lateral view explode(split(regexp_replace(regexp_replace(obj_list, '\[|\]','') , '\}\,\{','\}\;\{'), '\;') )list_obj as list_json where t2.obj_list is not null group by t2.device_no, get_json_object(list_json,'$.id'), create_time, get_json_object(list_json,'$.eventType'), get_json_object(list_json,'$.posX'), get_json_object(list_json,'$.posY'), get_json_object(list_json,'$.targetLen')) select a2.id, device_no, create_time, event_type, lane_no, speed, pos_x, pos_y, brand, source_image, source_num, source_type, source_url, direction_radar, congestion_grade, target_count, lane_no_original, event_type_detail, target_len, queue_len, queue_count, pos_head, pos_tail, day from a2;
六、检查新的SQL运行效果
执行成功!
虽然还是不清楚之前SQL报错的原因,但是换种方式能运行就行。
对于之前SQL报错的原因,如果大家知道的话还请告诉我,谢谢!
org.apache.hadoop.hive.ql.parse.SemanticException: Line 2:5 Ambiguous table alias 't2'
猜你喜欢
- 21天前(安徽民宿发展报告)首届安徽省乡村民宿创意设计大赛启动
- 21天前(艾美酒店连锁)艾美酒店全球夏日计划回归,联手Wishbone主厨推出创新冰饮
- 21天前(屿见不一样是哪个酒店)屿见白纱,遇见自己 “佳能PhotoGirls屿见白纱”摄影派对玩转海岛
- 21天前(天气预报 华为)2025HDC华为天气上新系统级天气智能体,引领更智能的气象服务
- 21天前(云南滇陇工程咨询有限公司)陇滇携手谋发展 文旅合作谱新篇
- 21天前(纳米比亚旅游报价)纳米比亚旅游局2024年中国推介会圆满落幕
- 21天前(当科学邂逅喜剧:科技馆喜剧嘉年华背后的"文旅破壁者")当科学邂逅喜剧:科技馆喜剧嘉年华背后的"文旅破壁者"
- 21天前(殷建祥简历)全国十大牛商解码:殷建祥如何用178天技术突围打造星空梦星空房
- 21天前(“三天跨两城”催生租车新需求,神州租车清明跨城订单同比增长416%)“三天跨两城”催生租车新需求,神州租车清明跨城订单同比增长416%
- 21天前(内蒙古冬季旅游攻略)内蒙古冬日奇遇:携程租车带你策马踏雪
网友评论
- 搜索
- 最新文章
- (2020广州车展哈弗)你的猛龙 独一无二 哈弗猛龙广州车展闪耀登场
- (哈弗新能源suv2019款)智能科技颠覆出行体验 哈弗重塑新能源越野SUV价值认知
- (2021款全新哈弗h5自动四驱报价)新哈弗H5再赴保障之旅,无惧冰雪护航哈弗全民电四驱挑战赛
- (海南航空现况怎样)用一场直播找到市场扩张新渠道,海南航空做对了什么?
- (visa jcb 日本)优惠面面俱到 JCB信用卡邀您畅玩日本冰雪季
- (第三届“堡里有年味·回村过大年”民俗花灯会活动)第三届“堡里有年味·回村过大年”民俗花灯会活动
- (展示非遗魅力 长安启源助力铜梁龙舞出征)展示非遗魅力 长安启源助力铜梁龙舞出征
- (阿斯塔纳航空公司)阿斯塔纳航空机队飞机数量增至50架
- (北京香港航班动态查询)香港快运航空北京大兴新航线今日首航
- (我在港航“呵护”飞机 每一次安全着陆就是最好的荣誉)我在港航“呵护”飞机 每一次安全着陆就是最好的荣誉
- 热门文章