How to pass command to beeline without using interactive mode?

427 Views Asked by At

Using beeline, you can give specific hive commands (not HQL queries !) for hive configuration such as:

add jar myjar.jar

However, I do not understand how you can provide these commands to beeline without being in interactive mode as the documentation does not (or I do not find it) specify how to do it.

I have tried to provide it with the query argument -e , but no success:

beeline \
        -u toto \
        -n toto\
        -p toto \
        --silent=true \
        -e "add jar hivexmlserde-1.0.5.3.jar; show databases;" 

Error: AnalysisException: Syntax error in line 1:
add jar hivexmlserde-1.0.5.3.jar; show databases
^
Encountered: ADD

I have tried to do something like this, but it does not seem to do anything:

beeline \
        -u toto \
        -n toto\
        -p toto\
        --silent=true \
        -e "show databases;" <<EOF
        add jar hivexmlserde-1.0.5.3.jar
        list jar
        EOF

Which does not provide any log about adding a jar to the distributed cache.

How can I give to beeline some beeline commands before executing the provided HQL queries ?

1

There are 1 best solutions below

1
On

Not sure why you are trying to add jar using beeline. You can easily do using hive shell.

  • upload the JAR file into hdfs path hadoop fs -put ~/Downloads/hive.jar /lib/
  • open hive shell and issue - add jar hdfs:///lib/hive.jar

Now, if you want to issue a SQL command, you can use -q in beeline.

beeline ...   -q "show databases;" 

I think for beeline - -u require to give DB url. Something like this

beeline -n username -p password -u jdbc:hive2://hs2.local:10012