I use beeline from the command line quite a lot, so I would like to create a bash alias for the beeline command that takes care of all the boilerplate for me and does some argument parsing and things. Specifically, one thing I would like to do is create a showtables
command which takes a single argument, the name of a database, and invokes the beeline command with the boiler plate and passes the -e argument along with the appropriate SQL, i.e. - showtables db1
should invoke /usr/bin/beeline -u $config -e "SHOW TABLES IN db1"
. My source file looks like this :
/usr/bin/beeline --showHeader=False --outputformat=tsv2 -u $config -e \"SHOW TABLES IN $1\"
but the output is
...
Error: Error while compiling statement: FAILED: ParseException line 1:4 cannot recognize input near 'SHOW' '<EOF>' '<EOF>' in ddl statement (state=42000,code=40000)
Error: Error while compiling statement: FAILED: ParseException line 1:0 cannot recognize input near 'TABLES' '<EOF>' '<EOF>' (state=42000,code=40000)
Error: Error while compiling statement: FAILED: ParseException line 1:0 cannot recognize input near 'IN' '<EOF>' '<EOF>' (state=42000,code=40000)
Error: Error while compiling statement: FAILED: ParseException line 1:0 cannot recognize input near 'db1' '<EOF>' '<EOF>' (state=42000,code=40000)
...
I've verified that just doing
/usr/bin/beeline --showHeader=False --outputformat=tsv2 -u $config -e "SHOW TABLES IN db1"
works as expected. I don't understand why my executable isn't working though.
The backslashes before your quotes make them behave like regular characters from the perspective of parsing, and not like quotes anymore. Thus, when you put backslashes in front of the quotes, SHOW TABLES IN db1
is no longer a string, but is four separate strings: "SHOW
, TABLES
, IN
, and db1"
.
These words are not valid queries when run on their own -- hence your error. Take out the backslashes and the issue goes away.