2014-09-05 35 views
4

我試圖創建一個配置單元表以下查詢:MismatchedTokenException異常的蜂巢創建表查詢

CREATE TABLE IF NOT EXISTS BXDataSet 
    (ISBN STRING, 
    BookTitle STRING, 
    BookAuthor STRING, 
    YearOfPublication STRING, 
    Publisher STRING, 
    ImageURLS STRING, 
    ImageURLM STRING, 
    ImageURLL STRING) 
COMMENT 'BX-Books Table' 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ';' LINE TERMINATED BY '\n' 
STORED AS TEXTFILE; 

如何當我提交給攆我有以下異常:

MismatchedTokenException(-1!=301) 
    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:31433) 
    at org.apache.hadoop.hive.ql.parse.HiveParser.rowFormatDelimited(HiveParser.java:30386) 
    at org.apache.hadoop.hive.ql.parse.HiveParser.tableRowFormat(HiveParser.java:30662) 
    at org.apache.hadoop.hive.ql.parse.HiveParser.createTableStatement(HiveParser.java:4683) 
    at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2144) 
    at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1398) 
    at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1036) 
    at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:199) 
    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:322) 
    at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:975) 
    at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1040) 
    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:911) 
    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:901) 
    at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:268) 
    at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:220) 
    at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:423) 
    at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:792) 
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:686) 
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:625) 
    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 10:43 mismatched input '<EOF>' expecting StringLiteral near 'BY' in table row format's field separator 

蜂巢已正確安裝,我可以運行諸如顯示錶格之類的東西。那麼,這個查詢有什麼問題?

+0

我發現這是由於類似的錯誤,並且原來是由我的查詢中實際上是左引號和右引號的單引號引起的。 – Noah 2015-09-17 21:36:53

回答

10

您需要指定分隔符的OCT代碼。

這是爲了;華僑城代碼是073

CREATE TABLE IF NOT EXISTS BXDataSet 
(ISBN STRING, 
BookTitle STRING, 
BookAuthor STRING, 
YearOfPublication STRING, 
Publisher STRING, 
ImageURLS STRING, 
ImageURLM STRING, 
ImageURLL STRING) 
COMMENT 'BX-Books Table' 
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\073' LINE TERMINATED BY '\n' 
STORED AS TEXTFILE; 
+0

我有類似的錯誤爲'\ n'ParseException行11:49即使我嘗試使用相應的代碼'\ 012',也無法識別'serde屬性規範'中'LINE''TERMINATED''BY'附近的輸入! – bachr 2014-09-05 12:50:43

+0

參考https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/TruncateTable – 2014-09-05 13:10:44

+1

接受答案,如果它幫助你 – 2014-09-05 13:11:02

1

WRONGLINE TERMINATED BY '\n'

RIGHTLINES TERMINATED BY '\n'

'行' 而不是 'LINE'

1

簡單的答案是爲了躲避 「;」喜歡這個 」\;」 所以你的行將是 行格式DELIMITED FIELDS TERMINATED'';'行終止BY '\ n'

0

CREATE TABLE IF NOT EXISTS BXDataSetNew (ISBN STRING, BOOKTITLE STRING, BOOKAUTHOR STRING, yearofpublication介於STRING, 出版商STRING, ImageURLS STRING, ImageURLM STRING, ImageURLL STRING) 評論'BX-Books Table' 行格式界限字段'\ t'行終止'\ n' STORED AS TEXTFILE;