hive建表报错 FAILED: ParseException line 3:22 mismatched input ‘<EOF>‘ expecting StringLiteral near ‘by‘

错误

hive建表报错
FAILED: ParseException line 3:22 mismatched input ‘’ expecting StringLiteral near ‘by’ in table row format’s field separator

详细错误

在这里插入图片描述

建表语句

hive> create external table if not exists epidemicStatisticsData(dateRange string, numberOfAsymptomaticPeople int, cumulativeNumberOfConfirmedCases int, cumulativeNumberOfPeopleCured int, cumulativeNumberOfDeaths int)
    > row format delimited
    > fields terminated by ';'
    > stored as textfile
    > location '/usr/data/epidemicStatisticsData.txt';

终端报错

MismatchedTokenException(-1!=332)
	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.tableRowFormatFieldIdentifier(HiveParser.java:36442)
	at org.apache.hadoop.hive.ql.parse.HiveParser.rowFormatDelimited(HiveParser.java:35352)
	at org.apache.hadoop.hive.ql.parse.HiveParser.tableRowFormat(HiveParser.java:35636)
	at org.apache.hadoop.hive.ql.parse.HiveParser.createTableStatement(HiveParser.java:5398)
	at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2763)
	at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1756)
	at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1178)
	at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:204)
	at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
	at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:404)
	at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:329)
	at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1158)
	at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1253)
	at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1084)
	at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1072)
	at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:232)
	at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:183)
	at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:399)
	at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:776)
	at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:714)
	at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:641)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.hadoop.util.RunJar.run(RunJar.java:226)
	at org.apache.hadoop.util.RunJar.main(RunJar.java:141)
FAILED: ParseException line 3:22 mismatched input '<EOF>' expecting StringLiteral near 'by' in table row format's field separator

解决方案

更改建表语句中

fields terminated by ';'

fields terminated by '\073'

错误原因

由于笔者的hdfs文件中不同字段是通过分号分隔, 因此

fields terminated by ';'

但对于特殊字符,为避免产生歧义,hive 语法规定需通过asc码值对特殊字符进行转义
';'对应asc码值为'\073'
即改为

fields terminated by '\073'

对于其他字符对应的asc码值
ASCII码值表

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

猜你喜欢

转载自blog.csdn.net/T_Y_F_/article/details/128391225