Unable to exit Hive - hadoop

I've just installed Hive on my Ubuntu machine (14.04). When I run hive in the terminal, it comes up with Logging initialized using configuration in jar:file:/home/nkhl/Documents/apachehive/lib/hive-common-1.2.1.jar!/hive-log4j.properties which is fine, I guess. Then the Hive shell opens. I haven't learnt Hive (yet) so when i run quit to quit the shell, it does nothing.
Here's the version of Hive i am on now:
Hive 1.2.1
Subversion git://localhost.localdomain/home/sush/dev/hive.git -r 243e7c1ac39cb7ac8b65c5bc6988f5cc3162f558
Compiled by sush on Fri Jun 19 02:03:48 PDT 2015
From source with checksum ab480aca41b24a9c3751b8c023338231
I close the terminal off, to quit the shell. Please help!
Thanks in advance.

I guess you must have forgotten to write semi-colon at the end of quit.
Use quit or exit to leave the interactive shell as shown below. Notice semi-colon (i.e. ; )
hive> quit;
OR
hive> exit;

Here we can exit from hive shell by the following 3 commands
1.hive>exit;
2.hive>quit;
As we all know that we can connect to hiveserver2 from beeline,jdbc-odbc,trift api.So when you are using beeline shell then the first two commands will not work so its better to use the following command to exit from beeline.
!exit
no semicolon should be used

You should also be about to use ctrl+c to exit

This is the right way to quit or exit from hive session.
hive> quit;
or
hive> exit;
Not the ;

You can quit using Ctrl(key) + C(Key) or quit; at the hive shell prompt.
That should work!!

use ctr+c to exit the hive
or hive > exit;

Once you type exit without ';' then ctrl+C won't work, in this case you shall directly quit the shell by closing terminal.

Related

I do not want by Bash script to stop if a Hive command fails

I have a bash script sending a lot of HiveQL commands to hive. The problem is that I do not want it to stop if one of these commands fails. I tried the usual Bash command:
set +e
but it does not work (the script stops running if one of the Hive command fails). Do you know where is the problem ? An option in my hive config or something :-) ?
Thank you !
EDIT: I use the Hiveshell, doing something like this:
#Send my command to hive ...
hive -S -e "\"$MyCommand\""
#... but I want my script continue running if the command fails :-).

Exiting from CockroachDB SQL CLI

Once I’m in the CockroachDB SQL shell, how do I get out of it? I tried exit; and quit; and it didn’t work.
You can exit from the CockroachDB SQL CLI with ctrl + C or \q.
you can also exit the CLI with quit or exit WITHOUT the training semicolon

how to invoke shell script in hive

Could someone please explain me how to invoke a shell script from hive?. I explored on this and found that we have to use source FILE command to invoke a shell script from hive. But I am not sure how exactly I can call my shell script from hive using source File command. So can someone help me on this? Thanks in Advance.
using ! <command> - Executes a shell command from the Hive shell.
test_1.sh:
#!/bin/sh
echo "This massage is from $0 file"
hive-test.hql:
! echo showing databases... ;
show databases;
! echo showing tables...;
show tables;
! echo runing shell script...;
! /home/cloudera/test_1.sh
output:
$ hive -v -f hive-test.hql
showing databases...
show databases
OK
default
retail_edw
sqoop_import
Time taken: 0.997 seconds, Fetched: 3 row(s)
showing tables...
show tables
OK
scala_departments
scaladepartments
stack
stackover_hive
Time taken: 0.062 seconds, Fetched: 4 row(s)
runing shell script...
This massage is from /home/cloudera/test_1.sh file
To invoke a shell script through HIVE CLI, please look at the example below.
!sh file.sh;
or
!./file.sh;
Please go though Hive Interactive Shell Commands section in the link below for more information.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli
Don't know if it would suit you, but you can inverse your problem by launching the hive commands from the bash shell in combination with the hive queries results. You can even create a single bash script for this to combine your hive queries with bash commands in a single script:
#!/bin/bash
hive -e 'SELECT count(*) from table' > temp.txt
cat temp.txt

Need to pass Variable from Shell Action to Oozie Shell using Hive

All,
Looking to pass variable from shell action to the oozie shell. I am running commands such as this, in my script:
#!/bin/sh
evalDate="hive -e 'set hive.execution.engine=mr; select max(cast(create_date as int)) from db.table;'"
evalPartition=$(eval $evalBaais)
echo "evaldate=$evalPartition"
Trick being that it is a hive command in the shell.
Then I am running this to get it in oozie:
${wf:actionData('getPartitions')['evaldate']}
But it pulls a blank every time! I can run those commands in my shell fine and it seems to work but oozie does not. Likewise, if I run the commands on the other boxes of the cluster, they run fine as well. Any ideas?
The issue was configuration regarding to my cluster. When I ran as oozie user, I had write permission issues to /tmp/yarn. With that, I changed the command to run as:
baais="export HADOOP_USER_NAME=functionalid; hive yarn -hiveconf hive.execution.engine=mr -e 'select max(cast(create_date as int)) from db.table;'"
Where hive allows me to run as yarn.
The solution to your problem is to use "-S" switch in hive command for silent output. (see below)
Also, what is "evalBaais"? You might need to replace this with "evalDate". So your code should look like this -
#!/bin/sh
evalDate="hive -S -e 'set hive.execution.engine=mr; select max(cast(create_date as int)) from db.table;'"
evalPartition=$(eval $evalDate)
echo "evaldate=$evalPartition"
Now you should be able to capture the out.

Exit from the oracle user session when running a script

I have a problem with a bash script on an Ubuntu system. I need to program a script which connects to oracle an spool some queries to text files.
Almost all of this tasks are acomplished but the script doesn't run as it should be.
To generate the connection to oracle I use the following lines inside my script:
su oracle
export ORACLE_SID=DB_SID
export ORACLE_HOME=[ORACLE_PATH]
export TWO_TASK=[HOSTNAME:PORT]
export PATH=$ORACLE_HOME/bin:$PATH
sqlplus -s usr/pass << EOF
In the subsequent lines I make all the spooling of the data and finally for exiting from sqlplus I use the following lines:
quit;
To diconnect from sqlplus
exit
To exit from the su oracle session
EOF
And after the EOF tag I put some other commands to be executed.
Problem is when I run my script:
user# sh MyScript.sh
Instead of doing all the tasks, the script only executes the lines to the point of the << EOF and returns to me the control of the terminal still logged as the oracle user.
oracle#user#
If I type 'exit' and press enter then the rest of the script is executed.
I need the script to execute from start to finish without this middle step but I don't know how.
Thanks in advance.
In the end it's not neccesary to use the [su oracle] to make the export of the environment variables so I simply deleted the line:
su oracle
And the process worked like a charm.
Thanks for all who helped.

Resources