Support Questions
Find answers, ask questions, and share your expertise

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

Solved Go to solution
Highlighted

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

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

Accepted Solutions
Highlighted

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

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
Highlighted

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

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

Highlighted

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

Super Collaborator

Perfect! Thanks!

Highlighted

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

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

Highlighted

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

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

Highlighted

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

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.