在hbase shell上运行多次查询,而不再次调用hbase shell

kx1ctssn  于 2021-06-09  发布在  Hbase
关注(0)|答案(2)|浏览(352)

再次调用shell需要时间,我想通过调用一次hbase shell来执行多个命令。下面的代码只运行一个查询。

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

我想对单个hbase shell调用运行多个查询。

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

我怎样才能做到这一点?

pgx2nnw8

pgx2nnw81#

尝试使用 -e 为了 echo :

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

q5lcpyga2#

我知道有四种选择
选项1:分号

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

选项2:换行

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

选项3:执行

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

选项4:外部文件

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

是否包括 -n 争论取决于你和你的用例。它指示shell在第一个失败的命令后停止执行,并使用非零退出代码退出。添加了hbase-11658。
我个人更喜欢选项3,因为它是可读的,不需要临时文件。

相关问题