Hive SQL报错:SemanticException [Error 10004]: Invalid table alias or column reference

Hive SQL报错:SemanticException [Error 10004]: Invalid table alias or column reference

在python脚本中执行Hive SQL

python脚本如下:

sql="""SELECT
test_url,
(case
when substring_index(test_url, '/', 1) == 'dev.test.com`:`1024/' then substr(test_url,25)
when substring_index(test_url, '/', 1) == 'localhost:80/' then substr(test_url,21)
else test_url
end) as test_url_cleaned,
page_title,
FROM test.report_table
where dt = '%s' and web_id in
(
select web_id FROM dev.dev_report
) """% (num)

执行python脚本过程中报错:

FAILED: SemanticException [Error 10004]: Line 73:47 Invalid table alias or column reference ‘dev’: (possible column names are: test_url, test_url, page_title)

排查过程:
将SQL脚本单独拿出来执行时执行成功,但是实际在执行过程中报错如上,在google搜索错误信息时一开始用FAILED: SemanticException [Error 10004]搜索并没有搜索出有用的信息,多次检查脚本、搜索错误信息无果后极度想放弃。后来详细看了一下报错信息Invalid table alias or column reference ‘dev’,无效的表别名或者列引用,因为在我的sql中dev是表名起到了混淆作用,因此一开始并没有反应过来。后来将dev去掉后,发现报错为:Invalid table alias or column reference ‘test’:,因此找到问题所在:在python脚本中执行Hive SQL,拼接SQL语句时只能用占位符的方式拼接字符串。

修改后如下:

	sql="""SELECT
			test_url,
			(case
			    when substring_index(test_url, '/', 1) == '%s' then substr(test_url,25)
			    when substring_index(test_url, '/', 1) ==  '%s' then substr(test_url,21)
			    else ct_url
			end) as test_url_cleaned,
			page_title,
		FROM
			test.report_table
		where
			dt = '%s'
			and web_id in
			(
				select web_id FROM dev.dev_report
			)
	) """% (url1,url2,num)
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木笔の园子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值