HiveQL - How to use escaped keywords in a WHERE clause?
Clash Royale CLAN TAG#URR8PPP
HiveQL - How to use escaped keywords in a WHERE clause?
I am trying to query a table by selecting only those cases that meet a certain condition. It is a query called from Beeline, within a R script.
The problem is the field that must meet this condition has a reserved word as a column name: 'table'.
Whenever I run this in an AWS-EMR cluster:
SELECT ... FROM ... WHERE `table` = 'something' AND year = 2018
I get the following error:
bash: table: command not found
Connecting to jdbc:hive2://localhost:10000
Connected to: Apache Hive (version 2.3.2-amzn-0)
Driver: Hive JDBC (version 2.3.2-amzn-0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
. . . . . . . . . . . . . . . . Error: Error while compiling statement: FAILED: ParseException line 1:242 cannot recognize input near '=' ''something'' 'and' in expression specification (state=42000,code=40000)
Closing: 0: jdbc:hive2://localhost:10000
ExitValue: 1
Both blocks marked in bold style should be fixed. Notice that the keyword 'table' is already escaped with backticks.
I have searched the web, but still cannot find a proper solution. Any help would be appreciated.
bash
Beeline called from an R script. It is crazy, I know... The magic of 'as is' projects...
– MiguelFCerdan
Aug 10 at 19:57
Short-term workaround: try escaping back-ticks i.e.
`table`
or maybe \`table\`
– Samson Scharfrichter
Aug 11 at 21:11
`table`
\`table\`
Long-term fix: use
RJDBC
to run Hive queries straight from R.– Samson Scharfrichter
Aug 11 at 21:13
RJDBC
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What tool do you "run" that SQL query into, that
bash
tries to parse the SQL?!?!?– Samson Scharfrichter
Aug 10 at 19:42