Created 06-20-2016 05:20 PM
I know how to accomplish this with Java, but I'm wondering if there is a simpler way using some sort of CLI client and piping.
I just want to run a set query, and write the results to a text file.
And I want to be able to execute this from a shell script.
Any suggestions?
Created 06-20-2016 05:33 PM
bash> cat /path/to/my_script.sql
!outputformat csv
select count(*) from system.catalog
/usr/hdp/current/phoenix-client/bin/sqlline.py zk_host:2181:/hbase-unsecure /path/to/my_script.sql > out.txt
bash> cat out.txt
83/83 (100%) Done
'COUNT(1)'
'87'
Created 06-20-2016 05:33 PM
bash> cat /path/to/my_script.sql
!outputformat csv
select count(*) from system.catalog
/usr/hdp/current/phoenix-client/bin/sqlline.py zk_host:2181:/hbase-unsecure /path/to/my_script.sql > out.txt
bash> cat out.txt
83/83 (100%) Done
'COUNT(1)'
'87'
Created 06-20-2016 06:10 PM
Perfect! Thanks!
Created 06-20-2016 06:32 PM
In your example, do you know how I would filter everything but the count?
So instead of
83/83 (100%) Done
'COUNT(1)'
'87'
I would only print
87
Created 06-20-2016 06:57 PM
Unfortunately I don't. I suggest an inverted grep on the file like: grep -v '(100%) Done' out.txt
Created 10-16-2017 08:10 AM
Can we check if below job failed.
/usr/hdp/current/phoenix-client/bin/sqlline.py zk_host:2181:/hbase-unsecure /path/to/my_script.sql > out.txt
Even though it fails I am getting $? as zero. Is there any way to check the same.