要再次调用shell需要时间,我想通过调用一次hbase shell来执行多个命令.Below代码只运行单个查询.
cmd="echo \"put 'test', 'row1', 'cf:a', 'value1'\"| hbase shell"
Run Code Online (Sandbox Code Playgroud)
我想在单个hbase shell调用上运行多个查询.
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'
Run Code Online (Sandbox Code Playgroud)
我该怎么做到这一点?
我知道有4种选择
选项1:分号
echo "put 'test','row1','cf:a','value1'; put 'test','row2','cf:b','value2'; put 'test','row3','cf:c','value3'" | hbase shell -n
Run Code Online (Sandbox Code Playgroud)
选项2:换行符
echo -e "put 'test','row1','cf:a','value1'\nput 'test','row2','cf:b','value2'\nput 'test','row3','cf:c','value3'" | hbase shell -n
Run Code Online (Sandbox Code Playgroud)
选项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
Run Code Online (Sandbox Code Playgroud)
选项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
Run Code Online (Sandbox Code Playgroud)
是否包含-n参数取决于您和您的用例.它指示shell在第一个失败的命令后停止执行,并以非零退出代码退出.它与HBASE-11658一起添加.
我个人更喜欢选项3,因为它是可读的,不需要临时文件.