Home / Hive / Query compilation
Hive: ParseException: cannot recognize input near
org.apache.hadoop.hive.ql.parse.ParseExceptionFAILED: ParseException line 1:7 cannot recognize input near 'date' ',' 'amount' in select clauseThe parser hit tokens it did not expect. The three tokens quoted after "near" show where parsing stopped; the mistake is at or just before them. Reserved words used as identifiers and syntax from other SQL dialects are the common causes.
Common causes
- A reserved keyword such as date, timestamp, user or order is used as a column or table name without backticks.How to confirm: One of the quoted tokens is a keyword used as a name.
- Syntax from another dialect, for example TOP n, a trailing comma before FROM, or a missing alias on a subquery in FROM.How to confirm: The quoted tokens sit right after the construct that Hive does not support.
How to fix it
Quote reserved words with backticks.
SELECT `date`, `user` FROM events;Rewrite unsupported constructs: use LIMIT instead of TOP, remove trailing commas, and alias every subquery in FROM.
Where the message comes from
HiveParser.ginapache/hiveatrel/release-4.2.1- Message checked in Hive 4.2.1
Message template in the source: cannot recognize input near