Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Can I write a script to perform a phoenix query and write the output to a file?

avatar
Super Collaborator

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?

1 ACCEPTED SOLUTION

avatar

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'

View solution in original post

5 REPLIES 5

avatar

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'

avatar
Super Collaborator

Perfect! Thanks!

avatar
Super Collaborator

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

avatar

Unfortunately I don't. I suggest an inverted grep on the file like: grep -v '(100%) Done' out.txt

avatar
New Member

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.