Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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 Contributor

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.