- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Can I write a script to perform a phoenix query and write the output to a file?
- Labels:
-
Apache Phoenix
Created ‎06-20-2016 05:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Perfect! Thanks!
Created ‎06-20-2016 06:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
