java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.ParseException:line 1:116 cannot recogni

错误

使用jdbc执行hive查询语句,控制台报错

java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.ParseException:line 1:116 cannot recognize input near 'limit' ''0'' ',' in limit clause

详细错误

使用jdbc执行hive查询语句

sql = "select * from ep02  where deadline >= '" + startTime + "' and deadline <= '" + endTime + "' order by addAsymptomaticPeople desc limit '" + pageNum + "','" + pageSize+ "'";   

控制台报错

java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.ParseException:line 1:116 cannot recognize input near 'limit' ''0'' ',' in limit clause
	at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:207) ~[na:na]
	at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166) ~[na:na]
	at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:404) ~[na:na]
	at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:329) ~[na:na]
	at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1158) ~[na:na]
	at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1145) ~[na:na]
	at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:184) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:269) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.hive.service.cli.operation.Operation.run(Operation.java:324) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:460) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:447) ~[hive-service-2.1.0.jar:2.1.0]
	at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_261]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_261]
	at org.apache.hive.service.cli.session.HiveSessionProxy.invoke(HiveSessionProxy.java:78) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.hive.service.cli.session.HiveSessionProxy.access$000(HiveSessionProxy.java:36) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.hive.service.cli.session.HiveSessionProxy$1.run(HiveSessionProxy.java:63) ~[hive-service-2.1.0.jar:2.1.0]
	at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_261]
	at javax.security.auth.Subject.doAs(Subject.java:422) ~[na:1.8.0_261]
	at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1762) ~[hadoop-common-2.7.7.jar:na]
	at org.apache.hive.service.cli.session.HiveSessionProxy.invoke(HiveSessionProxy.java:59) ~[hive-service-2.1.0.jar:2.1.0]
	at com.sun.proxy.$Proxy35.executeStatementAsync(Unknown Source) ~[na:na]
	at org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:294) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:497) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1437) ~[hive-service-rpc-2.1.0.jar:2.1.0]
	at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1422) ~[hive-service-rpc-2.1.0.jar:2.1.0]
	at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39) ~[libthrift-0.9.3.jar:0.9.3]
	at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39) ~[libthrift-0.9.3.jar:0.9.3]
	at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56) ~[hive-service-2.1.0.jar:2.1.0]
	at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286) ~[libthrift-0.9.3.jar:0.9.3]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_261]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_261]
	at java.lang.Thread.run(Thread.java:750) ~[na:1.8.0_261]

解决方案

更改sql语句为

sql = "select * from ep02  where deadline >= '" + startTime + "' and deadline <= '" + endTime + "' order by addasymptomatic desc limit " + pageNum+ "," + pageSize;

原因

hive sql 对于字符串拼接有者较mysql而言更为严格的语法格式
具体的:若拼接对象为字符型,使用

"上一条语句'" + 字符型对象 + "'下一条语句"

即需要单引号表示拼接对象为字符型
若拼接对象为数值型,使用

"上一条语句" + 字符型对象 + "下一条语句"

即无需单引号表示拼接对象为数值型
由于笔者通过limit语句操作对象为数值型,无需单引号

原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

飞滕人生TYF

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

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

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

打赏作者

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

抵扣说明:

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

余额充值