FAILED:ParseException行1:94不匹配的输入'hdfs'期望分区位置中'location'附近的StringLiteral

时间:2017-12-12 17:47:03

标签: java mysql apache hadoop hive

Java代码:

String cmd0 = "hive  -e \"use "
                        + hiveuser
                        + ";set hive.exec.compress.output=true;set mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec;set mapreduce.job.queuename="
                        + queue + ";alter table " + " resident_tmp "
                        + " add if not exists partition (weekday ='"
                        + "weekday=20170807" + "') location " + location + "\"";
    ComandUtil.exec(cmd0);

在hadoop集群中执行它可以成功,但是使用java api commandUtil.exec(..)来执行它是失败的。

failure log:
    17/12/13 01:18:52 INFO main.Run_WLOD: excute hive sentence :hive  -e "use vendorsjgt;set hive.exec.compress.output=true;set mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec;set mapreduce.job.queuename=ven5;alter table  resident_tmp  add if not exists partition (weekday ='weekday=20170807') location "hdfs://gzresearch/user/vendorsjgt/zcy/wlod/tmp/resident/weekday=20170807""
    17/12/13 01:18:55 WARN conf.HiveConf: HiveConf of name hive.optimize.mapjoin.mapreduce does not exist
    17/12/13 01:18:55 WARN conf.HiveConf: HiveConf of name hive.server2.custom.authentication.file does not exist
    17/12/13 01:18:55 WARN conf.HiveConf: HiveConf of name hive.heapsize does not exist
    17/12/13 01:18:55 WARN conf.HiveConf: HiveConf of name hive.metastore.local does not exist
    17/12/13 01:18:55 WARN conf.HiveConf: HiveConf of name hive.server2.enable.impersonation does not exist
    17/12/13 01:18:55 WARN conf.HiveConf: HiveConf of name hive.semantic.analyzer.factory.impl does not exist
    17/12/13 01:18:55 WARN conf.HiveConf: HiveConf of name hive.auto.convert.sortmerge.join.noconditionaltask does not exist

    Logging initialized using configuration in file:/software/servers/apache-hive-0.14.0-bin/conf/hive-log4j.properties
    OK
    Time taken: 1.654 seconds
    MismatchedTokenException(26!=313)
            at org.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:617)
            at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115)
            at org.apache.hadoop.hive.ql.parse.HiveParser.partitionLocation(HiveParser.java:11426)
            at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatementSuffixAddPartitionsElement(HiveParser.java:10973)
            at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatementSuffixAddPartitions(HiveParser.java:10800)
            at org.apache.hadoop.hive.ql.parse.HiveParser.alterTableStatementSuffix(HiveParser.java:7983)
            at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatement(HiveParser.java:7401)
            at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2685)
            at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1650)
            at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1109)
            at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:202)
            at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
            at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:396)
            at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:308)
            at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1122)
            at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1170)
            at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1059)
            at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1049)
            at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:213)
            at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:165)
            at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:376)
            at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:311)
            at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:708)
            at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:681)
            at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:621)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
            at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
    FAILED: ParseException line 1:94 mismatched input 'hdfs' expecting StringLiteral near 'location' in partition location
    Exception in thread "main" java.lang.RuntimeException: org.apache.commons.exec.ExecuteException: Process exited with an error: 64 (Exit value: 64)
            at com.cn.cennavi.util.ComandUtil.exec(ComandUtil.java:46)
            at cn.com.cennavi.main.Run_WLOD.main(Run_WLOD.java:177)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
            at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
    Caused by: org.apache.commons.exec.ExecuteException: Process exited with an error: 64 (Exit value: 64)
            at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
            at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
            at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:153)
            at com.cn.cennavi.util.ComandUtil.exec(ComandUtil.java:43)
            ... 7 more

命令句:

hive  -e "use vendorsjgt;set hive.exec.compress.output=true;set mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec;set mapreduce.job.queuename=ven5;alter table  resident_tmp  add if not exists partition (weekday ='weekday=20170807') location "hdfs://gzresearch/user/vendorsjgt/zcy/wlod/tmp/resident/weekday=20170807""

在Hadoop集群中执行它()可以成功,但是在java代码中使用它并在ComandUtil.exec(...)中执行它的执行失败..

在Hadoop集群()中执行它:

[vendorsjgt@GZA05-104-BigData-164000005 ~]$ hive  -e "use vendorsjgt;set hive.exec.compress.output=true;set mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec;set mapreduce.job.queuename=ven5;alter table  resident_tmp  add if not exists partition (weekday ='weekday=20170807') location 'hdfs://gzresearch/user/vendorsjgt/zcy/wlod/tmp/resident/weekday=20170807'"
17/12/13 00:55:40 WARN conf.HiveConf: HiveConf of name hive.optimize.mapjoin.mapreduce does not exist
17/12/13 00:55:40 WARN conf.HiveConf: HiveConf of name hive.server2.custom.authentication.file does not exist
17/12/13 00:55:40 WARN conf.HiveConf: HiveConf of name hive.heapsize does not exist
17/12/13 00:55:40 WARN conf.HiveConf: HiveConf of name hive.metastore.local does not exist
17/12/13 00:55:40 WARN conf.HiveConf: HiveConf of name hive.server2.enable.impersonation does not exist
17/12/13 00:55:40 WARN conf.HiveConf: HiveConf of name hive.semantic.analyzer.factory.impl does not exist
17/12/13 00:55:40 WARN conf.HiveConf: HiveConf of name hive.auto.convert.sortmerge.join.noconditionaltask does not exist

Logging initialized using configuration in file:/software/servers/apache-hive-0.14.0-bin/conf/hive-log4j.properties
OK
Time taken: 1.663 seconds
OK
Time taken: 0.26 seconds

我的项目和我的目标只是处理有关HQL的问题..并使用java api apache.commons.exec来做...而且我尝试了很多现有的解决方案,例如“hive创建表查询中的MismatchedTokenException”但它不起作用。

1 个答案:

答案 0 :(得分:1)

  

在Hadoop集群中执行它可以成功

你混淆了你的报价。你在终端

中运行了这个
hive -e "some query ... location "hdfs://location
                                ^^ Query failed here

你在Java中运行它

beeline
  1. 不推荐使用Hive CLI。使用{{1}}。
  2. Beeline使用JDBC,您也应该使用它