Running multiple query against hbase shell without calling hbase shell again

It takes a while to call the shell again, I want to execute multiple commands by calling the shell hbase once.Below code only fires one request.

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

      

I want to run multiple queries when calling one hbase shell.

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

      

how can i achieve this?

+3


source to share


2 answers


There are 4 options that I know

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: new lines

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

      

The inclusion of the argument is -n

up to you and your use case. It instructs the shell to terminate after the first failed command and exit with a nonzero exit code. It was added with HBASE-11658 .

I personally prefer option 3 as it is readable and without the need for a temporary file.

+4


source


Try to use -e

for echo

:



echo -e "put ...\n put ...\n"

      

+3


source







All Articles