Purpose: Query the number of results to be judged based on whether you must execute the next script.
1. script.q query script as follows:
select count(1) as count from test;
2. shell script is as follows:
Note here that the statement requires hive wrapped in `` (upper left ~ button) which, then outputs the result is assigned to a variable.
#!/bin/sh count=`beeline --silent=true --outputformat=csv2 \ --showHeader=false --showWarnings=false \ -u 'jdbc:hive2://localhost:10000/default' \ -n "username" -p 'password' \ -f script.q` echo '===============总数量:========================' echo 'count:' $count echo '================ size comparison ======================== ' IF [ $ COUNT -LT-0 ] ; the then echo ' is less than 0 ' elif [ $ COUNT -gt 7000 ] ; the then echo ' greater than 7000 ' elif [ $ COUNT -gt 6456 ] ; the then echo ' greater than 6456 ' the else echo ' OTHER ' Fi echo ' ==== Compare ========= end ============== '
Execution results are shown below: