【障碍再现】
在创建支持Map数据结构的Hive表时,抛出如下异常
hive> create table tab_map(name string,info map<string,string>) > row format delimited > fields terminated by ' ' > collection items terminated by ';' > map keys terminated by ':'; MismatchedTokenException(-1!=286) 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.tableRowFormatCollItemsIdentifier(HiveParser.java:24000) at org.apache.hadoop.hive.ql.parse.HiveParser.rowFormatDelimited(HiveParser.java:22887) at org.apache.hadoop.hive.ql.parse.HiveParser.tableRowFormat(HiveParser.java:23091) at org.apache.hadoop.hive.ql.parse.HiveParser.createTableStatement(HiveParser.java:4388) at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2016) at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1298) at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:938) at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:190) at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:424) at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:342) at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:977) at org.apache.hadoop.hive.ql.Driver.run(Driver.java:888) at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:259) at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:216) at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:413) at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:781) at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:675) at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:614) 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.main(RunJar.java:212) FAILED: ParseException line 4:32 mismatched input '<EOF>' expecting StringLiteral near 'by' in table row format's column separator
【原因分析】
主要原因是 定义字段分割符的时候 用了";"作为字段分隔符,而HDFS文件的的格式就是用分号隔开的,因此,相互冲突。
【解决方案】
找到分号的asc码值 : http://blog.csdn.net/lxpbs8851/article/details/11525501
(其他字符有同样问题 也可以这样做) 找到的是073 那么将定义表的语句修改为:
row format delimited fields terminated by '73'。
最初的建表代码:
create table tab_map(name string,info map<string,string>) row format delimited fields terminated by ' ' collection items terminated by ';' <---- 注意此处 map keys terminated by ':';
解决问题后的代码:
create table tab_map(name string,info map<string,string>) row format delimited fields terminated by ' ' collection items terminated by '73' <------注意此处 map keys terminated by ':';