错误
使用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语句操作对象为数值型,无需单引号
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈