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

骑猪看日落 2023-09-24 15:42 138阅读 0赞

错误

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

详细错误

在这里插入图片描述

建表语句

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

终端报错

  1. MismatchedTokenException(-1!=332)
  2. at org.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:617)
  3. at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115)
  4. at org.apache.hadoop.hive.ql.parse.HiveParser.tableRowFormatFieldIdentifier(HiveParser.java:36442)
  5. at org.apache.hadoop.hive.ql.parse.HiveParser.rowFormatDelimited(HiveParser.java:35352)
  6. at org.apache.hadoop.hive.ql.parse.HiveParser.tableRowFormat(HiveParser.java:35636)
  7. at org.apache.hadoop.hive.ql.parse.HiveParser.createTableStatement(HiveParser.java:5398)
  8. at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2763)
  9. at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1756)
  10. at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1178)
  11. at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:204)
  12. at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
  13. at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:404)
  14. at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:329)
  15. at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1158)
  16. at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1253)
  17. at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1084)
  18. at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1072)
  19. at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:232)
  20. at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:183)
  21. at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:399)
  22. at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:776)
  23. at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:714)
  24. at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:641)
  25. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  26. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  27. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  28. at java.lang.reflect.Method.invoke(Method.java:498)
  29. at org.apache.hadoop.util.RunJar.run(RunJar.java:226)
  30. at org.apache.hadoop.util.RunJar.main(RunJar.java:141)
  31. FAILED: ParseException line 3:22 mismatched input '<EOF>' expecting StringLiteral near 'by' in table row format's field separator

解决方案

更改建表语句中

  1. fields terminated by ';'

  1. fields terminated by '\073'

错误原因

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

  1. fields terminated by ';'

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

  1. fields terminated by '\073'

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

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

发表评论

表情:
评论列表 (有 0 条评论,138人围观)

还没有评论,来说两句吧...

相关阅读