Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiples query on Hbase shell without calling hbase shell again

Tags:

shell

awk

hbase

To invoke shell again takes time , i want to execute multiple commands by invoking hbase shell once.Below code run only single query.

cmd="echo \"put 'test', 'row1', 'cf:a', 'value1'\"| hbase shell"

I want to run multiple queries on single hbase shell call.

put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'

how can I achieve this ?

like image 847
Aashu Avatar asked Dec 14 '22 20:12

Aashu


2 Answers

There are 4 options I know of

Option 1: semicolons

echo "put 'test','row1','cf:a','value1'; put 'test','row2','cf:b','value2'; put 'test','row3','cf:c','value3'" | hbase shell -n

Option 2: newlines

echo -e "put 'test','row1','cf:a','value1'\nput 'test','row2','cf:b','value2'\nput 'test','row3','cf:c','value3'" | hbase shell -n

Option 3: exec

exec hbase shell -n << EOF
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'
EOF

Option 4: external file

echo "put 'test', 'row1', 'cf:a', 'value1'" > tmpFile
echo "put 'test', 'row2', 'cf:b', 'value2'" >> tmpFile
echo "put 'test', 'row3', 'cf:c', 'value3'" >> tmpFile
hbase shell -n tmpFile
# obviously this also works: cat tmpFile | hbase shell -n
rm tmpFile

Whether to include the -n argument is up to you and your use case. It instructs the shell to stop executing after the first failed command and exit with a non-zero exit code. It was added with HBASE-11658.

I personally prefer option 3 since it's readable and without the need for a temp file.

like image 83
Keegan Avatar answered May 21 '23 08:05

Keegan


Try using -e for echo:

echo -e "put ...\n put ...\n"
like image 27
Tao Su Avatar answered May 21 '23 09:05

Tao Su